@effect/language-service 0.44.1 → 0.45.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/language-service",
3
- "version": "0.44.1",
3
+ "version": "0.45.1",
4
4
  "description": "A Language-Service Plugin to Refactor and Diagnostic effect-ts projects",
5
5
  "main": "index.cjs",
6
6
  "bin": {
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.17.8/node_modules/effect/dist/esm/Function.js
27
+ // node_modules/.pnpm/effect@3.18.4/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") {
@@ -118,7 +118,7 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
118
118
  }
119
119
  }
120
120
 
121
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/GlobalValue.js
121
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/GlobalValue.js
122
122
  var globalStoreId = `effect/GlobalValue`;
123
123
  var globalStore;
124
124
  var globalValue = (id, compute) => {
@@ -132,7 +132,7 @@ var globalValue = (id, compute) => {
132
132
  return globalStore.get(id);
133
133
  };
134
134
 
135
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Predicate.js
135
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Predicate.js
136
136
  var isString = (input) => typeof input === "string";
137
137
  var isNumber = (input) => typeof input === "number";
138
138
  var isBoolean = (input) => typeof input === "boolean";
@@ -142,7 +142,7 @@ var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
142
142
  var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
143
143
  var isRecord = (input) => isRecordOrArray(input) && !Array.isArray(input);
144
144
 
145
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Utils.js
145
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Utils.js
146
146
  var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
147
147
  var GenKindImpl = class {
148
148
  value;
@@ -264,7 +264,7 @@ var internalCall = isNotOptimizedAway ? standard.effect_internal_function : forc
264
264
  var genConstructor = function* () {
265
265
  }.constructor;
266
266
 
267
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Hash.js
267
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Hash.js
268
268
  var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
269
269
  var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
270
270
  var hash = (self) => {
@@ -363,7 +363,7 @@ var cached = function() {
363
363
  return hash2;
364
364
  };
365
365
 
366
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Equal.js
366
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Equal.js
367
367
  var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
368
368
  function equals() {
369
369
  if (arguments.length === 1) {
@@ -417,7 +417,7 @@ function compareBoth(self, that) {
417
417
  var isEqual = (u) => hasProperty(u, symbol2);
418
418
  var equivalence = () => equals;
419
419
 
420
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Inspectable.js
420
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Inspectable.js
421
421
  var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
422
422
  var toJSON = (x) => {
423
423
  try {
@@ -469,7 +469,7 @@ var redact = (u) => {
469
469
  return u;
470
470
  };
471
471
 
472
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Pipeable.js
472
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Pipeable.js
473
473
  var pipeArguments = (self, args2) => {
474
474
  switch (args2.length) {
475
475
  case 0:
@@ -502,14 +502,14 @@ var pipeArguments = (self, args2) => {
502
502
  }
503
503
  };
504
504
 
505
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/opCodes/effect.js
505
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/internal/opCodes/effect.js
506
506
  var OP_COMMIT = "Commit";
507
507
 
508
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/version.js
509
- var moduleVersion = "3.17.8";
508
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/internal/version.js
509
+ var moduleVersion = "3.18.4";
510
510
  var getCurrentVersion = () => moduleVersion;
511
511
 
512
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/effectable.js
512
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/internal/effectable.js
513
513
  var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
514
514
  var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
515
515
  var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
@@ -596,7 +596,7 @@ var StructuralCommitPrototype = {
596
596
  ...StructuralPrototype
597
597
  };
598
598
 
599
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/option.js
599
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/internal/option.js
600
600
  var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
601
601
  var CommonProto = {
602
602
  ...EffectPrototype,
@@ -654,7 +654,7 @@ var some = (value) => {
654
654
  return a;
655
655
  };
656
656
 
657
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/either.js
657
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/internal/either.js
658
658
  var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
659
659
  var CommonProto2 = {
660
660
  ...EffectPrototype,
@@ -716,7 +716,7 @@ var right = (right3) => {
716
716
  return a;
717
717
  };
718
718
 
719
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Either.js
719
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Either.js
720
720
  var right2 = right;
721
721
  var left2 = left;
722
722
  var isLeft2 = isLeft;
@@ -724,14 +724,14 @@ var isRight2 = isRight;
724
724
  var map = /* @__PURE__ */ dual(2, (self, f) => isRight2(self) ? right2(f(self.right)) : left2(self.left));
725
725
  var getOrElse = /* @__PURE__ */ dual(2, (self, onLeft) => isLeft2(self) ? onLeft(self.left) : self.right);
726
726
 
727
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/internal/array.js
727
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/internal/array.js
728
728
  var isNonEmptyArray = (self) => self.length > 0;
729
729
 
730
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Order.js
730
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Order.js
731
731
  var make = (compare) => (self, that) => self === that ? 0 : compare(self, that);
732
732
  var string2 = /* @__PURE__ */ make((self, that) => self < that ? -1 : 1);
733
733
 
734
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Option.js
734
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Option.js
735
735
  var none2 = () => none;
736
736
  var some2 = some;
737
737
  var isNone2 = isNone;
@@ -739,7 +739,7 @@ var isSome2 = isSome;
739
739
  var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
740
740
  var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
741
741
 
742
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Record.js
742
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Record.js
743
743
  var map2 = /* @__PURE__ */ dual(2, (self, f) => {
744
744
  const out = {
745
745
  ...self
@@ -751,7 +751,7 @@ var map2 = /* @__PURE__ */ dual(2, (self, f) => {
751
751
  });
752
752
  var keys = (self) => Object.keys(self);
753
753
 
754
- // node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Array.js
754
+ // node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/esm/Array.js
755
755
  var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
756
756
  var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
757
757
  var appendAll = /* @__PURE__ */ dual(2, (self, that) => fromIterable(self).concat(fromIterable(that)));
@@ -1195,14 +1195,19 @@ var defaults = {
1195
1195
  target: "service",
1196
1196
  pattern: "default",
1197
1197
  skipLeadingPath: ["src/"]
1198
- }]
1198
+ }, {
1199
+ target: "custom",
1200
+ pattern: "default",
1201
+ skipLeadingPath: ["src/"]
1202
+ }],
1203
+ extendedKeyDetection: false
1199
1204
  };
1200
1205
  function parseKeyPatterns(patterns) {
1201
1206
  const result = [];
1202
1207
  for (const entry of patterns) {
1203
1208
  if (!isObject(entry)) continue;
1204
1209
  result.push({
1205
- target: hasProperty(entry, "target") && isString(entry.target) && ["service", "error"].includes(entry.target.toLowerCase()) ? entry.target.toLowerCase() : "service",
1210
+ target: hasProperty(entry, "target") && isString(entry.target) && ["service", "error", "custom"].includes(entry.target.toLowerCase()) ? entry.target.toLowerCase() : "service",
1206
1211
  pattern: hasProperty(entry, "pattern") && isString(entry.pattern) && ["package-identifier", "default"].includes(entry.pattern.toLowerCase()) ? entry.pattern.toLowerCase() : "default",
1207
1212
  skipLeadingPath: hasProperty(entry, "skipLeadingPath") && isArray(entry.skipLeadingPath) && entry.skipLeadingPath.every(isString) ? entry.skipLeadingPath : ["src/"]
1208
1213
  });
@@ -1228,7 +1233,8 @@ function parse(config) {
1228
1233
  topLevelNamedReexports: isObject(config) && hasProperty(config, "topLevelNamedReexports") && isString(config.topLevelNamedReexports) && ["ignore", "follow"].includes(config.topLevelNamedReexports.toLowerCase()) ? config.topLevelNamedReexports.toLowerCase() : defaults.topLevelNamedReexports,
1229
1234
  renames: isObject(config) && hasProperty(config, "renames") && isBoolean(config.renames) ? config.renames : defaults.renames,
1230
1235
  noExternal: isObject(config) && hasProperty(config, "noExternal") && isBoolean(config.noExternal) ? config.noExternal : defaults.noExternal,
1231
- keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns
1236
+ keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns,
1237
+ extendedKeyDetection: isObject(config) && hasProperty(config, "extendedKeyDetection") && isBoolean(config.extendedKeyDetection) ? config.extendedKeyDetection : defaults.extendedKeyDetection
1232
1238
  };
1233
1239
  }
1234
1240
 
@@ -3551,6 +3557,62 @@ var deterministicKeys = createDiagnostic({
3551
3557
  apply: fn("deterministicKeys.apply")(function* (sourceFile, report) {
3552
3558
  const ts = yield* service(TypeScriptApi);
3553
3559
  const typeParser = yield* service(TypeParser);
3560
+ const typeChecker = yield* service(TypeCheckerApi);
3561
+ const typeScriptUtils = yield* service(TypeScriptUtils);
3562
+ const options = yield* service(LanguageServicePluginOptions);
3563
+ const parseExtendsCustom = cachedBy(
3564
+ fn("parseExtendsCustom")(function* (classDeclaration) {
3565
+ if (!options.extendedKeyDetection) {
3566
+ return yield* typeParserIssue("Extended key detection is disabled", void 0, classDeclaration);
3567
+ }
3568
+ if (!classDeclaration.name) {
3569
+ return yield* typeParserIssue("Class has no name", void 0, classDeclaration);
3570
+ }
3571
+ if (!ts.isIdentifier(classDeclaration.name)) {
3572
+ return yield* typeParserIssue("Class name is not an identifier", void 0, classDeclaration);
3573
+ }
3574
+ const heritageClauses = classDeclaration.heritageClauses;
3575
+ if (!heritageClauses) {
3576
+ return yield* typeParserIssue("Class has no heritage clauses", void 0, classDeclaration);
3577
+ }
3578
+ const nodeToVisit2 = [...classDeclaration.heritageClauses];
3579
+ const appendNodeToVisit2 = (node) => {
3580
+ nodeToVisit2.push(node);
3581
+ return void 0;
3582
+ };
3583
+ while (nodeToVisit2.length > 0) {
3584
+ const node = nodeToVisit2.shift();
3585
+ if (ts.isCallExpression(node)) {
3586
+ for (let i = 0; i < node.arguments.length; i++) {
3587
+ const arg = node.arguments[i];
3588
+ if (!ts.isStringLiteral(arg)) continue;
3589
+ const resolvedSignature = typeChecker.getResolvedSignature(node);
3590
+ if (resolvedSignature) {
3591
+ const parameter = resolvedSignature.parameters[i];
3592
+ if (!parameter) continue;
3593
+ if (parameter.declarations) {
3594
+ for (const declaration of parameter.declarations) {
3595
+ const parameterSourceFile = typeScriptUtils.getSourceFileOfNode(declaration);
3596
+ const paramText = parameterSourceFile.text.substring(declaration.pos, declaration.end);
3597
+ if (paramText.toLowerCase().includes("@effect-identifier")) {
3598
+ return { className: classDeclaration.name, keyStringLiteral: arg, target: "custom" };
3599
+ }
3600
+ }
3601
+ }
3602
+ }
3603
+ }
3604
+ }
3605
+ ts.forEachChild(node, appendNodeToVisit2);
3606
+ }
3607
+ return yield* typeParserIssue(
3608
+ "Class does not extend any custom pattern",
3609
+ void 0,
3610
+ classDeclaration
3611
+ );
3612
+ }),
3613
+ "deterministicKeys.parseExtendsCustom",
3614
+ (classDeclaration) => classDeclaration
3615
+ );
3554
3616
  const nodeToVisit = [];
3555
3617
  const appendNodeToVisit = (node) => {
3556
3618
  nodeToVisit.push(node);
@@ -3574,12 +3636,13 @@ var deterministicKeys = createDiagnostic({
3574
3636
  map4(({ className, keyStringLiteral }) => ({ keyStringLiteral, className, target: "error" }))
3575
3637
  )
3576
3638
  ),
3639
+ orElse2(() => parseExtendsCustom(node)),
3577
3640
  orElse2(() => void_)
3578
3641
  );
3579
3642
  if (result && result.keyStringLiteral) {
3580
- const { className, keyStringLiteral } = result;
3643
+ const { className, keyStringLiteral, target } = result;
3581
3644
  const classNameText = ts.idText(className);
3582
- const expectedKey = yield* createString(sourceFile, classNameText, result.target);
3645
+ const expectedKey = yield* createString(sourceFile, classNameText, target);
3583
3646
  if (!expectedKey) continue;
3584
3647
  const actualIdentifier = keyStringLiteral.text;
3585
3648
  if (actualIdentifier !== expectedKey) {
@@ -5077,17 +5140,67 @@ var overriddenSchemaConstructor = createDiagnostic({
5077
5140
  const members = node.members;
5078
5141
  for (const member of members) {
5079
5142
  if (ts.isConstructorDeclaration(member)) {
5143
+ const fixAsStaticNew = {
5144
+ fixName: "overriddenSchemaConstructor_static",
5145
+ description: "Rewrite using the static 'new' pattern",
5146
+ apply: gen(function* () {
5147
+ const changeTracker = yield* service(ChangeTracker);
5148
+ const visitor = (node2) => {
5149
+ if (ts.isExpressionStatement(node2) && ts.isCallExpression(node2.expression) && ts.isToken(node2.expression.expression) && node2.expression.expression.kind === ts.SyntaxKind.SuperKeyword) {
5150
+ const constructThis = ts.factory.createNewExpression(
5151
+ ts.factory.createIdentifier("this"),
5152
+ void 0,
5153
+ node2.expression.arguments
5154
+ );
5155
+ return ts.factory.createVariableStatement(
5156
+ void 0,
5157
+ ts.factory.createVariableDeclarationList(
5158
+ [ts.factory.createVariableDeclaration(
5159
+ "_this",
5160
+ void 0,
5161
+ void 0,
5162
+ constructThis
5163
+ )],
5164
+ ts.NodeFlags.Const
5165
+ )
5166
+ );
5167
+ }
5168
+ if (ts.isToken(node2) && node2.kind === ts.SyntaxKind.ThisKeyword) {
5169
+ return ts.factory.createIdentifier("_this");
5170
+ }
5171
+ return ts.visitEachChild(node2, visitor, ts.nullTransformationContext);
5172
+ };
5173
+ const newBody = visitor(member.body);
5174
+ const bodyWithReturn = ts.factory.updateBlock(
5175
+ newBody,
5176
+ newBody.statements.concat([
5177
+ ts.factory.createReturnStatement(ts.factory.createIdentifier("_this"))
5178
+ ])
5179
+ );
5180
+ const newMethod = ts.factory.createMethodDeclaration(
5181
+ ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Public | ts.ModifierFlags.Static),
5182
+ void 0,
5183
+ "new",
5184
+ void 0,
5185
+ member.typeParameters,
5186
+ member.parameters,
5187
+ member.type,
5188
+ bodyWithReturn
5189
+ );
5190
+ changeTracker.replaceNode(sourceFile, member, newMethod);
5191
+ })
5192
+ };
5080
5193
  report({
5081
5194
  location: member,
5082
- messageText: "Classes extending Schema must not override the constructor",
5083
- fixes: [{
5195
+ messageText: "Classes extending Schema must not override the constructor; this is because it silently breaks the schema decoding behaviour. If that's needed, we recommend instead to use a static 'new' method that constructs the instance.",
5196
+ fixes: (member.body ? [fixAsStaticNew] : []).concat([{
5084
5197
  fixName: "overriddenSchemaConstructor_fix",
5085
5198
  description: "Remove the constructor override",
5086
5199
  apply: gen(function* () {
5087
5200
  const changeTracker = yield* service(ChangeTracker);
5088
5201
  changeTracker.delete(sourceFile, member);
5089
5202
  })
5090
- }]
5203
+ }])
5091
5204
  });
5092
5205
  break;
5093
5206
  }