@effect/language-service 0.15.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/index.js +78 -43
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +33 -29
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -1004,23 +1004,27 @@ var contextGet = (context, tag) => {
|
|
|
1004
1004
|
}
|
|
1005
1005
|
return none2();
|
|
1006
1006
|
};
|
|
1007
|
-
var
|
|
1008
|
-
|
|
1009
|
-
|
|
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.
|
|
1023
|
+
return left2(result.value);
|
|
1020
1024
|
case "Defect":
|
|
1021
|
-
return left2(new NanoDefectException(result.
|
|
1025
|
+
return left2(new NanoDefectException(result.value));
|
|
1022
1026
|
case "Right":
|
|
1023
|
-
return right2(result.
|
|
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) =>
|
|
1034
|
-
var fail = (value) =>
|
|
1035
|
-
var sync = (value) =>
|
|
1036
|
-
var flatMap3 = dual(2, (fa, f) =>
|
|
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.
|
|
1043
|
+
return f(result.value).run(ctx);
|
|
1040
1044
|
}));
|
|
1041
|
-
var map3 = dual(2, (fa, f) =>
|
|
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",
|
|
1048
|
+
return { _tag: "Right", value: f(result.value) };
|
|
1045
1049
|
}));
|
|
1046
|
-
var orElse3 = (f) => (fa) =>
|
|
1050
|
+
var orElse3 = (f) => (fa) => make3((ctx) => {
|
|
1047
1051
|
const result = fa.run(ctx);
|
|
1048
|
-
if (result._tag === "Left") return f(result.
|
|
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) =>
|
|
1056
|
+
var service = (tag) => make3(
|
|
1053
1057
|
(ctx) => contextGet(ctx, tag).pipe(match2({
|
|
1054
|
-
onNone: () => ({ _tag: "Defect",
|
|
1055
|
-
onSome: (value) => ({ _tag: "Right",
|
|
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) =>
|
|
1062
|
+
var provideService = (tag, value) => (fa) => make3((ctx) => {
|
|
1059
1063
|
return fa.run(contextAdd(ctx, tag, value));
|
|
1060
1064
|
});
|
|
1061
|
-
var gen2 = (...args) =>
|
|
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.
|
|
1074
|
+
state = iterator.next(result.value);
|
|
1071
1075
|
}
|
|
1072
|
-
return { _tag: "Right",
|
|
1076
|
+
return { _tag: "Right", value: state.value };
|
|
1073
1077
|
});
|
|
1074
|
-
var fn = (_) => (body) => (...args) =>
|
|
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,17 +1084,17 @@ var fn = (_) => (body) => (...args) => new Nano((ctx) => {
|
|
|
1080
1084
|
if (result._tag !== "Right") {
|
|
1081
1085
|
return result;
|
|
1082
1086
|
}
|
|
1083
|
-
state = iterator.next(result.
|
|
1087
|
+
state = iterator.next(result.value);
|
|
1084
1088
|
}
|
|
1085
|
-
return { _tag: "Right",
|
|
1089
|
+
return { _tag: "Right", value: state.value };
|
|
1086
1090
|
});
|
|
1087
|
-
var option = (fa) =>
|
|
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",
|
|
1095
|
+
return { _tag: "Right", value: some2(result.value) };
|
|
1092
1096
|
case "Left":
|
|
1093
|
-
return { _tag: "Right",
|
|
1097
|
+
return { _tag: "Right", value: none2() };
|
|
1094
1098
|
case "Defect":
|
|
1095
1099
|
return result;
|
|
1096
1100
|
}
|
|
@@ -3595,6 +3599,7 @@ var makeSchemaGenContext = fn("SchemaGen.makeSchemaGenContext")(function* (sourc
|
|
|
3595
3599
|
case "Date":
|
|
3596
3600
|
case "Pick":
|
|
3597
3601
|
case "Omit":
|
|
3602
|
+
case "Record":
|
|
3598
3603
|
return some2(name.text);
|
|
3599
3604
|
case "ReadonlyArray":
|
|
3600
3605
|
case "Array":
|
|
@@ -3631,8 +3636,17 @@ var parseAllLiterals = fn(
|
|
|
3631
3636
|
)(
|
|
3632
3637
|
function* (node) {
|
|
3633
3638
|
const { ts } = yield* service(SchemaGenContext);
|
|
3634
|
-
if (ts.isLiteralTypeNode(node)
|
|
3635
|
-
|
|
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
|
+
}
|
|
3636
3650
|
}
|
|
3637
3651
|
if (ts.isUnionTypeNode(node)) {
|
|
3638
3652
|
return flatten(yield* all2(...node.types.map((_) => parseAllLiterals(_))));
|
|
@@ -3675,23 +3689,30 @@ var processNode = (node) => gen2(function* () {
|
|
|
3675
3689
|
return createApiPropertyAccess("BigInt");
|
|
3676
3690
|
}
|
|
3677
3691
|
if (ts.isLiteralTypeNode(node)) {
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
case ts.SyntaxKind.TrueKeyword:
|
|
3682
|
-
return createApiCall("Literal", [ts.factory.createTrue()]);
|
|
3683
|
-
case ts.SyntaxKind.FalseKeyword:
|
|
3684
|
-
return createApiCall("Literal", [ts.factory.createFalse()]);
|
|
3685
|
-
case ts.SyntaxKind.StringLiteral:
|
|
3686
|
-
return createApiCall("Literal", [ts.factory.createStringLiteral(node.literal.text)]);
|
|
3687
|
-
case ts.SyntaxKind.NumericLiteral:
|
|
3688
|
-
return createApiCall("Literal", [ts.factory.createNumericLiteral(node.literal.text)]);
|
|
3689
|
-
}
|
|
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);
|
|
3690
3695
|
}
|
|
3691
3696
|
if (ts.isUnionTypeNode(node)) {
|
|
3697
|
+
const allLiterals = yield* option(parseAllLiterals(node));
|
|
3698
|
+
if (isSome2(allLiterals)) return createApiCall("Literal", allLiterals.value);
|
|
3692
3699
|
const members = yield* all2(...node.types.map((_) => processNode(_)));
|
|
3693
3700
|
return createApiCall("Union", members);
|
|
3694
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
|
+
}
|
|
3695
3716
|
if (ts.isArrayTypeNode(node)) {
|
|
3696
3717
|
const typeSchema = yield* processNode(node.elementType);
|
|
3697
3718
|
return createApiCall("Array", [typeSchema]);
|
|
@@ -3718,6 +3739,20 @@ var processNode = (node) => gen2(function* () {
|
|
|
3718
3739
|
);
|
|
3719
3740
|
return createApiCall(parsedName.value, elements);
|
|
3720
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
|
+
}
|
|
3721
3756
|
case "Either": {
|
|
3722
3757
|
const elements = yield* all2(
|
|
3723
3758
|
...node.typeArguments ? node.typeArguments.map(processNode) : []
|