@effect/language-service 0.14.0 → 0.15.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/README.md CHANGED
@@ -46,10 +46,12 @@ Your `tsconfig.json` should look like this:
46
46
  }
47
47
  ```
48
48
 
49
+ To get diagnostics you need to install `ts-patch` which will make it possible to run `tspc`.
50
+
49
51
  Running `tspc` in your project will now also run the plugin and give you the diagnostics at compile time.
50
52
 
51
53
  ```ts
52
- $ npm tspc
54
+ $ npx tspc
53
55
  index.ts:3:1 - error TS3: Effect must be yielded or assigned to a variable.
54
56
 
55
57
  3 Effect.succeed(1)
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
- var __export = (target, all2) => {
4
- for (var name in all2)
5
- __defProp(target, name, { get: all2[name], enumerable: true });
3
+ var __export = (target, all3) => {
4
+ for (var name in all3)
5
+ __defProp(target, name, { get: all3[name], enumerable: true });
6
6
  };
7
7
 
8
8
  // node_modules/.pnpm/effect@3.12.5/node_modules/effect/dist/esm/Function.js
@@ -1004,23 +1004,27 @@ var contextGet = (context, tag) => {
1004
1004
  }
1005
1005
  return none2();
1006
1006
  };
1007
- var Nano = class {
1008
- constructor(run2) {
1009
- this.run = run2;
1010
- }
1007
+ var Proto = {
1008
+ run: () => {
1009
+ },
1011
1010
  [Symbol.iterator]() {
1012
1011
  return new SingleShotGen(new YieldWrap(this));
1013
1012
  }
1014
1013
  };
1014
+ function make3(run2) {
1015
+ const result = Object.create(Proto);
1016
+ result.run = run2;
1017
+ return result;
1018
+ }
1015
1019
  var unsafeRun = (fa) => {
1016
1020
  const result = fa.run(contextEmpty);
1017
1021
  switch (result._tag) {
1018
1022
  case "Left":
1019
- return left2(result.left);
1023
+ return left2(result.value);
1020
1024
  case "Defect":
1021
- return left2(new NanoDefectException(result.defect));
1025
+ return left2(new NanoDefectException(result.value));
1022
1026
  case "Right":
1023
- return right2(result.right);
1027
+ return right2(result.value);
1024
1028
  }
1025
1029
  };
1026
1030
  var run = (fa) => {
@@ -1030,35 +1034,35 @@ var run = (fa) => {
1030
1034
  return left2(new NanoDefectException(e));
1031
1035
  }
1032
1036
  };
1033
- var succeed = (value) => new Nano(() => ({ _tag: "Right", right: value }));
1034
- var fail = (value) => new Nano(() => ({ _tag: "Left", left: value }));
1035
- var sync = (value) => new Nano(() => ({ _tag: "Right", right: value() }));
1036
- var flatMap3 = dual(2, (fa, f) => new Nano((ctx) => {
1037
+ var succeed = (value) => make3(() => ({ _tag: "Right", value }));
1038
+ var fail = (value) => make3(() => ({ _tag: "Left", value }));
1039
+ var sync = (value) => make3(() => ({ _tag: "Right", value: value() }));
1040
+ var flatMap3 = dual(2, (fa, f) => make3((ctx) => {
1037
1041
  const result = fa.run(ctx);
1038
1042
  if (result._tag !== "Right") return result;
1039
- return f(result.right).run(ctx);
1043
+ return f(result.value).run(ctx);
1040
1044
  }));
1041
- var map3 = dual(2, (fa, f) => new Nano((ctx) => {
1045
+ var map3 = dual(2, (fa, f) => make3((ctx) => {
1042
1046
  const result = fa.run(ctx);
1043
1047
  if (result._tag !== "Right") return result;
1044
- return { _tag: "Right", right: f(result.right) };
1048
+ return { _tag: "Right", value: f(result.value) };
1045
1049
  }));
1046
- var orElse3 = (f) => (fa) => new Nano((ctx) => {
1050
+ var orElse3 = (f) => (fa) => make3((ctx) => {
1047
1051
  const result = fa.run(ctx);
1048
- if (result._tag === "Left") return f().run(ctx);
1052
+ if (result._tag === "Left") return f(result.value).run(ctx);
1049
1053
  return result;
1050
1054
  });
1051
1055
  var firstSuccessOf = (arr) => reduce(arr.slice(1), arr[0], (arr2, fa) => orElse3(() => fa)(arr2));
1052
- var service = (tag) => new Nano(
1056
+ var service = (tag) => make3(
1053
1057
  (ctx) => contextGet(ctx, tag).pipe(match2({
1054
- onNone: () => ({ _tag: "Defect", defect: `Cannot find service ${tag.key}` }),
1055
- onSome: (value) => ({ _tag: "Right", right: value })
1058
+ onNone: () => ({ _tag: "Defect", value: `Cannot find service ${tag.key}` }),
1059
+ onSome: (value) => ({ _tag: "Right", value })
1056
1060
  }))
1057
1061
  );
1058
- var provideService = (tag, value) => (fa) => new Nano((ctx) => {
1062
+ var provideService = (tag, value) => (fa) => make3((ctx) => {
1059
1063
  return fa.run(contextAdd(ctx, tag, value));
1060
1064
  });
1061
- var gen2 = (...args) => new Nano((ctx) => {
1065
+ var gen2 = (...args) => make3((ctx) => {
1062
1066
  const iterator = args[0]();
1063
1067
  let state = iterator.next();
1064
1068
  while (!state.done) {
@@ -1067,11 +1071,11 @@ var gen2 = (...args) => new Nano((ctx) => {
1067
1071
  if (result._tag !== "Right") {
1068
1072
  return result;
1069
1073
  }
1070
- state = iterator.next(result.right);
1074
+ state = iterator.next(result.value);
1071
1075
  }
1072
- return { _tag: "Right", right: state.value };
1076
+ return { _tag: "Right", value: state.value };
1073
1077
  });
1074
- var fn = (_) => (body) => (...args) => new Nano((ctx) => {
1078
+ var fn = (_) => (body) => (...args) => make3((ctx) => {
1075
1079
  const iterator = body(...args);
1076
1080
  let state = iterator.next();
1077
1081
  while (!state.done) {
@@ -1080,21 +1084,29 @@ var fn = (_) => (body) => (...args) => new Nano((ctx) => {
1080
1084
  if (result._tag !== "Right") {
1081
1085
  return result;
1082
1086
  }
1083
- state = iterator.next(result.right);
1087
+ state = iterator.next(result.value);
1084
1088
  }
1085
- return { _tag: "Right", right: state.value };
1089
+ return { _tag: "Right", value: state.value };
1086
1090
  });
1087
- var option = (fa) => new Nano((ctx) => {
1091
+ var option = (fa) => make3((ctx) => {
1088
1092
  const result = fa.run(ctx);
1089
1093
  switch (result._tag) {
1090
1094
  case "Right":
1091
- return { _tag: "Right", right: some2(result.right) };
1095
+ return { _tag: "Right", value: some2(result.value) };
1092
1096
  case "Left":
1093
- return { _tag: "Right", right: none2() };
1097
+ return { _tag: "Right", value: none2() };
1094
1098
  case "Defect":
1095
1099
  return result;
1096
1100
  }
1097
1101
  });
1102
+ var all2 = (...args) => gen2(function* () {
1103
+ const results = [];
1104
+ for (const arg of args) {
1105
+ const result = yield* arg;
1106
+ results.push(result);
1107
+ }
1108
+ return results;
1109
+ });
1098
1110
 
1099
1111
  // src/core/TypeScriptApi.ts
1100
1112
  var TypeScriptApi = Tag("TypeScriptApi");
@@ -3511,6 +3523,491 @@ var toggleTypeAnnotation = createRefactor({
3511
3523
  })
3512
3524
  });
3513
3525
 
3526
+ // src/utils/SchemaGen.ts
3527
+ var TypeParametersNotSupportedError = class {
3528
+ constructor(node) {
3529
+ this.node = node;
3530
+ }
3531
+ _tag = "@effect/language-service/TypeParametersNotSupportedError";
3532
+ toString() {
3533
+ return `Could not process types with type parameters.`;
3534
+ }
3535
+ };
3536
+ var OnlyLiteralPropertiesSupportedError = class {
3537
+ constructor(node) {
3538
+ this.node = node;
3539
+ }
3540
+ _tag = "@effect/language-service/OnlyLiteralPropertiesSupportedError";
3541
+ toString() {
3542
+ return `Could not process ${this.node.getText()} as only literal properties are supported.`;
3543
+ }
3544
+ };
3545
+ var RequiredExplicitTypesError = class {
3546
+ constructor(node) {
3547
+ this.node = node;
3548
+ }
3549
+ _tag = "@effect/language-service/RequiredExplicitTypesError";
3550
+ toString() {
3551
+ return `Could not process ${this.node.getText()} as only explicit types are supported.`;
3552
+ }
3553
+ };
3554
+ var IndexSignatureWithMoreThanOneParameterError = class {
3555
+ constructor(node) {
3556
+ this.node = node;
3557
+ }
3558
+ _tag = "@effect/language-service/IndexSignatureWithMoreThanOneParameterError";
3559
+ toString() {
3560
+ return `Could not process ${this.node.getText()} as only index signatures with one parameter are supported.`;
3561
+ }
3562
+ };
3563
+ var SchemaGenContext = Tag("SchemaGenContext");
3564
+ var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourceFile) {
3565
+ const effectSchemaIdentifier = pipe(
3566
+ yield* option(
3567
+ findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", "Schema")
3568
+ ),
3569
+ match2({
3570
+ onNone: () => "Schema",
3571
+ onSome: (_) => _.text
3572
+ })
3573
+ );
3574
+ const moduleToImportedName = {};
3575
+ for (const moduleName of ["Option", "Either", "Chunk", "Duration"]) {
3576
+ const importedName = yield* option(
3577
+ findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, "effect", moduleName)
3578
+ );
3579
+ if (isSome2(importedName)) moduleToImportedName[moduleName] = importedName.value.text;
3580
+ }
3581
+ const ts = yield* service(TypeScriptApi);
3582
+ return {
3583
+ sourceFile,
3584
+ createApiPropertyAccess: (apiName) => ts.factory.createPropertyAccessExpression(
3585
+ ts.factory.createIdentifier(effectSchemaIdentifier),
3586
+ apiName
3587
+ ),
3588
+ createApiCall: (apiName, args) => ts.factory.createCallExpression(
3589
+ ts.factory.createPropertyAccessExpression(
3590
+ ts.factory.createIdentifier(effectSchemaIdentifier),
3591
+ apiName
3592
+ ),
3593
+ [],
3594
+ args
3595
+ ),
3596
+ entityNameToDataTypeName: (name) => {
3597
+ if (ts.isIdentifier(name)) {
3598
+ switch (name.text) {
3599
+ case "Date":
3600
+ case "Pick":
3601
+ case "Omit":
3602
+ case "Record":
3603
+ return some2(name.text);
3604
+ case "ReadonlyArray":
3605
+ case "Array":
3606
+ return some2("Array");
3607
+ }
3608
+ return none2();
3609
+ }
3610
+ if (!ts.isIdentifier(name.left)) return none2();
3611
+ for (const moduleName in moduleToImportedName) {
3612
+ if (name.left.text === moduleToImportedName[moduleName] && name.right.text === moduleName) {
3613
+ return some2(moduleName);
3614
+ }
3615
+ }
3616
+ return none2();
3617
+ },
3618
+ ts
3619
+ };
3620
+ });
3621
+ var typeEntityNameToNode = fn(
3622
+ "SchemaGen.typeEntityNameToNode"
3623
+ )(
3624
+ function* (entityName) {
3625
+ const { ts } = yield* service(SchemaGenContext);
3626
+ if (ts.isIdentifier(entityName)) return ts.factory.createIdentifier(entityName.text);
3627
+ const left3 = yield* typeEntityNameToNode(entityName.left);
3628
+ return ts.factory.createPropertyAccessExpression(
3629
+ left3,
3630
+ ts.factory.createIdentifier(entityName.right.text)
3631
+ );
3632
+ }
3633
+ );
3634
+ var parseAllLiterals = fn(
3635
+ "SchemaGen.parseAllLiterals"
3636
+ )(
3637
+ function* (node) {
3638
+ const { ts } = yield* service(SchemaGenContext);
3639
+ if (ts.isLiteralTypeNode(node)) {
3640
+ switch (node.literal.kind) {
3641
+ case ts.SyntaxKind.StringLiteral:
3642
+ return [ts.factory.createStringLiteral(node.literal.text)];
3643
+ case ts.SyntaxKind.NumericLiteral:
3644
+ return [ts.factory.createNumericLiteral(node.literal.text)];
3645
+ case ts.SyntaxKind.TrueKeyword:
3646
+ return [ts.factory.createTrue()];
3647
+ case ts.SyntaxKind.FalseKeyword:
3648
+ return [ts.factory.createFalse()];
3649
+ }
3650
+ }
3651
+ if (ts.isUnionTypeNode(node)) {
3652
+ return flatten(yield* all2(...node.types.map((_) => parseAllLiterals(_))));
3653
+ }
3654
+ if (ts.isParenthesizedTypeNode(node)) {
3655
+ return yield* parseAllLiterals(node.type);
3656
+ }
3657
+ return yield* fail(node);
3658
+ }
3659
+ );
3660
+ var createUnsupportedNodeComment = (ts, sourceFile, node) => ts.addSyntheticTrailingComment(
3661
+ ts.factory.createIdentifier(""),
3662
+ ts.SyntaxKind.MultiLineCommentTrivia,
3663
+ " Not supported conversion: " + node.getText(sourceFile) + " "
3664
+ );
3665
+ var processNode = (node) => gen2(function* () {
3666
+ const { createApiCall, createApiPropertyAccess, entityNameToDataTypeName, sourceFile, ts } = yield* service(
3667
+ SchemaGenContext
3668
+ );
3669
+ switch (node.kind) {
3670
+ case ts.SyntaxKind.AnyKeyword:
3671
+ return createApiPropertyAccess("Any");
3672
+ case ts.SyntaxKind.NeverKeyword:
3673
+ return createApiPropertyAccess("Never");
3674
+ case ts.SyntaxKind.UnknownKeyword:
3675
+ return createApiPropertyAccess("Unknown");
3676
+ case ts.SyntaxKind.VoidKeyword:
3677
+ return createApiPropertyAccess("Void");
3678
+ case ts.SyntaxKind.NullKeyword:
3679
+ return createApiPropertyAccess("Null");
3680
+ case ts.SyntaxKind.UndefinedKeyword:
3681
+ return createApiPropertyAccess("Undefined");
3682
+ case ts.SyntaxKind.StringKeyword:
3683
+ return createApiPropertyAccess("String");
3684
+ case ts.SyntaxKind.NumberKeyword:
3685
+ return createApiPropertyAccess("Number");
3686
+ case ts.SyntaxKind.BooleanKeyword:
3687
+ return createApiPropertyAccess("Boolean");
3688
+ case ts.SyntaxKind.BigIntKeyword:
3689
+ return createApiPropertyAccess("BigInt");
3690
+ }
3691
+ if (ts.isLiteralTypeNode(node)) {
3692
+ if (node.literal.kind === ts.SyntaxKind.NullKeyword) return createApiPropertyAccess("Null");
3693
+ const literalMembers = yield* option(parseAllLiterals(node));
3694
+ if (isSome2(literalMembers)) return createApiCall("Literal", literalMembers.value);
3695
+ }
3696
+ if (ts.isUnionTypeNode(node)) {
3697
+ const allLiterals = yield* option(parseAllLiterals(node));
3698
+ if (isSome2(allLiterals)) return createApiCall("Literal", allLiterals.value);
3699
+ const members = yield* all2(...node.types.map((_) => processNode(_)));
3700
+ return createApiCall("Union", members);
3701
+ }
3702
+ if (ts.isIntersectionTypeNode(node)) {
3703
+ const [firstSchema, ...otherSchemas] = yield* all2(
3704
+ ...node.types.map((_) => processNode(_))
3705
+ );
3706
+ if (otherSchemas.length === 0) return firstSchema;
3707
+ return ts.factory.createCallExpression(
3708
+ ts.factory.createPropertyAccessExpression(
3709
+ firstSchema,
3710
+ "pipe"
3711
+ ),
3712
+ [],
3713
+ otherSchemas.map((_) => createApiCall("extend", [_]))
3714
+ );
3715
+ }
3716
+ if (ts.isArrayTypeNode(node)) {
3717
+ const typeSchema = yield* processNode(node.elementType);
3718
+ return createApiCall("Array", [typeSchema]);
3719
+ }
3720
+ if (ts.isTypeLiteralNode(node)) {
3721
+ const { properties, records } = yield* processMembers(node.members);
3722
+ return createApiCall(
3723
+ "Struct",
3724
+ [ts.factory.createObjectLiteralExpression(properties, true)].concat(records)
3725
+ );
3726
+ }
3727
+ if (ts.isTypeReferenceNode(node)) {
3728
+ const parsedName = entityNameToDataTypeName(node.typeName);
3729
+ if (isSome2(parsedName)) {
3730
+ switch (parsedName.value) {
3731
+ case "Duration":
3732
+ case "Date":
3733
+ return createApiPropertyAccess(parsedName.value);
3734
+ case "Option":
3735
+ case "Chunk":
3736
+ case "Array": {
3737
+ const elements = yield* all2(
3738
+ ...node.typeArguments ? node.typeArguments.map(processNode) : []
3739
+ );
3740
+ return createApiCall(parsedName.value, elements);
3741
+ }
3742
+ case "Record": {
3743
+ const elements = yield* all2(
3744
+ ...node.typeArguments ? node.typeArguments.map(processNode) : []
3745
+ );
3746
+ if (elements.length >= 2) {
3747
+ return createApiCall(parsedName.value, [
3748
+ ts.factory.createObjectLiteralExpression([
3749
+ ts.factory.createPropertyAssignment("key", elements[0]),
3750
+ ts.factory.createPropertyAssignment("value", elements[1])
3751
+ ])
3752
+ ]);
3753
+ }
3754
+ return createUnsupportedNodeComment(ts, sourceFile, node);
3755
+ }
3756
+ case "Either": {
3757
+ const elements = yield* all2(
3758
+ ...node.typeArguments ? node.typeArguments.map(processNode) : []
3759
+ );
3760
+ if (elements.length >= 2) {
3761
+ return createApiCall(parsedName.value, [
3762
+ ts.factory.createObjectLiteralExpression([
3763
+ ts.factory.createPropertyAssignment("right", elements[0]),
3764
+ ts.factory.createPropertyAssignment("left", elements[1])
3765
+ ])
3766
+ ]);
3767
+ }
3768
+ return createUnsupportedNodeComment(ts, sourceFile, node);
3769
+ }
3770
+ case "Pick":
3771
+ case "Omit": {
3772
+ const typeArguments = fromIterable(node.typeArguments || []);
3773
+ if (typeArguments.length !== 2) {
3774
+ return createUnsupportedNodeComment(ts, sourceFile, node);
3775
+ }
3776
+ const baseType = yield* processNode(typeArguments[0]);
3777
+ const stringLiteralArguments = yield* option(parseAllLiterals(typeArguments[1]));
3778
+ if (isNone2(stringLiteralArguments)) {
3779
+ return createUnsupportedNodeComment(ts, sourceFile, node);
3780
+ }
3781
+ return ts.factory.createCallExpression(
3782
+ ts.factory.createPropertyAccessExpression(
3783
+ baseType,
3784
+ "pipe"
3785
+ ),
3786
+ [],
3787
+ [createApiCall(parsedName.value.toLowerCase(), stringLiteralArguments.value)]
3788
+ );
3789
+ }
3790
+ }
3791
+ }
3792
+ }
3793
+ if (ts.isTypeReferenceNode(node)) {
3794
+ if (!(node.typeArguments && node.typeArguments.length > 0)) {
3795
+ return yield* typeEntityNameToNode(node.typeName);
3796
+ }
3797
+ }
3798
+ return createUnsupportedNodeComment(ts, sourceFile, node);
3799
+ });
3800
+ var processMembers = fn(
3801
+ "SchemaGen.processMembers"
3802
+ )(
3803
+ function* (members) {
3804
+ const { createApiCall, ts } = yield* service(
3805
+ SchemaGenContext
3806
+ );
3807
+ const properties = [];
3808
+ for (const propertySignature of members.filter(ts.isPropertySignature)) {
3809
+ const name = propertySignature.name;
3810
+ if (!(ts.isIdentifier(name) || ts.isStringLiteral(name))) {
3811
+ return yield* fail(new OnlyLiteralPropertiesSupportedError(propertySignature));
3812
+ }
3813
+ if (!propertySignature.type) {
3814
+ return yield* fail(new RequiredExplicitTypesError(propertySignature));
3815
+ }
3816
+ const propertyAssignment = pipe(
3817
+ yield* processNode(propertySignature.type),
3818
+ propertySignature.questionToken ? (_) => createApiCall("optional", [_]) : identity,
3819
+ (_) => ts.factory.createPropertyAssignment(name, _)
3820
+ );
3821
+ properties.push(propertyAssignment);
3822
+ }
3823
+ const records = [];
3824
+ for (const indexSignature of members.filter(ts.isIndexSignatureDeclaration)) {
3825
+ if (indexSignature.parameters.length !== 1) {
3826
+ return yield* fail(new IndexSignatureWithMoreThanOneParameterError(indexSignature));
3827
+ }
3828
+ const parameter = indexSignature.parameters[0];
3829
+ if (!parameter.type) return yield* fail(new RequiredExplicitTypesError(parameter));
3830
+ const parameterType = parameter.type;
3831
+ const key = yield* processNode(parameterType);
3832
+ const value = yield* processNode(indexSignature.type);
3833
+ records.push(
3834
+ ts.factory.createObjectLiteralExpression([
3835
+ ts.factory.createPropertyAssignment("key", key),
3836
+ ts.factory.createPropertyAssignment("value", value)
3837
+ ])
3838
+ );
3839
+ }
3840
+ return { properties, records };
3841
+ }
3842
+ );
3843
+ var processInterfaceDeclaration = fn("SchemaGen.processInterfaceDeclaration")(
3844
+ function* (node, preferClass) {
3845
+ if (node.typeParameters && node.typeParameters.length > 0) {
3846
+ return yield* fail(new TypeParametersNotSupportedError(node));
3847
+ }
3848
+ const { createApiCall, ts } = yield* service(
3849
+ SchemaGenContext
3850
+ );
3851
+ const { properties, records } = yield* processMembers(node.members);
3852
+ if (preferClass && records.length === 0) {
3853
+ return yield* createExportSchemaClassDeclaration(node.name.text, properties);
3854
+ }
3855
+ const schemaStruct = createApiCall(
3856
+ "Struct",
3857
+ [ts.factory.createObjectLiteralExpression(properties, true)].concat(records)
3858
+ );
3859
+ return yield* createExportVariableDeclaration(node.name.text, schemaStruct);
3860
+ }
3861
+ );
3862
+ var processTypeAliasDeclaration = fn("SchemaGen.processInterfaceDeclaration")(
3863
+ function* (node, preferClass) {
3864
+ const { ts } = yield* service(SchemaGenContext);
3865
+ if (node.typeParameters && node.typeParameters.length > 0) {
3866
+ return yield* fail(new TypeParametersNotSupportedError(node));
3867
+ }
3868
+ if (preferClass && ts.isTypeLiteralNode(node.type)) {
3869
+ const { properties, records } = yield* processMembers(node.type.members);
3870
+ if (records.length === 0) {
3871
+ return yield* createExportSchemaClassDeclaration(node.name.text, properties);
3872
+ }
3873
+ }
3874
+ const effectSchema = yield* processNode(node.type);
3875
+ return yield* createExportVariableDeclaration(node.name.text, effectSchema);
3876
+ }
3877
+ );
3878
+ var createExportVariableDeclaration = fn("SchemaGen.createExportVariableDeclaration")(
3879
+ function* (name, initializer) {
3880
+ const ts = yield* service(TypeScriptApi);
3881
+ return ts.factory.createVariableStatement(
3882
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
3883
+ ts.factory.createVariableDeclarationList([
3884
+ ts.factory.createVariableDeclaration(
3885
+ ts.factory.createIdentifier(name),
3886
+ void 0,
3887
+ void 0,
3888
+ initializer
3889
+ )
3890
+ ], ts.NodeFlags.Const)
3891
+ );
3892
+ }
3893
+ );
3894
+ var createExportSchemaClassDeclaration = fn("SchemaGen.createExportSchemaClassDeclaration")(
3895
+ function* (name, members) {
3896
+ const { createApiPropertyAccess } = yield* service(SchemaGenContext);
3897
+ const ts = yield* service(TypeScriptApi);
3898
+ return ts.factory.createClassDeclaration(
3899
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
3900
+ ts.factory.createIdentifier(name),
3901
+ [],
3902
+ [ts.factory.createHeritageClause(
3903
+ ts.SyntaxKind.ExtendsKeyword,
3904
+ [
3905
+ ts.factory.createExpressionWithTypeArguments(
3906
+ ts.factory.createCallExpression(
3907
+ ts.factory.createCallExpression(
3908
+ createApiPropertyAccess("Class"),
3909
+ [ts.factory.createTypeReferenceNode(
3910
+ name
3911
+ )],
3912
+ [ts.factory.createStringLiteral(name)]
3913
+ ),
3914
+ [],
3915
+ [ts.factory.createObjectLiteralExpression(
3916
+ members,
3917
+ true
3918
+ )]
3919
+ ),
3920
+ []
3921
+ )
3922
+ ]
3923
+ )],
3924
+ []
3925
+ );
3926
+ }
3927
+ );
3928
+ var process = fn("SchemaGen.process")(
3929
+ function* (sourceFile, node, preferClass) {
3930
+ const ctx = yield* makeSchemaGenContext(sourceFile);
3931
+ const ts = yield* service(TypeScriptApi);
3932
+ return yield* pipe(
3933
+ ts.isInterfaceDeclaration(node) ? processInterfaceDeclaration(node, preferClass) : processTypeAliasDeclaration(node, preferClass),
3934
+ provideService(SchemaGenContext, ctx)
3935
+ );
3936
+ }
3937
+ );
3938
+ var findNodeToProcess = fn("SchemaGen.findNodeToProcess")(
3939
+ function* (sourceFile, textRange) {
3940
+ const ts = yield* service(TypeScriptApi);
3941
+ return pipe(
3942
+ yield* getAncestorNodesInRange(sourceFile, textRange),
3943
+ filter((node) => ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)),
3944
+ filter((node) => isNodeInRange(textRange)(node.name)),
3945
+ filter((node) => (node.typeParameters || []).length === 0),
3946
+ head
3947
+ );
3948
+ }
3949
+ );
3950
+ var applyAtNode = fn("SchemaGen.applyAtNode")(
3951
+ function* (sourceFile, node, preferClass) {
3952
+ const ts = yield* service(TypeScriptApi);
3953
+ const changeTracker = yield* service(ChangeTracker);
3954
+ const newNode = yield* pipe(
3955
+ process(sourceFile, node, preferClass),
3956
+ orElse3(
3957
+ (error) => succeed(ts.addSyntheticLeadingComment(
3958
+ ts.factory.createIdentifier(""),
3959
+ ts.SyntaxKind.MultiLineCommentTrivia,
3960
+ " " + String(error) + " ",
3961
+ true
3962
+ ))
3963
+ )
3964
+ );
3965
+ changeTracker.insertNodeBefore(sourceFile, node, newNode, true, {
3966
+ leadingTriviaOption: ts.textChanges.LeadingTriviaOption.StartLine
3967
+ });
3968
+ }
3969
+ );
3970
+
3971
+ // src/refactors/typeToEffectSchema.ts
3972
+ var typeToEffectSchema = createRefactor({
3973
+ name: "effect/typeToEffectSchema",
3974
+ description: "Refactor to Schema",
3975
+ apply: fn("typeToEffectSchema.apply")(function* (sourceFile, textRange) {
3976
+ const ts = yield* service(TypeScriptApi);
3977
+ const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
3978
+ if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
3979
+ const node = maybeNode.value;
3980
+ return {
3981
+ kind: "refactor.rewrite.effect.typeToEffectSchema",
3982
+ description: "Refactor to Schema",
3983
+ apply: pipe(
3984
+ applyAtNode(sourceFile, node, false),
3985
+ provideService(TypeScriptApi, ts)
3986
+ )
3987
+ };
3988
+ })
3989
+ });
3990
+
3991
+ // src/refactors/typeToEffectSchemaClass.ts
3992
+ var typeToEffectSchemaClass = createRefactor({
3993
+ name: "effect/typeToEffectSchemaClass",
3994
+ description: "Refactor to Schema.Class",
3995
+ apply: fn("typeToEffectSchemaClass.apply")(function* (sourceFile, textRange) {
3996
+ const ts = yield* service(TypeScriptApi);
3997
+ const maybeNode = yield* findNodeToProcess(sourceFile, textRange);
3998
+ if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
3999
+ const node = maybeNode.value;
4000
+ return {
4001
+ kind: "refactor.rewrite.effect.typeToEffectSchemaClass",
4002
+ description: "Refactor to Schema.Class",
4003
+ apply: pipe(
4004
+ applyAtNode(sourceFile, node, true),
4005
+ provideService(TypeScriptApi, ts)
4006
+ )
4007
+ };
4008
+ })
4009
+ });
4010
+
3514
4011
  // src/refactors/wrapWithEffectGen.ts
3515
4012
  var wrapWithEffectGen = createRefactor({
3516
4013
  name: "effect/wrapWithEffectGen",
@@ -3601,6 +4098,8 @@ var refactors = [
3601
4098
  asyncAwaitToGen,
3602
4099
  asyncAwaitToGenTryPromise,
3603
4100
  functionToArrow,
4101
+ typeToEffectSchema,
4102
+ typeToEffectSchemaClass,
3604
4103
  makeSchemaOpaque,
3605
4104
  makeSchemaOpaqueWithNs,
3606
4105
  pipeableToDatafirst,