@effect/language-service 0.73.1 → 0.74.0
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/cli.js +206 -29
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +205 -28
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +264 -46
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +205 -28
- package/transform.js.map +1 -1
package/package.json
CHANGED
package/transform.js
CHANGED
|
@@ -3404,6 +3404,28 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3404
3404
|
`TypeParser.isNodeReferenceToEffectParseResultModuleApi(${memberName})`,
|
|
3405
3405
|
(node) => node
|
|
3406
3406
|
);
|
|
3407
|
+
const isEffectSchemaParserSourceFile = cachedBy(
|
|
3408
|
+
fn("TypeParser.isEffectSchemaParserSourceFile")(function* (sourceFile) {
|
|
3409
|
+
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
|
3410
|
+
if (!moduleSymbol) return yield* typeParserIssue("Node has no symbol", void 0, sourceFile);
|
|
3411
|
+
const parseIssueSymbol = typeChecker.tryGetMemberInModuleExports("Parser", moduleSymbol);
|
|
3412
|
+
if (!parseIssueSymbol) return yield* typeParserIssue("ParseIssue type not found", void 0, sourceFile);
|
|
3413
|
+
const decodeSyncSymbol = typeChecker.tryGetMemberInModuleExports("decodeEffect", moduleSymbol);
|
|
3414
|
+
if (!decodeSyncSymbol) return yield* typeParserIssue("decodeSync not found", void 0, sourceFile);
|
|
3415
|
+
const encodeSyncSymbol = typeChecker.tryGetMemberInModuleExports("encodeEffect", moduleSymbol);
|
|
3416
|
+
if (!encodeSyncSymbol) return yield* typeParserIssue("encodeSync not found", void 0, sourceFile);
|
|
3417
|
+
return sourceFile;
|
|
3418
|
+
}),
|
|
3419
|
+
"TypeParser.isEffectSchemaParserSourceFile",
|
|
3420
|
+
(sourceFile) => sourceFile
|
|
3421
|
+
);
|
|
3422
|
+
const isNodeReferenceToEffectSchemaParserModuleApi = (memberName) => cachedBy(
|
|
3423
|
+
fn("TypeParser.isNodeReferenceToEffectSchemaParserModuleApi")(function* (node) {
|
|
3424
|
+
return yield* isNodeReferenceToExportOfPackageModule(node, "effect", isEffectSchemaParserSourceFile, memberName);
|
|
3425
|
+
}),
|
|
3426
|
+
`TypeParser.isNodeReferenceToEffectSchemaParserModuleApi(${memberName})`,
|
|
3427
|
+
(node) => node
|
|
3428
|
+
);
|
|
3407
3429
|
const contextTagVarianceStruct = (type, atLocation) => map4(
|
|
3408
3430
|
all(
|
|
3409
3431
|
varianceStructInvariantType(type, atLocation, "_Identifier"),
|
|
@@ -3411,6 +3433,31 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3411
3433
|
),
|
|
3412
3434
|
([Identifier, Service]) => ({ Identifier, Service })
|
|
3413
3435
|
);
|
|
3436
|
+
const serviceVarianceStruct = (type, atLocation) => map4(
|
|
3437
|
+
all(
|
|
3438
|
+
varianceStructInvariantType(type, atLocation, "_Identifier"),
|
|
3439
|
+
varianceStructInvariantType(type, atLocation, "_Service")
|
|
3440
|
+
),
|
|
3441
|
+
([Identifier, Service]) => ({ Identifier, Service })
|
|
3442
|
+
);
|
|
3443
|
+
const serviceType = cachedBy(
|
|
3444
|
+
fn("TypeParser.serviceType")(function* (type, atLocation) {
|
|
3445
|
+
yield* pipeableType(type, atLocation);
|
|
3446
|
+
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
3447
|
+
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
|
|
3448
|
+
);
|
|
3449
|
+
if (propertiesSymbols.length === 0) {
|
|
3450
|
+
return yield* typeParserIssue("Type has no tag variance struct", type, atLocation);
|
|
3451
|
+
}
|
|
3452
|
+
propertiesSymbols.sort((a, b) => ts.symbolName(b).indexOf("TypeId") - ts.symbolName(a).indexOf("TypeId"));
|
|
3453
|
+
return yield* firstSuccessOf(propertiesSymbols.map((propertySymbol) => {
|
|
3454
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
3455
|
+
return serviceVarianceStruct(propertyType, atLocation);
|
|
3456
|
+
}));
|
|
3457
|
+
}),
|
|
3458
|
+
"TypeParser.serviceType",
|
|
3459
|
+
(type) => type
|
|
3460
|
+
);
|
|
3414
3461
|
const contextTag = cachedBy(
|
|
3415
3462
|
fn("TypeParser.contextTag")(function* (type, atLocation) {
|
|
3416
3463
|
yield* pipeableType(type, atLocation);
|
|
@@ -3492,14 +3539,22 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3492
3539
|
);
|
|
3493
3540
|
const scopeType = cachedBy(
|
|
3494
3541
|
fn("TypeParser.scopeType")(function* (type, atLocation) {
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
return type;
|
|
3542
|
+
if (supportedEffect() === "v4") {
|
|
3543
|
+
const typeIdSymbol = typeChecker.getPropertyOfType(type, "~effect/Scope");
|
|
3544
|
+
if (typeIdSymbol) {
|
|
3545
|
+
return type;
|
|
3546
|
+
}
|
|
3547
|
+
return yield* typeParserIssue("Type is not an effect", type, atLocation);
|
|
3548
|
+
} else {
|
|
3549
|
+
yield* pipeableType(type, atLocation);
|
|
3550
|
+
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
3551
|
+
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
|
|
3552
|
+
);
|
|
3553
|
+
if (propertiesSymbols.some((s) => ts.symbolName(s).indexOf("ScopeTypeId") !== -1)) {
|
|
3554
|
+
return type;
|
|
3555
|
+
}
|
|
3556
|
+
return yield* typeParserIssue("Type has no scope type id", type, atLocation);
|
|
3501
3557
|
}
|
|
3502
|
-
return yield* typeParserIssue("Type has no scope type id", type, atLocation);
|
|
3503
3558
|
}),
|
|
3504
3559
|
"TypeParser.scopeType",
|
|
3505
3560
|
(type) => type
|
|
@@ -3981,6 +4036,55 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3981
4036
|
"TypeParser.extendsEffectService",
|
|
3982
4037
|
(atLocation) => atLocation
|
|
3983
4038
|
);
|
|
4039
|
+
const extendsServiceMapService = cachedBy(
|
|
4040
|
+
fn("TypeParser.extendsServiceMapService")(function* (atLocation) {
|
|
4041
|
+
if (!atLocation.name) {
|
|
4042
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
4043
|
+
}
|
|
4044
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
4045
|
+
if (!heritageClauses) {
|
|
4046
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
4047
|
+
}
|
|
4048
|
+
for (const heritageClause of heritageClauses) {
|
|
4049
|
+
for (const typeX of heritageClause.types) {
|
|
4050
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
4051
|
+
const wholeCall = typeX.expression;
|
|
4052
|
+
if (ts.isCallExpression(wholeCall)) {
|
|
4053
|
+
const serviceMapServiceCall = wholeCall.expression;
|
|
4054
|
+
if (ts.isCallExpression(serviceMapServiceCall) && serviceMapServiceCall.typeArguments && serviceMapServiceCall.typeArguments.length > 0) {
|
|
4055
|
+
const serviceMapServiceIdentifier = serviceMapServiceCall.expression;
|
|
4056
|
+
const selfTypeNode = serviceMapServiceCall.typeArguments[0];
|
|
4057
|
+
const isServiceMapService = yield* pipe(
|
|
4058
|
+
isNodeReferenceToServiceMapModuleApi("Service")(serviceMapServiceIdentifier),
|
|
4059
|
+
orUndefined
|
|
4060
|
+
);
|
|
4061
|
+
if (isServiceMapService) {
|
|
4062
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
4063
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
4064
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
4065
|
+
const parsedServiceType = yield* pipe(
|
|
4066
|
+
serviceType(type, atLocation),
|
|
4067
|
+
orUndefined
|
|
4068
|
+
);
|
|
4069
|
+
if (parsedServiceType) {
|
|
4070
|
+
return {
|
|
4071
|
+
...parsedServiceType,
|
|
4072
|
+
className: atLocation.name,
|
|
4073
|
+
selfTypeNode,
|
|
4074
|
+
keyStringLiteral: wholeCall.arguments.length > 0 && ts.isStringLiteral(wholeCall.arguments[0]) ? wholeCall.arguments[0] : void 0
|
|
4075
|
+
};
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
}
|
|
4083
|
+
return yield* typeParserIssue("Class does not extend ServiceMap.Service", void 0, atLocation);
|
|
4084
|
+
}),
|
|
4085
|
+
"TypeParser.extendsServiceMapService",
|
|
4086
|
+
(atLocation) => atLocation
|
|
4087
|
+
);
|
|
3984
4088
|
const isEffectSqlModelTypeSourceFile = cachedBy(
|
|
3985
4089
|
fn("TypeParser.isEffectSqlModelTypeSourceFile")(function* (sourceFile) {
|
|
3986
4090
|
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
|
@@ -4073,6 +4177,24 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
4073
4177
|
`TypeParser.isNodeReferenceToEffectLayerModuleApi(${memberName})`,
|
|
4074
4178
|
(node) => node
|
|
4075
4179
|
);
|
|
4180
|
+
const isServiceMapTypeSourceFile = cachedBy(
|
|
4181
|
+
fn("TypeParser.isServiceMapTypeSourceFile")(function* (sourceFile) {
|
|
4182
|
+
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
|
4183
|
+
if (!moduleSymbol) return yield* typeParserIssue("Node has no symbol", void 0, sourceFile);
|
|
4184
|
+
const serviceMapSymbol = typeChecker.tryGetMemberInModuleExports("ServiceMap", moduleSymbol);
|
|
4185
|
+
if (!serviceMapSymbol) return yield* typeParserIssue("ServiceMap not found", void 0, sourceFile);
|
|
4186
|
+
return sourceFile;
|
|
4187
|
+
}),
|
|
4188
|
+
"TypeParser.isServiceMapTypeSourceFile",
|
|
4189
|
+
(sourceFile) => sourceFile
|
|
4190
|
+
);
|
|
4191
|
+
const isNodeReferenceToServiceMapModuleApi = (memberName) => cachedBy(
|
|
4192
|
+
fn("TypeParser.isNodeReferenceToServiceMapModuleApi")(function* (node) {
|
|
4193
|
+
return yield* isNodeReferenceToExportOfPackageModule(node, "effect", isServiceMapTypeSourceFile, memberName);
|
|
4194
|
+
}),
|
|
4195
|
+
`TypeParser.isNodeReferenceToServiceMapModuleApi(${memberName})`,
|
|
4196
|
+
(node) => node
|
|
4197
|
+
);
|
|
4076
4198
|
const lazyExpression = cachedBy(
|
|
4077
4199
|
function(node) {
|
|
4078
4200
|
if (!ts.isArrowFunction(node) && !ts.isFunctionExpression(node)) {
|
|
@@ -4403,6 +4525,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
4403
4525
|
isNodeReferenceToEffectContextModuleApi,
|
|
4404
4526
|
isNodeReferenceToEffectSqlModelModuleApi,
|
|
4405
4527
|
isNodeReferenceToEffectLayerModuleApi,
|
|
4528
|
+
isNodeReferenceToEffectSchemaParserModuleApi,
|
|
4529
|
+
isServiceMapTypeSourceFile,
|
|
4530
|
+
isNodeReferenceToServiceMapModuleApi,
|
|
4406
4531
|
effectType,
|
|
4407
4532
|
strictEffectType,
|
|
4408
4533
|
layerType,
|
|
@@ -4418,6 +4543,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
4418
4543
|
unnecessaryEffectGen: unnecessaryEffectGen2,
|
|
4419
4544
|
effectSchemaType,
|
|
4420
4545
|
contextTag,
|
|
4546
|
+
serviceType,
|
|
4421
4547
|
pipeableType,
|
|
4422
4548
|
pipeCall,
|
|
4423
4549
|
singleArgCall,
|
|
@@ -4425,6 +4551,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
4425
4551
|
promiseLike,
|
|
4426
4552
|
extendsEffectTag,
|
|
4427
4553
|
extendsEffectService,
|
|
4554
|
+
extendsServiceMapService,
|
|
4428
4555
|
extendsContextTag,
|
|
4429
4556
|
extendsSchemaClass,
|
|
4430
4557
|
extendsSchemaTaggedClass,
|
|
@@ -4902,6 +5029,7 @@ var deterministicKeys = createDiagnostic({
|
|
|
4902
5029
|
typeParser.extendsEffectService(node),
|
|
4903
5030
|
orElse2(() => typeParser.extendsContextTag(node)),
|
|
4904
5031
|
orElse2(() => typeParser.extendsEffectTag(node)),
|
|
5032
|
+
orElse2(() => typeParser.extendsServiceMapService(node)),
|
|
4905
5033
|
map4(({ className, keyStringLiteral }) => ({ keyStringLiteral, className, target: "service" }))
|
|
4906
5034
|
),
|
|
4907
5035
|
orElse2(
|
|
@@ -6297,6 +6425,9 @@ More info and examples at https://effect.website/docs/requirements-management/la
|
|
|
6297
6425
|
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && ts.idText(node.expression.name) === "GenericTag") {
|
|
6298
6426
|
const nodeType = typeCheckerUtils.getTypeAtLocation(node);
|
|
6299
6427
|
if (nodeType) typesToCheck.push([nodeType, node]);
|
|
6428
|
+
} else if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && ts.idText(node.expression.name) === "Service") {
|
|
6429
|
+
const nodeType = typeCheckerUtils.getTypeAtLocation(node);
|
|
6430
|
+
if (nodeType) typesToCheck.push([nodeType, node]);
|
|
6300
6431
|
} else if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {
|
|
6301
6432
|
const classSym = typeChecker.getSymbolAtLocation(node.name);
|
|
6302
6433
|
if (classSym) {
|
|
@@ -6310,6 +6441,7 @@ More info and examples at https://effect.website/docs/requirements-management/la
|
|
|
6310
6441
|
for (const [type, reportAt] of typesToCheck) {
|
|
6311
6442
|
yield* pipe(
|
|
6312
6443
|
typeParser.contextTag(type, node),
|
|
6444
|
+
orElse2(() => typeParser.serviceType(type, node)),
|
|
6313
6445
|
flatMap2(
|
|
6314
6446
|
({ Service }) => pipe(
|
|
6315
6447
|
parseLeakedRequirements(Service, node),
|
|
@@ -7084,6 +7216,7 @@ var nonObjectEffectServiceType = createDiagnostic({
|
|
|
7084
7216
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
7085
7217
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
7086
7218
|
const typeParser = yield* service(TypeParser);
|
|
7219
|
+
if (typeParser.supportedEffect() === "v4") return;
|
|
7087
7220
|
function isPrimitiveType(type) {
|
|
7088
7221
|
return typeCheckerUtils.unrollUnionMembers(type).some(
|
|
7089
7222
|
(type2) => !!(type2.flags & ts.TypeFlags.String || type2.flags & ts.TypeFlags.Number || type2.flags & ts.TypeFlags.Boolean || type2.flags & ts.TypeFlags.StringLiteral || type2.flags & ts.TypeFlags.NumberLiteral || type2.flags & ts.TypeFlags.BooleanLiteral || type2.flags & ts.TypeFlags.Undefined || type2.flags & ts.TypeFlags.Null)
|
|
@@ -7368,6 +7501,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
|
7368
7501
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
7369
7502
|
const typeParser = yield* service(TypeParser);
|
|
7370
7503
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
7504
|
+
if (typeParser.supportedEffect() === "v4") return yield* fail("not applicable to Effect v4");
|
|
7371
7505
|
if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
|
|
7372
7506
|
const { Service, accessors: accessors2, className, kind } = yield* pipe(
|
|
7373
7507
|
map4(typeParser.extendsEffectService(node), (_) => ({ kind: "effectService", ..._ })),
|
|
@@ -7610,16 +7744,16 @@ var pushHoistedVariableStatement = fn("StructuralSchemaGen.pushHoistedVariableSt
|
|
|
7610
7744
|
);
|
|
7611
7745
|
}
|
|
7612
7746
|
);
|
|
7613
|
-
var createProcessingContext = (maxDepth = 200) => ({
|
|
7747
|
+
var createProcessingContext = (supportedEffect, maxDepth = 200) => ({
|
|
7614
7748
|
depth: 0,
|
|
7615
7749
|
maxDepth,
|
|
7616
|
-
hoistName: void 0
|
|
7750
|
+
hoistName: void 0,
|
|
7751
|
+
supportedEffect
|
|
7617
7752
|
});
|
|
7618
7753
|
var processType = fn(
|
|
7619
7754
|
"StructuralSchemaGen.processType"
|
|
7620
7755
|
)(
|
|
7621
|
-
function* (type,
|
|
7622
|
-
const processingContext = context || createProcessingContext();
|
|
7756
|
+
function* (type, processingContext) {
|
|
7623
7757
|
const { hoistedSchemas, nameToType, ts, typeChecker, usedGlobalIdentifiers } = yield* service(
|
|
7624
7758
|
StructuralSchemaGenContext
|
|
7625
7759
|
);
|
|
@@ -7754,7 +7888,7 @@ var processUnionType = fn(
|
|
|
7754
7888
|
const allLiterals = types.every(
|
|
7755
7889
|
(t) => t.flags & ts.TypeFlags.StringLiteral || t.flags & ts.TypeFlags.NumberLiteral || t.flags & ts.TypeFlags.BooleanLiteral
|
|
7756
7890
|
);
|
|
7757
|
-
if (allLiterals) {
|
|
7891
|
+
if (allLiterals && context.supportedEffect !== "v4") {
|
|
7758
7892
|
const literals = yield* all(
|
|
7759
7893
|
...types.map((t) => processType(t, context))
|
|
7760
7894
|
);
|
|
@@ -7764,7 +7898,13 @@ var processUnionType = fn(
|
|
|
7764
7898
|
}
|
|
7765
7899
|
return expr;
|
|
7766
7900
|
}).filter((arg) => arg !== void 0);
|
|
7767
|
-
return [
|
|
7901
|
+
return [
|
|
7902
|
+
createApiCall(
|
|
7903
|
+
"Literal",
|
|
7904
|
+
literalValues
|
|
7905
|
+
),
|
|
7906
|
+
false
|
|
7907
|
+
];
|
|
7768
7908
|
}
|
|
7769
7909
|
const members = yield* all(
|
|
7770
7910
|
...types.map((t) => processType(t, context))
|
|
@@ -7772,7 +7912,13 @@ var processUnionType = fn(
|
|
|
7772
7912
|
if (members.length === 1) {
|
|
7773
7913
|
return [members[0], false];
|
|
7774
7914
|
}
|
|
7775
|
-
return [
|
|
7915
|
+
return [
|
|
7916
|
+
createApiCall(
|
|
7917
|
+
"Union",
|
|
7918
|
+
context.supportedEffect === "v4" ? [ts.factory.createArrayLiteralExpression(members)] : members
|
|
7919
|
+
),
|
|
7920
|
+
false
|
|
7921
|
+
];
|
|
7776
7922
|
}
|
|
7777
7923
|
);
|
|
7778
7924
|
var processIntersectionType = fn(
|
|
@@ -7818,12 +7964,18 @@ var processTupleType = fn(
|
|
|
7818
7964
|
"StructuralSchemaGen.processTupleType"
|
|
7819
7965
|
)(
|
|
7820
7966
|
function* (type, context) {
|
|
7821
|
-
const { createApiCall, typeChecker } = yield* service(StructuralSchemaGenContext);
|
|
7967
|
+
const { createApiCall, ts, typeChecker } = yield* service(StructuralSchemaGenContext);
|
|
7822
7968
|
const typeArgs = typeChecker.getTypeArguments(type);
|
|
7823
7969
|
const elementSchemas = yield* all(
|
|
7824
7970
|
...typeArgs.map((t) => processType(t, context))
|
|
7825
7971
|
);
|
|
7826
|
-
return [
|
|
7972
|
+
return [
|
|
7973
|
+
createApiCall(
|
|
7974
|
+
"Tuple",
|
|
7975
|
+
context.supportedEffect === "v4" ? [ts.factory.createArrayLiteralExpression(elementSchemas)] : elementSchemas
|
|
7976
|
+
),
|
|
7977
|
+
false
|
|
7978
|
+
];
|
|
7827
7979
|
}
|
|
7828
7980
|
);
|
|
7829
7981
|
var processObjectType = fn(
|
|
@@ -7840,7 +7992,6 @@ var processObjectType = fn(
|
|
|
7840
7992
|
} = yield* service(
|
|
7841
7993
|
StructuralSchemaGenContext
|
|
7842
7994
|
);
|
|
7843
|
-
let hasRecords = false;
|
|
7844
7995
|
const properties = typeChecker.getPropertiesOfType(type);
|
|
7845
7996
|
const propertyAssignments = [];
|
|
7846
7997
|
for (const property of properties) {
|
|
@@ -7880,20 +8031,28 @@ var processObjectType = fn(
|
|
|
7880
8031
|
const args2 = [
|
|
7881
8032
|
ts.factory.createObjectLiteralExpression(propertyAssignments, propertyAssignments.length > 0)
|
|
7882
8033
|
];
|
|
8034
|
+
const records = [];
|
|
7883
8035
|
for (const indexInfo of indexInfos) {
|
|
7884
|
-
hasRecords = true;
|
|
7885
8036
|
const keyType = indexInfo.keyType;
|
|
7886
8037
|
const valueType = indexInfo.type;
|
|
7887
8038
|
const keySchema = yield* processType(keyType, context);
|
|
7888
8039
|
const valueSchema = yield* processType(valueType, context);
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
8040
|
+
records.push({ key: keySchema, value: valueSchema });
|
|
8041
|
+
}
|
|
8042
|
+
if (context.supportedEffect === "v4") {
|
|
8043
|
+
if (records.length > 0) {
|
|
8044
|
+
return [
|
|
8045
|
+
createApiCall("StructWithRest", [
|
|
8046
|
+
createApiCall("Struct", args2),
|
|
8047
|
+
ts.factory.createArrayLiteralExpression(
|
|
8048
|
+
records.map(({ key, value }) => createApiCall("Record", [key, value]))
|
|
8049
|
+
)
|
|
8050
|
+
]),
|
|
8051
|
+
propertyAssignments.length === 0
|
|
8052
|
+
];
|
|
8053
|
+
}
|
|
7895
8054
|
}
|
|
7896
|
-
if (
|
|
8055
|
+
if (records.length === 0 && context.hoistName) {
|
|
7897
8056
|
const ctx = yield* service(StructuralSchemaGenContext);
|
|
7898
8057
|
yield* pushHoistedStatement(
|
|
7899
8058
|
ctx,
|
|
@@ -7928,6 +8087,14 @@ var processObjectType = fn(
|
|
|
7928
8087
|
);
|
|
7929
8088
|
return [ctx.hoistedSchemas.get(type)(), true];
|
|
7930
8089
|
}
|
|
8090
|
+
for (const { key, value } of records) {
|
|
8091
|
+
args2.push(
|
|
8092
|
+
ts.factory.createObjectLiteralExpression([
|
|
8093
|
+
ts.factory.createPropertyAssignment("key", key),
|
|
8094
|
+
ts.factory.createPropertyAssignment("value", value)
|
|
8095
|
+
])
|
|
8096
|
+
);
|
|
8097
|
+
}
|
|
7931
8098
|
return [createApiCall("Struct", args2), propertyAssignments.length === 0];
|
|
7932
8099
|
}
|
|
7933
8100
|
);
|
|
@@ -8013,7 +8180,7 @@ var process = fn("StructuralSchemaGen.process")(
|
|
|
8013
8180
|
all(
|
|
8014
8181
|
...fromIterable(ctx.nameToType.entries()).map(
|
|
8015
8182
|
([name, type]) => pipe(
|
|
8016
|
-
processType(type),
|
|
8183
|
+
processType(type, createProcessingContext(typeParser.supportedEffect())),
|
|
8017
8184
|
orElse2(
|
|
8018
8185
|
(error) => succeed(ts.addSyntheticLeadingComment(
|
|
8019
8186
|
ts.factory.createIdentifier(""),
|
|
@@ -8595,6 +8762,7 @@ var runEffectInsideEffect = createDiagnostic({
|
|
|
8595
8762
|
const ts = yield* service(TypeScriptApi);
|
|
8596
8763
|
const typeParser = yield* service(TypeParser);
|
|
8597
8764
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
8765
|
+
if (typeParser.supportedEffect() === "v4") return;
|
|
8598
8766
|
const parseEffectMethod = (node, methodName) => pipe(
|
|
8599
8767
|
typeParser.isNodeReferenceToEffectModuleApi(methodName)(node),
|
|
8600
8768
|
map4(() => ({ node, methodName }))
|
|
@@ -8789,12 +8957,18 @@ var schemaStructWithTag = createDiagnostic({
|
|
|
8789
8957
|
});
|
|
8790
8958
|
|
|
8791
8959
|
// src/diagnostics/schemaSyncInEffect.ts
|
|
8792
|
-
var
|
|
8960
|
+
var syncToEffectMethodV3 = {
|
|
8793
8961
|
decodeSync: "decode",
|
|
8794
8962
|
decodeUnknownSync: "decodeUnknown",
|
|
8795
8963
|
encodeSync: "encode",
|
|
8796
8964
|
encodeUnknownSync: "encodeUnknown"
|
|
8797
8965
|
};
|
|
8966
|
+
var syncToEffectMethodV4 = {
|
|
8967
|
+
decodeSync: "decodeEffect",
|
|
8968
|
+
decodeUnknownSync: "decodeUnknownEffect",
|
|
8969
|
+
encodeSync: "encodeEffect",
|
|
8970
|
+
encodeUnknownSync: "encodeUnknownEffect"
|
|
8971
|
+
};
|
|
8798
8972
|
var schemaSyncInEffect = createDiagnostic({
|
|
8799
8973
|
name: "schemaSyncInEffect",
|
|
8800
8974
|
code: 43,
|
|
@@ -8803,8 +8977,10 @@ var schemaSyncInEffect = createDiagnostic({
|
|
|
8803
8977
|
apply: fn("schemaSyncInEffect.apply")(function* (sourceFile, report) {
|
|
8804
8978
|
const ts = yield* service(TypeScriptApi);
|
|
8805
8979
|
const typeParser = yield* service(TypeParser);
|
|
8980
|
+
const syncToEffectMethod = typeParser.supportedEffect() === "v3" ? syncToEffectMethodV3 : syncToEffectMethodV4;
|
|
8806
8981
|
const parseSchemaSyncMethod = (node, methodName) => pipe(
|
|
8807
8982
|
typeParser.isNodeReferenceToEffectParseResultModuleApi(methodName)(node),
|
|
8983
|
+
orElse2(() => typeParser.isNodeReferenceToEffectSchemaParserModuleApi(methodName)(node)),
|
|
8808
8984
|
map4(() => ({ node, methodName }))
|
|
8809
8985
|
);
|
|
8810
8986
|
const nodeToVisit = [];
|
|
@@ -8834,7 +9010,7 @@ var schemaSyncInEffect = createDiagnostic({
|
|
|
8834
9010
|
const effectMethodName = syncToEffectMethod[isSchemaSyncCall.value.methodName];
|
|
8835
9011
|
report({
|
|
8836
9012
|
location: node.expression,
|
|
8837
|
-
messageText: `Using ${nodeText} inside an Effect generator is not recommended. Use Schema.${effectMethodName} instead to get properly typed
|
|
9013
|
+
messageText: `Using ${nodeText} inside an Effect generator is not recommended. Use Schema.${effectMethodName} instead to get properly typed error channel.`,
|
|
8838
9014
|
fixes: []
|
|
8839
9015
|
});
|
|
8840
9016
|
}
|
|
@@ -8850,6 +9026,7 @@ var schemaUnionOfLiterals = createDiagnostic({
|
|
|
8850
9026
|
apply: fn("schemaUnionOfLiterals.apply")(function* (sourceFile, report) {
|
|
8851
9027
|
const ts = yield* service(TypeScriptApi);
|
|
8852
9028
|
const typeParser = yield* service(TypeParser);
|
|
9029
|
+
if (typeParser.supportedEffect() === "v4") return;
|
|
8853
9030
|
const nodeToVisit = [];
|
|
8854
9031
|
const appendNodeToVisit = (node) => {
|
|
8855
9032
|
nodeToVisit.push(node);
|