@effect/language-service 0.71.2 → 0.72.1

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/transform.js CHANGED
@@ -24,7 +24,7 @@ __export(transform_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(transform_exports);
26
26
 
27
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Function.js
27
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Function.js
28
28
  var isFunction = (input) => typeof input === "function";
29
29
  var dual = function(arity, body) {
30
30
  if (typeof arity === "function") {
@@ -120,7 +120,7 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
120
120
  }
121
121
  }
122
122
 
123
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/GlobalValue.js
123
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/GlobalValue.js
124
124
  var globalStoreId = `effect/GlobalValue`;
125
125
  var globalStore;
126
126
  var globalValue = (id, compute) => {
@@ -134,7 +134,7 @@ var globalValue = (id, compute) => {
134
134
  return globalStore.get(id);
135
135
  };
136
136
 
137
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Predicate.js
137
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Predicate.js
138
138
  var isString = (input) => typeof input === "string";
139
139
  var isNumber = (input) => typeof input === "number";
140
140
  var isBoolean = (input) => typeof input === "boolean";
@@ -144,7 +144,7 @@ var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
144
144
  var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
145
145
  var isRecord = (input) => isRecordOrArray(input) && !Array.isArray(input);
146
146
 
147
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Utils.js
147
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Utils.js
148
148
  var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
149
149
  var GenKindImpl = class {
150
150
  value;
@@ -266,7 +266,7 @@ var internalCall = isNotOptimizedAway ? standard.effect_internal_function : forc
266
266
  var genConstructor = function* () {
267
267
  }.constructor;
268
268
 
269
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Hash.js
269
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Hash.js
270
270
  var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
271
271
  var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
272
272
  var hash = (self) => {
@@ -368,7 +368,7 @@ var cached = function() {
368
368
  return hash2;
369
369
  };
370
370
 
371
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Equal.js
371
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Equal.js
372
372
  var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
373
373
  function equals() {
374
374
  if (arguments.length === 1) {
@@ -424,7 +424,7 @@ function compareBoth(self, that) {
424
424
  var isEqual = (u) => hasProperty(u, symbol2);
425
425
  var equivalence = () => equals;
426
426
 
427
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Inspectable.js
427
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Inspectable.js
428
428
  var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
429
429
  var toJSON = (x) => {
430
430
  try {
@@ -476,7 +476,7 @@ var redact = (u) => {
476
476
  return u;
477
477
  };
478
478
 
479
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Pipeable.js
479
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Pipeable.js
480
480
  var pipeArguments = (self, args2) => {
481
481
  switch (args2.length) {
482
482
  case 0:
@@ -509,14 +509,14 @@ var pipeArguments = (self, args2) => {
509
509
  }
510
510
  };
511
511
 
512
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/opCodes/effect.js
512
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/opCodes/effect.js
513
513
  var OP_COMMIT = "Commit";
514
514
 
515
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/version.js
515
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/version.js
516
516
  var moduleVersion = "3.19.14";
517
517
  var getCurrentVersion = () => moduleVersion;
518
518
 
519
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/effectable.js
519
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/effectable.js
520
520
  var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
521
521
  var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
522
522
  var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
@@ -603,7 +603,7 @@ var StructuralCommitPrototype = {
603
603
  ...StructuralPrototype
604
604
  };
605
605
 
606
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/option.js
606
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/option.js
607
607
  var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
608
608
  var CommonProto = {
609
609
  ...EffectPrototype,
@@ -661,7 +661,7 @@ var some = (value) => {
661
661
  return a;
662
662
  };
663
663
 
664
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/either.js
664
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/either.js
665
665
  var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
666
666
  var CommonProto2 = {
667
667
  ...EffectPrototype,
@@ -723,7 +723,7 @@ var right = (right3) => {
723
723
  return a;
724
724
  };
725
725
 
726
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Either.js
726
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Either.js
727
727
  var right2 = right;
728
728
  var left2 = left;
729
729
  var isLeft2 = isLeft;
@@ -731,14 +731,14 @@ var isRight2 = isRight;
731
731
  var map = /* @__PURE__ */ dual(2, (self, f) => isRight2(self) ? right2(f(self.right)) : left2(self.left));
732
732
  var getOrElse = /* @__PURE__ */ dual(2, (self, onLeft) => isLeft2(self) ? onLeft(self.left) : self.right);
733
733
 
734
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/array.js
734
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/internal/array.js
735
735
  var isNonEmptyArray = (self) => self.length > 0;
736
736
 
737
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Order.js
737
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Order.js
738
738
  var make = (compare) => (self, that) => self === that ? 0 : compare(self, that);
739
739
  var string2 = /* @__PURE__ */ make((self, that) => self < that ? -1 : 1);
740
740
 
741
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Option.js
741
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Option.js
742
742
  var none2 = () => none;
743
743
  var some2 = some;
744
744
  var isNone2 = isNone;
@@ -748,7 +748,7 @@ var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : se
748
748
  var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
749
749
  var getOrUndefined = /* @__PURE__ */ getOrElse2(constUndefined);
750
750
 
751
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Record.js
751
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Record.js
752
752
  var map2 = /* @__PURE__ */ dual(2, (self, f) => {
753
753
  const out = {
754
754
  ...self
@@ -760,7 +760,7 @@ var map2 = /* @__PURE__ */ dual(2, (self, f) => {
760
760
  });
761
761
  var keys = (self) => Object.keys(self);
762
762
 
763
- // node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Array.js
763
+ // ../../node_modules/.pnpm/effect@3.19.14/node_modules/effect/dist/esm/Array.js
764
764
  var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
765
765
  var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
766
766
  var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
@@ -1161,6 +1161,13 @@ var option = (fa) => {
1161
1161
  nano[contE] = (_) => _ instanceof NanoDefectException ? fail(_) : succeed(none2());
1162
1162
  return nano;
1163
1163
  };
1164
+ var orUndefined = (fa) => {
1165
+ const nano = Object.create(MatchProto);
1166
+ nano[args] = fa;
1167
+ nano[contA] = (_) => succeed(_);
1168
+ nano[contE] = (_) => _ instanceof NanoDefectException ? fail(_) : succeed(void 0);
1169
+ return nano;
1170
+ };
1164
1171
  var ignore = (fa) => {
1165
1172
  const nano = Object.create(MatchProto);
1166
1173
  nano[args] = fa;
@@ -1352,7 +1359,7 @@ function makeTypeScriptUtils(ts) {
1352
1359
  if (!hasProperty(packageJsonScope, "packageDirectory")) return;
1353
1360
  if (!isString(packageJsonScope.packageDirectory)) return;
1354
1361
  const { name } = packageJsonContent;
1355
- const version = hasProperty(packageJsonScope, "version") ? packageJsonScope.version : "";
1362
+ const version = hasProperty(packageJsonContent, "version") ? packageJsonContent.version : "unknown";
1356
1363
  if (!isString(name)) return;
1357
1364
  if (!isString(version)) return;
1358
1365
  const hasEffectInPeerDependencies = hasProperty(packageJsonContent, "peerDependencies") && isObject(packageJsonContent.peerDependencies) && hasProperty(packageJsonContent.peerDependencies, "effect");
@@ -2563,6 +2570,8 @@ function makeTypeCheckerUtils(ts, typeChecker, tsUtils) {
2563
2570
  }
2564
2571
 
2565
2572
  // src/core/TypeParser.ts
2573
+ var checkedPackagesCache = /* @__PURE__ */ new Map();
2574
+ var programResolvedCacheSize = /* @__PURE__ */ new Map();
2566
2575
  var TypeParser = Tag("@effect/language-service/TypeParser");
2567
2576
  var nanoLayer3 = (fa) => gen(function* () {
2568
2577
  const ts = yield* service(TypeScriptApi);
@@ -2583,6 +2592,40 @@ function typeParserIssue(_message, _type, _node) {
2583
2592
  return TypeParserIssue.issue;
2584
2593
  }
2585
2594
  function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
2595
+ function supportedEffect() {
2596
+ for (const fileName of program.getRootFileNames()) {
2597
+ const sourceFile = program.getSourceFile(fileName);
2598
+ if (!sourceFile) continue;
2599
+ const resolvedPackages = getEffectRelatedPackages(sourceFile);
2600
+ for (const version of Object.keys(resolvedPackages["effect"])) {
2601
+ if (String(version).startsWith("4")) return "v4";
2602
+ if (String(version).startsWith("3")) return "v3";
2603
+ }
2604
+ }
2605
+ return "v3";
2606
+ }
2607
+ function getEffectRelatedPackages(sourceFile) {
2608
+ let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
2609
+ const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
2610
+ const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
2611
+ if (newResolvedModuleSize !== oldResolvedSize) {
2612
+ const seenPackages = /* @__PURE__ */ new Set();
2613
+ resolvedPackages = {};
2614
+ program.getSourceFiles().map((_) => {
2615
+ const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_);
2616
+ if (!packageInfo) return;
2617
+ const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
2618
+ if (seenPackages.has(packageNameAndVersion)) return;
2619
+ seenPackages.add(packageNameAndVersion);
2620
+ if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
2621
+ resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
2622
+ resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory;
2623
+ });
2624
+ checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
2625
+ programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
2626
+ }
2627
+ return resolvedPackages;
2628
+ }
2586
2629
  const getSourceFilePackageInfo = cachedBy(
2587
2630
  fn("TypeParser.getSourceFilePackageInfo")(function* (sourceFile) {
2588
2631
  return tsUtils.resolveModuleWithPackageInfoFromSourceFile(program, sourceFile);
@@ -2811,19 +2854,28 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
2811
2854
  );
2812
2855
  const effectType = cachedBy(
2813
2856
  fn("TypeParser.effectType")(function* (type, atLocation) {
2814
- const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
2815
- (_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
2816
- );
2817
- if (propertiesSymbols.length === 0) {
2818
- return yield* typeParserIssue("Type has no effect variance struct", type, atLocation);
2857
+ if (supportedEffect() === "v4") {
2858
+ const typeIdSymbol = typeChecker.getPropertyOfType(type, "~effect/Effect");
2859
+ if (typeIdSymbol) {
2860
+ const typeIdType = typeChecker.getTypeOfSymbolAtLocation(typeIdSymbol, atLocation);
2861
+ return yield* effectVarianceStruct(typeIdType, atLocation);
2862
+ }
2863
+ return yield* typeParserIssue("Type is not an effect", type, atLocation);
2864
+ } else {
2865
+ const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
2866
+ (_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
2867
+ );
2868
+ if (propertiesSymbols.length === 0) {
2869
+ return yield* typeParserIssue("Type has no effect variance struct", type, atLocation);
2870
+ }
2871
+ propertiesSymbols.sort(
2872
+ (a, b) => ts.symbolName(b).indexOf("EffectTypeId") - ts.symbolName(a).indexOf("EffectTypeId")
2873
+ );
2874
+ return yield* firstSuccessOf(propertiesSymbols.map((propertySymbol) => {
2875
+ const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
2876
+ return effectVarianceStruct(propertyType, atLocation);
2877
+ }));
2819
2878
  }
2820
- propertiesSymbols.sort(
2821
- (a, b) => ts.symbolName(b).indexOf("EffectTypeId") - ts.symbolName(a).indexOf("EffectTypeId")
2822
- );
2823
- return yield* firstSuccessOf(propertiesSymbols.map((propertySymbol) => {
2824
- const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
2825
- return effectVarianceStruct(propertyType, atLocation);
2826
- }));
2827
2879
  }),
2828
2880
  "TypeParser.effectType",
2829
2881
  (type) => type
@@ -3143,10 +3195,10 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3143
3195
  }))
3144
3196
  )
3145
3197
  ),
3146
- option
3198
+ orUndefined
3147
3199
  );
3148
- if (isSome2(isEffectGen)) {
3149
- effectGenResult = isEffectGen.value;
3200
+ if (isEffectGen) {
3201
+ effectGenResult = isEffectGen;
3150
3202
  }
3151
3203
  }
3152
3204
  if (scopeNode && effectGenResult) {
@@ -3266,6 +3318,21 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3266
3318
  const effectSchemaType = cachedBy(
3267
3319
  fn("TypeParser.effectSchemaType")(function* (type, atLocation) {
3268
3320
  yield* pipeableType(type, atLocation);
3321
+ const typeId = typeChecker.getPropertyOfType(type, "~effect/Schema/Schema");
3322
+ if (typeId) {
3323
+ const typeKey = typeChecker.getPropertyOfType(type, "Type");
3324
+ const encodedKey = typeChecker.getPropertyOfType(type, "Encoded");
3325
+ if (typeKey && encodedKey) {
3326
+ const typeType = typeChecker.getTypeOfSymbolAtLocation(typeKey, atLocation);
3327
+ const encodedType = typeChecker.getTypeOfSymbolAtLocation(encodedKey, atLocation);
3328
+ return {
3329
+ A: typeType,
3330
+ I: encodedType,
3331
+ R: typeChecker.getNeverType()
3332
+ };
3333
+ }
3334
+ return yield* typeParserIssue("missing Type and Encoded");
3335
+ }
3269
3336
  const ast = typeChecker.getPropertyOfType(type, "ast");
3270
3337
  if (!ast) return yield* typeParserIssue("Has no 'ast' property", type, atLocation);
3271
3338
  const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
@@ -3484,9 +3551,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3484
3551
  if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
3485
3552
  const isEffectSchemaModuleApi = yield* pipe(
3486
3553
  isNodeReferenceToEffectSchemaModuleApi("Class")(schemaCall.expression),
3487
- option
3554
+ orUndefined
3488
3555
  );
3489
- if (isSome2(isEffectSchemaModuleApi)) {
3556
+ if (isEffectSchemaModuleApi) {
3490
3557
  return {
3491
3558
  className: atLocation.name,
3492
3559
  selfTypeNode: schemaCall.typeArguments[0]
@@ -3521,9 +3588,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3521
3588
  const selfTypeNode = schemaTaggedClassTCall.typeArguments[0];
3522
3589
  const isEffectSchemaModuleApi = yield* pipe(
3523
3590
  isNodeReferenceToEffectSchemaModuleApi("TaggedClass")(schemaTaggedClassTCall.expression),
3524
- option
3591
+ orUndefined
3525
3592
  );
3526
- if (isSome2(isEffectSchemaModuleApi)) {
3593
+ if (isEffectSchemaModuleApi) {
3527
3594
  return {
3528
3595
  className: atLocation.name,
3529
3596
  selfTypeNode,
@@ -3560,9 +3627,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3560
3627
  const selfTypeNode = schemaTaggedErrorTCall.typeArguments[0];
3561
3628
  const isEffectSchemaModuleApi = yield* pipe(
3562
3629
  isNodeReferenceToEffectSchemaModuleApi("TaggedError")(schemaTaggedErrorTCall.expression),
3563
- option
3630
+ orUndefined
3564
3631
  );
3565
- if (isSome2(isEffectSchemaModuleApi)) {
3632
+ if (isEffectSchemaModuleApi) {
3566
3633
  return {
3567
3634
  className: atLocation.name,
3568
3635
  selfTypeNode,
@@ -3582,6 +3649,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3582
3649
  );
3583
3650
  const extendsSchemaTaggedRequest = cachedBy(
3584
3651
  fn("TypeParser.extendsSchemaTaggedRequest")(function* (atLocation) {
3652
+ if (supportedEffect() === "v4") {
3653
+ return yield* typeParserIssue("Schema.TaggedClass is not supported in Effect v4", void 0, atLocation);
3654
+ }
3585
3655
  if (!atLocation.name) {
3586
3656
  return yield* typeParserIssue("Class has no name", void 0, atLocation);
3587
3657
  }
@@ -3599,9 +3669,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3599
3669
  const selfTypeNode = schemaTaggedRequestTCall.typeArguments[0];
3600
3670
  const isEffectSchemaModuleApi = yield* pipe(
3601
3671
  isNodeReferenceToEffectSchemaModuleApi("TaggedRequest")(schemaTaggedRequestTCall.expression),
3602
- option
3672
+ orUndefined
3603
3673
  );
3604
- if (isSome2(isEffectSchemaModuleApi)) {
3674
+ if (isEffectSchemaModuleApi) {
3605
3675
  return {
3606
3676
  className: atLocation.name,
3607
3677
  selfTypeNode,
@@ -3619,6 +3689,48 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3619
3689
  "TypeParser.extendsSchemaTaggedRequest",
3620
3690
  (atLocation) => atLocation
3621
3691
  );
3692
+ const extendsSchemaRequestClass = cachedBy(
3693
+ fn("TypeParser.extendsSchemaRequestClass")(function* (atLocation) {
3694
+ if (supportedEffect() === "v3") {
3695
+ return yield* typeParserIssue("Schema.RequestClass is not supported in Effect v3", void 0, atLocation);
3696
+ }
3697
+ if (!atLocation.name) {
3698
+ return yield* typeParserIssue("Class has no name", void 0, atLocation);
3699
+ }
3700
+ const heritageClauses = atLocation.heritageClauses;
3701
+ if (!heritageClauses) {
3702
+ return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
3703
+ }
3704
+ for (const heritageClause of heritageClauses) {
3705
+ for (const typeX of heritageClause.types) {
3706
+ if (ts.isExpressionWithTypeArguments(typeX)) {
3707
+ const expression = typeX.expression;
3708
+ if (ts.isCallExpression(expression)) {
3709
+ const schemaTaggedRequestTCall = expression.expression;
3710
+ if (ts.isCallExpression(schemaTaggedRequestTCall) && schemaTaggedRequestTCall.typeArguments && schemaTaggedRequestTCall.typeArguments.length > 0) {
3711
+ const selfTypeNode = schemaTaggedRequestTCall.typeArguments[0];
3712
+ const isEffectSchemaModuleApi = yield* pipe(
3713
+ isNodeReferenceToEffectSchemaModuleApi("RequestClass")(schemaTaggedRequestTCall.expression),
3714
+ orUndefined
3715
+ );
3716
+ if (isEffectSchemaModuleApi) {
3717
+ return {
3718
+ className: atLocation.name,
3719
+ selfTypeNode,
3720
+ tagStringLiteral: void 0,
3721
+ keyStringLiteral: schemaTaggedRequestTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedRequestTCall.arguments[0]) ? schemaTaggedRequestTCall.arguments[0] : void 0
3722
+ };
3723
+ }
3724
+ }
3725
+ }
3726
+ }
3727
+ }
3728
+ }
3729
+ return yield* typeParserIssue("Class does not extend Schema.RequestClass", void 0, atLocation);
3730
+ }),
3731
+ "TypeParser.extendsSchemaRequestClass",
3732
+ (atLocation) => atLocation
3733
+ );
3622
3734
  const extendsDataTaggedError = cachedBy(
3623
3735
  fn("TypeParser.extendsDataTaggedError")(function* (atLocation) {
3624
3736
  if (!atLocation.name) {
@@ -3638,13 +3750,13 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3638
3750
  if (ts.isPropertyAccessExpression(dataIdentifier) && ts.isIdentifier(dataIdentifier.name) && ts.idText(dataIdentifier.name) === "TaggedError") {
3639
3751
  const parsedDataModule = yield* pipe(
3640
3752
  importedDataModule(dataIdentifier.expression),
3641
- option
3753
+ orUndefined
3642
3754
  );
3643
- if (isSome2(parsedDataModule)) {
3755
+ if (parsedDataModule) {
3644
3756
  return {
3645
3757
  className: atLocation.name,
3646
3758
  keyStringLiteral: dataTaggedErrorCall.arguments.length > 0 && ts.isStringLiteral(dataTaggedErrorCall.arguments[0]) ? dataTaggedErrorCall.arguments[0] : void 0,
3647
- Data: parsedDataModule.value
3759
+ Data: parsedDataModule
3648
3760
  };
3649
3761
  }
3650
3762
  }
@@ -3676,13 +3788,13 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3676
3788
  if (ts.isPropertyAccessExpression(dataIdentifier) && ts.isIdentifier(dataIdentifier.name) && ts.idText(dataIdentifier.name) === "TaggedClass") {
3677
3789
  const parsedDataModule = yield* pipe(
3678
3790
  importedDataModule(dataIdentifier.expression),
3679
- option
3791
+ orUndefined
3680
3792
  );
3681
- if (isSome2(parsedDataModule)) {
3793
+ if (parsedDataModule) {
3682
3794
  return {
3683
3795
  className: atLocation.name,
3684
3796
  keyStringLiteral: dataTaggedClassCall.arguments.length > 0 && ts.isStringLiteral(dataTaggedClassCall.arguments[0]) ? dataTaggedClassCall.arguments[0] : void 0,
3685
- Data: parsedDataModule.value
3797
+ Data: parsedDataModule
3686
3798
  };
3687
3799
  }
3688
3800
  }
@@ -3716,9 +3828,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3716
3828
  if (ts.isPropertyAccessExpression(contextTagIdentifier) && ts.isIdentifier(contextTagIdentifier.name) && ts.idText(contextTagIdentifier.name) === "Tag") {
3717
3829
  const parsedContextModule = yield* pipe(
3718
3830
  importedContextModule(contextTagIdentifier.expression),
3719
- option
3831
+ orUndefined
3720
3832
  );
3721
- if (isSome2(parsedContextModule)) {
3833
+ if (parsedContextModule) {
3722
3834
  const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
3723
3835
  if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
3724
3836
  const type = typeChecker.getTypeOfSymbol(classSym);
@@ -3729,7 +3841,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3729
3841
  keyStringLiteral: ts.isStringLiteral(contextTagCall.arguments[0]) ? contextTagCall.arguments[0] : void 0,
3730
3842
  args: contextTagCall.arguments,
3731
3843
  Identifier: tagType.Identifier,
3732
- Tag: parsedContextModule.value
3844
+ Tag: parsedContextModule
3733
3845
  };
3734
3846
  }
3735
3847
  }
@@ -3767,9 +3879,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3767
3879
  const selfTypeNode = wholeCall.typeArguments[0];
3768
3880
  const isEffectTag = yield* pipe(
3769
3881
  isNodeReferenceToEffectModuleApi("Tag")(effectTagIdentifier),
3770
- option
3882
+ orUndefined
3771
3883
  );
3772
- if (isSome2(isEffectTag)) {
3884
+ if (isEffectTag) {
3773
3885
  return {
3774
3886
  className: atLocation.name,
3775
3887
  selfTypeNode,
@@ -3809,17 +3921,17 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3809
3921
  const selfTypeNode = effectServiceCall.typeArguments[0];
3810
3922
  const isEffectService = yield* pipe(
3811
3923
  isNodeReferenceToEffectModuleApi("Service")(effectServiceIdentifier),
3812
- option
3924
+ orUndefined
3813
3925
  );
3814
- if (isSome2(isEffectService)) {
3926
+ if (isEffectService) {
3815
3927
  const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
3816
3928
  if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
3817
3929
  const type = typeChecker.getTypeOfSymbol(classSym);
3818
3930
  const parsedContextTag = yield* pipe(
3819
3931
  contextTag(type, atLocation),
3820
- option
3932
+ orUndefined
3821
3933
  );
3822
- if (isSome2(parsedContextTag)) {
3934
+ if (parsedContextTag) {
3823
3935
  let accessors2 = void 0;
3824
3936
  let dependencies = void 0;
3825
3937
  if (wholeCall.arguments.length >= 2) {
@@ -3836,7 +3948,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3836
3948
  }
3837
3949
  }
3838
3950
  return {
3839
- ...parsedContextTag.value,
3951
+ ...parsedContextTag,
3840
3952
  className: atLocation.name,
3841
3953
  selfTypeNode,
3842
3954
  args: wholeCall.arguments,
@@ -3906,9 +4018,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
3906
4018
  if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {
3907
4019
  const isEffectSchemaModuleApi = yield* pipe(
3908
4020
  isNodeReferenceToEffectSqlModelModuleApi("Class")(schemaCall.expression),
3909
- option
4021
+ orUndefined
3910
4022
  );
3911
- if (isSome2(isEffectSchemaModuleApi)) {
4023
+ if (isEffectSchemaModuleApi) {
3912
4024
  return {
3913
4025
  className: atLocation.name,
3914
4026
  selfTypeNode: schemaCall.typeArguments[0]
@@ -4031,19 +4143,18 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4031
4143
  map4((s) => ({ _tag: "call", ...s }))
4032
4144
  )
4033
4145
  ),
4034
- option
4146
+ orUndefined
4035
4147
  );
4036
- if (isSome2(parsed)) {
4037
- const result2 = parsed.value;
4148
+ if (parsed) {
4038
4149
  let transformations;
4039
4150
  let flowNode;
4040
4151
  let childrenToTraverse = [];
4041
- if (result2._tag === "pipe") {
4042
- const signature = typeChecker.getResolvedSignature(result2.node);
4152
+ if (parsed._tag === "pipe") {
4153
+ const signature = typeChecker.getResolvedSignature(parsed.node);
4043
4154
  const typeArguments = signature ? typeChecker.getTypeArgumentsForResolvedSignature(signature) : void 0;
4044
4155
  transformations = [];
4045
- for (let i = 0; i < result2.args.length; i++) {
4046
- const arg = result2.args[i];
4156
+ for (let i = 0; i < parsed.args.length; i++) {
4157
+ const arg = parsed.args[i];
4047
4158
  const outType = typeArguments?.[i + 1];
4048
4159
  if (ts.isCallExpression(arg)) {
4049
4160
  transformations.push({
@@ -4052,7 +4163,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4052
4163
  args: Array.from(arg.arguments),
4053
4164
  // e.g., [(x) => x + 1]
4054
4165
  outType,
4055
- kind: result2.kind
4166
+ kind: parsed.kind
4056
4167
  });
4057
4168
  } else {
4058
4169
  transformations.push({
@@ -4060,17 +4171,17 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4060
4171
  // e.g., Effect.asVoid
4061
4172
  args: void 0,
4062
4173
  outType,
4063
- kind: result2.kind
4174
+ kind: parsed.kind
4064
4175
  });
4065
4176
  }
4066
4177
  }
4067
- flowNode = result2.node;
4068
- childrenToTraverse = result2.args;
4178
+ flowNode = parsed.node;
4179
+ childrenToTraverse = parsed.args;
4069
4180
  } else {
4070
4181
  const callSignature = typeChecker.getResolvedSignature(node);
4071
4182
  const outType = callSignature ? typeChecker.getReturnTypeOfSignature(callSignature) : void 0;
4072
4183
  transformations = [{
4073
- callee: result2.callee,
4184
+ callee: parsed.callee,
4074
4185
  args: void 0,
4075
4186
  outType,
4076
4187
  kind: "call"
@@ -4080,20 +4191,20 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4080
4191
  if (parentFlow) {
4081
4192
  parentFlow.transformations.unshift(...transformations);
4082
4193
  parentFlow.subject = {
4083
- node: result2.subject,
4084
- outType: typeCheckerUtils.getTypeAtLocation(result2.subject)
4194
+ node: parsed.subject,
4195
+ outType: typeCheckerUtils.getTypeAtLocation(parsed.subject)
4085
4196
  };
4086
- workQueue.push([result2.subject, parentFlow]);
4197
+ workQueue.push([parsed.subject, parentFlow]);
4087
4198
  } else {
4088
4199
  const newFlow = {
4089
4200
  node: flowNode,
4090
4201
  subject: {
4091
- node: result2.subject,
4092
- outType: typeCheckerUtils.getTypeAtLocation(result2.subject)
4202
+ node: parsed.subject,
4203
+ outType: typeCheckerUtils.getTypeAtLocation(parsed.subject)
4093
4204
  },
4094
4205
  transformations
4095
4206
  };
4096
- workQueue.push([result2.subject, newFlow]);
4207
+ workQueue.push([parsed.subject, newFlow]);
4097
4208
  }
4098
4209
  for (const child of childrenToTraverse) {
4099
4210
  ts.forEachChild(child, (c) => {
@@ -4103,17 +4214,17 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4103
4214
  continue;
4104
4215
  }
4105
4216
  if (includeEffectFn) {
4106
- const effectFnGenParsed = yield* pipe(effectFnGen(node), option);
4107
- const effectFnUntracedGenParsed = isNone2(effectFnGenParsed) ? yield* pipe(effectFnUntracedGen(node), option) : none2();
4108
- const effectFnNonGenParsed = isNone2(effectFnGenParsed) && isNone2(effectFnUntracedGenParsed) ? yield* pipe(effectFn(node), option) : none2();
4109
- const isEffectFnGen = isSome2(effectFnGenParsed);
4110
- const isEffectFnUntracedGen = isSome2(effectFnUntracedGenParsed);
4111
- const isEffectFnNonGen = isSome2(effectFnNonGenParsed);
4112
- const transformationKind = isEffectFnUntracedGen ? "effectFnUntraced" : "effectFn";
4113
- if (isEffectFnGen || isEffectFnUntracedGen) {
4114
- const effectFnParsed = isEffectFnGen ? effectFnGenParsed : effectFnUntracedGenParsed;
4115
- if (isSome2(effectFnParsed) && effectFnParsed.value.pipeArguments.length > 0) {
4116
- const fnResult = effectFnParsed.value;
4217
+ const effectFnKind = yield* pipe(
4218
+ map4(effectFnGen(node), (_) => ({ kind: "effectFnGen", ..._ })),
4219
+ orElse2(
4220
+ () => map4(effectFnUntracedGen(node), (_) => ({ kind: "effectFnUntracedGen", ..._ }))
4221
+ ),
4222
+ orElse2(() => map4(effectFn(node), (_) => ({ kind: "effectFn", ..._ }))),
4223
+ orUndefined
4224
+ );
4225
+ if (effectFnKind && (effectFnKind.kind === "effectFnGen" || effectFnKind.kind === "effectFnUntracedGen")) {
4226
+ if (effectFnKind.pipeArguments.length > 0) {
4227
+ const fnResult = effectFnKind;
4117
4228
  const pipeArgs = fnResult.pipeArguments;
4118
4229
  const transformations = [];
4119
4230
  let subjectType;
@@ -4133,14 +4244,14 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4133
4244
  callee: arg.expression,
4134
4245
  args: Array.from(arg.arguments),
4135
4246
  outType,
4136
- kind: transformationKind
4247
+ kind: effectFnKind.kind === "effectFnUntracedGen" ? "effectFnUntraced" : "effectFn"
4137
4248
  });
4138
4249
  } else {
4139
4250
  transformations.push({
4140
4251
  callee: arg,
4141
4252
  args: void 0,
4142
4253
  outType,
4143
- kind: transformationKind
4254
+ kind: effectFnKind.kind === "effectFnUntracedGen" ? "effectFnUntraced" : "effectFn"
4144
4255
  });
4145
4256
  }
4146
4257
  }
@@ -4162,8 +4273,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4162
4273
  continue;
4163
4274
  }
4164
4275
  }
4165
- if (isEffectFnNonGen && isSome2(effectFnNonGenParsed) && effectFnNonGenParsed.value.pipeArguments.length > 0) {
4166
- const fnResult = effectFnNonGenParsed.value;
4276
+ if (effectFnKind && effectFnKind.kind === "effectFn" && effectFnKind.pipeArguments.length > 0) {
4277
+ const fnResult = effectFnKind;
4167
4278
  const pipeArgs = fnResult.pipeArguments;
4168
4279
  const transformations = [];
4169
4280
  let subjectType;
@@ -4309,11 +4420,14 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
4309
4420
  extendsDataTaggedError,
4310
4421
  extendsDataTaggedClass,
4311
4422
  extendsSchemaTaggedRequest,
4423
+ extendsSchemaRequestClass,
4312
4424
  extendsEffectSqlModelClass,
4313
4425
  lazyExpression,
4314
4426
  emptyFunction,
4315
4427
  pipingFlows,
4316
- reconstructPipingFlow
4428
+ reconstructPipingFlow,
4429
+ getEffectRelatedPackages,
4430
+ supportedEffect
4317
4431
  };
4318
4432
  }
4319
4433
 
@@ -4429,6 +4543,7 @@ var catchAllToMapError = createDiagnostic({
4429
4543
  apply: fn("catchAllToMapError.apply")(function* (sourceFile, report) {
4430
4544
  const ts = yield* service(TypeScriptApi);
4431
4545
  const typeParser = yield* service(TypeParser);
4546
+ const catchAllName = typeParser.supportedEffect() === "v3" ? "catchAll" : "catch";
4432
4547
  const getFunctionBody = (node) => {
4433
4548
  if (ts.isArrowFunction(node)) {
4434
4549
  return node.body;
@@ -4443,10 +4558,10 @@ var catchAllToMapError = createDiagnostic({
4443
4558
  if (ts.isCallExpression(body)) {
4444
4559
  const isFailCall = yield* pipe(
4445
4560
  typeParser.isNodeReferenceToEffectModuleApi("fail")(body.expression),
4446
- option
4561
+ orUndefined
4447
4562
  );
4448
- if (isSome2(isFailCall) && body.arguments.length >= 1) {
4449
- return some2({ failCall: body, failArg: body.arguments[0] });
4563
+ if (isFailCall && body.arguments.length >= 1) {
4564
+ return { failCall: body, failArg: body.arguments[0] };
4450
4565
  }
4451
4566
  }
4452
4567
  if (ts.isBlock(body)) {
@@ -4456,15 +4571,14 @@ var catchAllToMapError = createDiagnostic({
4456
4571
  if (ts.isReturnStatement(stmt) && stmt.expression && ts.isCallExpression(stmt.expression)) {
4457
4572
  const isFailCall = yield* pipe(
4458
4573
  typeParser.isNodeReferenceToEffectModuleApi("fail")(stmt.expression.expression),
4459
- option
4574
+ orUndefined
4460
4575
  );
4461
- if (isSome2(isFailCall) && stmt.expression.arguments.length >= 1) {
4462
- return some2({ failCall: stmt.expression, failArg: stmt.expression.arguments[0] });
4576
+ if (isFailCall && stmt.expression.arguments.length >= 1) {
4577
+ return { failCall: stmt.expression, failArg: stmt.expression.arguments[0] };
4463
4578
  }
4464
4579
  }
4465
4580
  }
4466
4581
  }
4467
- return none2();
4468
4582
  });
4469
4583
  };
4470
4584
  const flows = yield* typeParser.pipingFlows(true)(sourceFile);
@@ -4474,10 +4588,10 @@ var catchAllToMapError = createDiagnostic({
4474
4588
  continue;
4475
4589
  }
4476
4590
  const isCatchAllCall = yield* pipe(
4477
- typeParser.isNodeReferenceToEffectModuleApi("catchAll")(transformation.callee),
4478
- option
4591
+ typeParser.isNodeReferenceToEffectModuleApi(catchAllName)(transformation.callee),
4592
+ orUndefined
4479
4593
  );
4480
- if (isNone2(isCatchAllCall)) {
4594
+ if (!isCatchAllCall) {
4481
4595
  continue;
4482
4596
  }
4483
4597
  const callback = transformation.args[0];
@@ -4485,11 +4599,11 @@ var catchAllToMapError = createDiagnostic({
4485
4599
  const functionBody = getFunctionBody(callback);
4486
4600
  if (!functionBody) continue;
4487
4601
  const failCallInfo = yield* getEffectFailCallInfo(functionBody);
4488
- if (isNone2(failCallInfo)) continue;
4489
- const { failArg, failCall } = failCallInfo.value;
4602
+ if (!failCallInfo) continue;
4603
+ const { failArg, failCall } = failCallInfo;
4490
4604
  report({
4491
4605
  location: transformation.callee,
4492
- messageText: `You can use Effect.mapError instead of Effect.catchAll + Effect.fail to transform the error type.`,
4606
+ messageText: `You can use Effect.mapError instead of Effect.${catchAllName} + Effect.fail to transform the error type.`,
4493
4607
  fixes: [{
4494
4608
  fixName: "catchAllToMapError_fix",
4495
4609
  description: "Replace with Effect.mapError",
@@ -4520,7 +4634,7 @@ var catchUnfailableEffect = createDiagnostic({
4520
4634
  apply: fn("catchUnfailableEffect.apply")(function* (sourceFile, report) {
4521
4635
  const ts = yield* service(TypeScriptApi);
4522
4636
  const typeParser = yield* service(TypeParser);
4523
- const catchFunctions = ["catchAll", "catch", "catchIf", "catchSome", "catchTag", "catchTags"];
4637
+ const catchFunctions = typeParser.supportedEffect() === "v3" ? ["catchAll", "catch", "catchIf", "catchSome", "catchTag", "catchTags"] : ["catch", "catchIf", "catchTag", "catchTags"];
4524
4638
  const flows = yield* typeParser.pipingFlows(true)(sourceFile);
4525
4639
  for (const flow2 of flows) {
4526
4640
  for (let i = 0; i < flow2.transformations.length; i++) {
@@ -4585,7 +4699,12 @@ var classSelfMismatch = createDiagnostic({
4585
4699
  orElse2(() => typeParser.extendsSchemaClass(node)),
4586
4700
  orElse2(() => typeParser.extendsSchemaTaggedClass(node)),
4587
4701
  orElse2(() => typeParser.extendsSchemaTaggedError(node)),
4588
- orElse2(() => typeParser.extendsSchemaTaggedRequest(node)),
4702
+ orElse2(
4703
+ () => pipe(
4704
+ typeParser.extendsSchemaTaggedRequest(node),
4705
+ orElse2(() => typeParser.extendsSchemaRequestClass(node))
4706
+ )
4707
+ ),
4589
4708
  orElse2(() => typeParser.extendsEffectSqlModelClass(node)),
4590
4709
  orElse2(() => void_)
4591
4710
  );
@@ -4812,39 +4931,18 @@ var deterministicKeys = createDiagnostic({
4812
4931
  });
4813
4932
 
4814
4933
  // src/diagnostics/duplicatePackage.ts
4815
- var checkedPackagesCache = /* @__PURE__ */ new Map();
4816
- var programResolvedCacheSize = /* @__PURE__ */ new Map();
4817
4934
  var duplicatePackage = createDiagnostic({
4818
4935
  name: "duplicatePackage",
4819
4936
  code: 6,
4820
4937
  description: "Detects when multiple versions of the same Effect package are loaded",
4821
4938
  severity: "warning",
4822
4939
  apply: fn("duplicatePackage.apply")(function* (sourceFile, report) {
4823
- const program = yield* service(TypeScriptProgram);
4824
- const tsUtils = yield* service(TypeScriptUtils);
4940
+ const typeParser = yield* service(TypeParser);
4825
4941
  const options = yield* service(LanguageServicePluginOptions);
4826
4942
  if (sourceFile.statements.length < 1) return;
4827
- let resolvedPackages = checkedPackagesCache.get(sourceFile.fileName) || {};
4828
- const newResolvedModuleSize = hasProperty(program, "resolvedModules") && hasProperty(program.resolvedModules, "size") && isNumber(program.resolvedModules.size) ? program.resolvedModules.size : 0;
4829
- const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1;
4830
- if (newResolvedModuleSize !== oldResolvedSize) {
4831
- const seenPackages = /* @__PURE__ */ new Set();
4832
- resolvedPackages = {};
4833
- program.getSourceFiles().map((_) => {
4834
- const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_);
4835
- if (!packageInfo) return;
4836
- const packageNameAndVersion = packageInfo.name + "@" + packageInfo.version;
4837
- if (seenPackages.has(packageNameAndVersion)) return;
4838
- seenPackages.add(packageNameAndVersion);
4839
- if (!(packageInfo.name === "effect" || packageInfo.hasEffectInPeerDependencies)) return;
4840
- if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return;
4841
- resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {};
4842
- resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory;
4843
- });
4844
- checkedPackagesCache.set(sourceFile.fileName, resolvedPackages);
4845
- programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize);
4846
- }
4943
+ const resolvedPackages = typeParser.getEffectRelatedPackages(sourceFile);
4847
4944
  for (const packageName of Object.keys(resolvedPackages)) {
4945
+ if (options.allowedDuplicatedPackages.indexOf(packageName) > -1) return;
4848
4946
  if (Object.keys(resolvedPackages[packageName]).length > 1) {
4849
4947
  const versions = Object.keys(resolvedPackages[packageName]);
4850
4948
  report({
@@ -5668,23 +5766,25 @@ var globalErrorInEffectCatch = createDiagnostic({
5668
5766
  if (isEffectWithCatch) {
5669
5767
  const signature = typeChecker.getResolvedSignature(node);
5670
5768
  if (signature) {
5671
- const objectType = typeChecker.getParameterType(signature, 0);
5672
- const catchFunctionSymbol = typeChecker.getPropertyOfType(objectType, "catch");
5673
- if (catchFunctionSymbol) {
5674
- const catchFunctionType = typeChecker.getTypeOfSymbolAtLocation(catchFunctionSymbol, node);
5675
- const signatures = typeChecker.getSignaturesOfType(catchFunctionType, ts.SignatureKind.Call);
5676
- if (signatures.length > 0) {
5677
- const returnType = typeChecker.getReturnTypeOfSignature(signatures[0]);
5678
- if (returnType && typeCheckerUtils.isGlobalErrorType(returnType)) {
5679
- const nodeText = sourceFile.text.substring(
5680
- ts.getTokenPosOfNode(node.expression, sourceFile),
5681
- node.expression.end
5682
- );
5683
- report({
5684
- location: node.expression,
5685
- messageText: `The 'catch' callback in ${nodeText} returns global 'Error', which loses type safety as untagged errors merge together. Consider using a tagged error and optionally wrapping the original in a 'cause' property.`,
5686
- fixes: []
5687
- });
5769
+ const firstParameterType = typeChecker.getParameterType(signature, 0);
5770
+ for (const objectType of typeCheckerUtils.unrollUnionMembers(firstParameterType)) {
5771
+ const catchFunctionSymbol = typeChecker.getPropertyOfType(objectType, "catch");
5772
+ if (catchFunctionSymbol) {
5773
+ const catchFunctionType = typeChecker.getTypeOfSymbolAtLocation(catchFunctionSymbol, node);
5774
+ const signatures = typeChecker.getSignaturesOfType(catchFunctionType, ts.SignatureKind.Call);
5775
+ if (signatures.length > 0) {
5776
+ const returnType = typeChecker.getReturnTypeOfSignature(signatures[0]);
5777
+ if (returnType && typeCheckerUtils.isGlobalErrorType(returnType)) {
5778
+ const nodeText = sourceFile.text.substring(
5779
+ ts.getTokenPosOfNode(node.expression, sourceFile),
5780
+ node.expression.end
5781
+ );
5782
+ report({
5783
+ location: node.expression,
5784
+ messageText: `The 'catch' callback in ${nodeText} returns global 'Error', which loses type safety as untagged errors merge together. Consider using a tagged error and optionally wrapping the original in a 'cause' property.`,
5785
+ fixes: []
5786
+ });
5787
+ }
5688
5788
  }
5689
5789
  }
5690
5790
  }
@@ -6497,22 +6597,23 @@ var missingEffectError = createDiagnostic({
6497
6597
  map4((result) => {
6498
6598
  if (result.missingErrorTypes.length === 0) return;
6499
6599
  const fixes = [];
6500
- if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never) {
6600
+ const catchAllErrorsName = typeParser.supportedEffect() === "v3" ? "catchAll" : "catch";
6601
+ if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never && catchAllErrorsName) {
6501
6602
  fixes.push({
6502
- fixName: "missingEffectError_catchAll",
6503
- description: "Catch all errors with Effect.catchAll",
6603
+ fixName: `missingEffectError_${catchAllErrorsName}`,
6604
+ description: `Catch all errors with Effect.${catchAllErrorsName}`,
6504
6605
  apply: gen(function* () {
6505
6606
  const changeTracker = yield* service(ChangeTracker);
6506
6607
  changeTracker.insertText(
6507
6608
  sourceFile,
6508
6609
  ts.getTokenPosOfNode(valueNode, sourceFile),
6509
- effectModuleIdentifier + ".catchAll("
6610
+ effectModuleIdentifier + `.${catchAllErrorsName}(`
6510
6611
  );
6511
6612
  changeTracker.insertText(sourceFile, valueNode.end, ", () => ");
6512
6613
  changeTracker.insertNodeAt(
6513
6614
  sourceFile,
6514
6615
  valueNode.end,
6515
- createDieMessage("TODO: catchAll not implemented")
6616
+ createDieMessage(`TODO: ${catchAllErrorsName} not implemented`)
6516
6617
  );
6517
6618
  changeTracker.insertText(sourceFile, valueNode.end, ")");
6518
6619
  })
@@ -6594,6 +6695,7 @@ var missingEffectServiceDependency = createDiagnostic({
6594
6695
  const typeChecker = yield* service(TypeCheckerApi);
6595
6696
  const typeCheckerUtils = yield* service(TypeCheckerUtils);
6596
6697
  const typeParser = yield* service(TypeParser);
6698
+ if (typeParser.supportedEffect() !== "v3") return;
6597
6699
  const nodeToVisit = [];
6598
6700
  const appendNodeToVisit = (node) => {
6599
6701
  nodeToVisit.push(node);
@@ -8813,6 +8915,7 @@ var scopeInLayerEffect = createDiagnostic({
8813
8915
  const typeChecker = yield* service(TypeCheckerApi);
8814
8916
  const typeParser = yield* service(TypeParser);
8815
8917
  const typeCheckerUtils = yield* service(TypeCheckerUtils);
8918
+ if (typeParser.supportedEffect() !== "v3") return;
8816
8919
  const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
8817
8920
  sourceFile,
8818
8921
  "effect",
@@ -9021,6 +9124,17 @@ var tryCatchInEffectGen = createDiagnostic({
9021
9124
  apply: fn("tryCatchInEffectGen.apply")(function* (sourceFile, report) {
9022
9125
  const ts = yield* service(TypeScriptApi);
9023
9126
  const typeParser = yield* service(TypeParser);
9127
+ const alternatives = typeParser.supportedEffect() === "v4" ? [
9128
+ "Effect.try",
9129
+ "Effect.tryPromise",
9130
+ "Effect.catch",
9131
+ "Effect.catchTag"
9132
+ ] : [
9133
+ "Effect.try",
9134
+ "Effect.tryPromise",
9135
+ "Effect.catchAll",
9136
+ "Effect.catchTag"
9137
+ ];
9024
9138
  const nodeToVisit = [];
9025
9139
  const appendNodeToVisit = (node) => {
9026
9140
  nodeToVisit.push(node);
@@ -9046,7 +9160,7 @@ var tryCatchInEffectGen = createDiagnostic({
9046
9160
  map4(() => {
9047
9161
  report({
9048
9162
  location: node,
9049
- messageText: "Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g., Effect.try, Effect.tryPromise, Effect.catchAll, Effect.catchTag).",
9163
+ messageText: `Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g. ${alternatives.join(", ")}).`,
9050
9164
  fixes: []
9051
9165
  });
9052
9166
  }),
@@ -9068,6 +9182,7 @@ var unknownInEffectCatch = createDiagnostic({
9068
9182
  const ts = yield* service(TypeScriptApi);
9069
9183
  const typeParser = yield* service(TypeParser);
9070
9184
  const typeChecker = yield* service(TypeCheckerApi);
9185
+ const typeCheckerUtils = yield* service(TypeCheckerUtils);
9071
9186
  const nodeToVisit = [];
9072
9187
  const appendNodeToVisit = (node) => {
9073
9188
  nodeToVisit.push(node);
@@ -9088,24 +9203,26 @@ var unknownInEffectCatch = createDiagnostic({
9088
9203
  if (isEffectWithCatch) {
9089
9204
  const signature = typeChecker.getResolvedSignature(node);
9090
9205
  if (signature) {
9091
- const objectType = typeChecker.getParameterType(signature, 0);
9092
- const catchFunctionSymbol = typeChecker.getPropertyOfType(objectType, "catch");
9093
- if (catchFunctionSymbol) {
9094
- const catchFunctionType = typeChecker.getTypeOfSymbolAtLocation(catchFunctionSymbol, node);
9095
- const signatures = typeChecker.getSignaturesOfType(catchFunctionType, ts.SignatureKind.Call);
9096
- if (signatures.length > 0) {
9097
- const returnType = typeChecker.getReturnTypeOfSignature(signatures[0]);
9098
- if (returnType && (returnType.flags & ts.TypeFlags.Unknown || returnType.flags & ts.TypeFlags.Any)) {
9099
- const nodeText = sourceFile.text.substring(
9100
- ts.getTokenPosOfNode(node.expression, sourceFile),
9101
- node.expression.end
9102
- );
9103
- report({
9104
- location: node.expression,
9105
- messageText: `The 'catch' callback in ${nodeText} returns 'unknown'. The catch callback should be used to provide typed errors.
9206
+ const parameterType = typeChecker.getParameterType(signature, 0);
9207
+ for (const objectType of typeCheckerUtils.unrollUnionMembers(parameterType)) {
9208
+ const catchFunctionSymbol = typeChecker.getPropertyOfType(objectType, "catch");
9209
+ if (catchFunctionSymbol) {
9210
+ const catchFunctionType = typeChecker.getTypeOfSymbolAtLocation(catchFunctionSymbol, node);
9211
+ const signatures = typeChecker.getSignaturesOfType(catchFunctionType, ts.SignatureKind.Call);
9212
+ if (signatures.length > 0) {
9213
+ const returnType = typeChecker.getReturnTypeOfSignature(signatures[0]);
9214
+ if (returnType && (returnType.flags & ts.TypeFlags.Unknown || returnType.flags & ts.TypeFlags.Any)) {
9215
+ const nodeText = sourceFile.text.substring(
9216
+ ts.getTokenPosOfNode(node.expression, sourceFile),
9217
+ node.expression.end
9218
+ );
9219
+ report({
9220
+ location: node.expression,
9221
+ messageText: `The 'catch' callback in ${nodeText} returns 'unknown'. The catch callback should be used to provide typed errors.
9106
9222
  Consider wrapping unknown errors into Effect's Data.TaggedError for example, or narrow down the type to the specific error raised.`,
9107
- fixes: []
9108
- });
9223
+ fixes: []
9224
+ });
9225
+ }
9109
9226
  }
9110
9227
  }
9111
9228
  }