@effect/language-service 0.73.0 → 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/README.md +10 -0
- package/cli.js +221 -34
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +220 -33
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +279 -51
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +220 -33
- package/transform.js.map +1 -1
|
@@ -1967,7 +1967,7 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
1967
1967
|
const lineOverrides = {};
|
|
1968
1968
|
const sectionOverrides = {};
|
|
1969
1969
|
const skippedRules = [];
|
|
1970
|
-
const regex = /@effect-diagnostics(-next-line)?((?:\s[a-zA-Z0-9/]
|
|
1970
|
+
const regex = /@effect-diagnostics(-next-line)?((?:\s(?:[a-zA-Z0-9/]+|\*):(?:off|warning|error|message|suggestion|skip-file))+)?/gm;
|
|
1971
1971
|
let match2;
|
|
1972
1972
|
while ((match2 = regex.exec(sourceFile.text)) !== null) {
|
|
1973
1973
|
const nextLineCaptureGroup = match2[1];
|
|
@@ -2016,8 +2016,10 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
2016
2016
|
const codeFixes = [];
|
|
2017
2017
|
const ruleNameLowered = rule.name.toLowerCase();
|
|
2018
2018
|
const defaultLevel = pluginOptions.diagnosticSeverity[ruleNameLowered] || rule.severity;
|
|
2019
|
-
if (skippedRules.indexOf(ruleNameLowered) > -1
|
|
2020
|
-
|
|
2019
|
+
if (skippedRules.indexOf(ruleNameLowered) > -1 || skippedRules.indexOf("*") > -1) {
|
|
2020
|
+
return { diagnostics: diagnostics2, codeFixes };
|
|
2021
|
+
}
|
|
2022
|
+
if (defaultLevel === "off" && (lineOverrides[ruleNameLowered] || sectionOverrides[ruleNameLowered] || lineOverrides["*"] || sectionOverrides["*"] || []).length === 0) {
|
|
2021
2023
|
return { diagnostics: diagnostics2, codeFixes };
|
|
2022
2024
|
}
|
|
2023
2025
|
const fixByDisableNextLine = (node) => ({
|
|
@@ -2066,14 +2068,22 @@ var createDiagnosticExecutor = fn("LSP.createCommentDirectivesProcessor")(
|
|
|
2066
2068
|
const unusedLineOverrides = new Set(lineOverrides[ruleNameLowered] || []);
|
|
2067
2069
|
for (const emitted of applicableDiagnostics.slice(0)) {
|
|
2068
2070
|
let newLevel = defaultLevel;
|
|
2069
|
-
const
|
|
2071
|
+
const specificLineOverride = (lineOverrides[ruleNameLowered] || []).find(
|
|
2072
|
+
(_) => _.pos < emitted.range.pos && _.end >= emitted.range.end
|
|
2073
|
+
);
|
|
2074
|
+
const wildcardLineOverride = (lineOverrides["*"] || []).find(
|
|
2070
2075
|
(_) => _.pos < emitted.range.pos && _.end >= emitted.range.end
|
|
2071
2076
|
);
|
|
2077
|
+
const lineOverride = specificLineOverride && wildcardLineOverride ? specificLineOverride.pos >= wildcardLineOverride.pos ? specificLineOverride : wildcardLineOverride : specificLineOverride || wildcardLineOverride;
|
|
2072
2078
|
if (lineOverride) {
|
|
2073
2079
|
newLevel = lineOverride.level;
|
|
2074
2080
|
unusedLineOverrides.delete(lineOverride);
|
|
2075
2081
|
} else {
|
|
2076
|
-
const
|
|
2082
|
+
const specificSectionOverride = (sectionOverrides[ruleNameLowered] || []).find(
|
|
2083
|
+
(_) => _.pos < emitted.range.pos
|
|
2084
|
+
);
|
|
2085
|
+
const wildcardSectionOverride = (sectionOverrides["*"] || []).find((_) => _.pos < emitted.range.pos);
|
|
2086
|
+
const sectionOverride = specificSectionOverride && wildcardSectionOverride ? specificSectionOverride.pos >= wildcardSectionOverride.pos ? specificSectionOverride : wildcardSectionOverride : specificSectionOverride || wildcardSectionOverride;
|
|
2077
2087
|
if (sectionOverride) newLevel = sectionOverride.level;
|
|
2078
2088
|
}
|
|
2079
2089
|
if (!(newLevel in levelToDiagnosticCategory)) continue;
|
|
@@ -3399,6 +3409,28 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3399
3409
|
`TypeParser.isNodeReferenceToEffectParseResultModuleApi(${memberName})`,
|
|
3400
3410
|
(node) => node
|
|
3401
3411
|
);
|
|
3412
|
+
const isEffectSchemaParserSourceFile = cachedBy(
|
|
3413
|
+
fn("TypeParser.isEffectSchemaParserSourceFile")(function* (sourceFile) {
|
|
3414
|
+
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
|
3415
|
+
if (!moduleSymbol) return yield* typeParserIssue("Node has no symbol", void 0, sourceFile);
|
|
3416
|
+
const parseIssueSymbol = typeChecker.tryGetMemberInModuleExports("Parser", moduleSymbol);
|
|
3417
|
+
if (!parseIssueSymbol) return yield* typeParserIssue("ParseIssue type not found", void 0, sourceFile);
|
|
3418
|
+
const decodeSyncSymbol = typeChecker.tryGetMemberInModuleExports("decodeEffect", moduleSymbol);
|
|
3419
|
+
if (!decodeSyncSymbol) return yield* typeParserIssue("decodeSync not found", void 0, sourceFile);
|
|
3420
|
+
const encodeSyncSymbol = typeChecker.tryGetMemberInModuleExports("encodeEffect", moduleSymbol);
|
|
3421
|
+
if (!encodeSyncSymbol) return yield* typeParserIssue("encodeSync not found", void 0, sourceFile);
|
|
3422
|
+
return sourceFile;
|
|
3423
|
+
}),
|
|
3424
|
+
"TypeParser.isEffectSchemaParserSourceFile",
|
|
3425
|
+
(sourceFile) => sourceFile
|
|
3426
|
+
);
|
|
3427
|
+
const isNodeReferenceToEffectSchemaParserModuleApi = (memberName) => cachedBy(
|
|
3428
|
+
fn("TypeParser.isNodeReferenceToEffectSchemaParserModuleApi")(function* (node) {
|
|
3429
|
+
return yield* isNodeReferenceToExportOfPackageModule(node, "effect", isEffectSchemaParserSourceFile, memberName);
|
|
3430
|
+
}),
|
|
3431
|
+
`TypeParser.isNodeReferenceToEffectSchemaParserModuleApi(${memberName})`,
|
|
3432
|
+
(node) => node
|
|
3433
|
+
);
|
|
3402
3434
|
const contextTagVarianceStruct = (type, atLocation) => map4(
|
|
3403
3435
|
all(
|
|
3404
3436
|
varianceStructInvariantType(type, atLocation, "_Identifier"),
|
|
@@ -3406,6 +3438,31 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3406
3438
|
),
|
|
3407
3439
|
([Identifier, Service]) => ({ Identifier, Service })
|
|
3408
3440
|
);
|
|
3441
|
+
const serviceVarianceStruct = (type, atLocation) => map4(
|
|
3442
|
+
all(
|
|
3443
|
+
varianceStructInvariantType(type, atLocation, "_Identifier"),
|
|
3444
|
+
varianceStructInvariantType(type, atLocation, "_Service")
|
|
3445
|
+
),
|
|
3446
|
+
([Identifier, Service]) => ({ Identifier, Service })
|
|
3447
|
+
);
|
|
3448
|
+
const serviceType = cachedBy(
|
|
3449
|
+
fn("TypeParser.serviceType")(function* (type, atLocation) {
|
|
3450
|
+
yield* pipeableType(type, atLocation);
|
|
3451
|
+
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
3452
|
+
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
|
|
3453
|
+
);
|
|
3454
|
+
if (propertiesSymbols.length === 0) {
|
|
3455
|
+
return yield* typeParserIssue("Type has no tag variance struct", type, atLocation);
|
|
3456
|
+
}
|
|
3457
|
+
propertiesSymbols.sort((a, b) => ts.symbolName(b).indexOf("TypeId") - ts.symbolName(a).indexOf("TypeId"));
|
|
3458
|
+
return yield* firstSuccessOf(propertiesSymbols.map((propertySymbol) => {
|
|
3459
|
+
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
3460
|
+
return serviceVarianceStruct(propertyType, atLocation);
|
|
3461
|
+
}));
|
|
3462
|
+
}),
|
|
3463
|
+
"TypeParser.serviceType",
|
|
3464
|
+
(type) => type
|
|
3465
|
+
);
|
|
3409
3466
|
const contextTag = cachedBy(
|
|
3410
3467
|
fn("TypeParser.contextTag")(function* (type, atLocation) {
|
|
3411
3468
|
yield* pipeableType(type, atLocation);
|
|
@@ -3487,14 +3544,22 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3487
3544
|
);
|
|
3488
3545
|
const scopeType = cachedBy(
|
|
3489
3546
|
fn("TypeParser.scopeType")(function* (type, atLocation) {
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
return type;
|
|
3547
|
+
if (supportedEffect() === "v4") {
|
|
3548
|
+
const typeIdSymbol = typeChecker.getPropertyOfType(type, "~effect/Scope");
|
|
3549
|
+
if (typeIdSymbol) {
|
|
3550
|
+
return type;
|
|
3551
|
+
}
|
|
3552
|
+
return yield* typeParserIssue("Type is not an effect", type, atLocation);
|
|
3553
|
+
} else {
|
|
3554
|
+
yield* pipeableType(type, atLocation);
|
|
3555
|
+
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
3556
|
+
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
|
|
3557
|
+
);
|
|
3558
|
+
if (propertiesSymbols.some((s) => ts.symbolName(s).indexOf("ScopeTypeId") !== -1)) {
|
|
3559
|
+
return type;
|
|
3560
|
+
}
|
|
3561
|
+
return yield* typeParserIssue("Type has no scope type id", type, atLocation);
|
|
3496
3562
|
}
|
|
3497
|
-
return yield* typeParserIssue("Type has no scope type id", type, atLocation);
|
|
3498
3563
|
}),
|
|
3499
3564
|
"TypeParser.scopeType",
|
|
3500
3565
|
(type) => type
|
|
@@ -3976,6 +4041,55 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3976
4041
|
"TypeParser.extendsEffectService",
|
|
3977
4042
|
(atLocation) => atLocation
|
|
3978
4043
|
);
|
|
4044
|
+
const extendsServiceMapService = cachedBy(
|
|
4045
|
+
fn("TypeParser.extendsServiceMapService")(function* (atLocation) {
|
|
4046
|
+
if (!atLocation.name) {
|
|
4047
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
4048
|
+
}
|
|
4049
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
4050
|
+
if (!heritageClauses) {
|
|
4051
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
4052
|
+
}
|
|
4053
|
+
for (const heritageClause of heritageClauses) {
|
|
4054
|
+
for (const typeX of heritageClause.types) {
|
|
4055
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
4056
|
+
const wholeCall = typeX.expression;
|
|
4057
|
+
if (ts.isCallExpression(wholeCall)) {
|
|
4058
|
+
const serviceMapServiceCall = wholeCall.expression;
|
|
4059
|
+
if (ts.isCallExpression(serviceMapServiceCall) && serviceMapServiceCall.typeArguments && serviceMapServiceCall.typeArguments.length > 0) {
|
|
4060
|
+
const serviceMapServiceIdentifier = serviceMapServiceCall.expression;
|
|
4061
|
+
const selfTypeNode = serviceMapServiceCall.typeArguments[0];
|
|
4062
|
+
const isServiceMapService = yield* pipe(
|
|
4063
|
+
isNodeReferenceToServiceMapModuleApi("Service")(serviceMapServiceIdentifier),
|
|
4064
|
+
orUndefined
|
|
4065
|
+
);
|
|
4066
|
+
if (isServiceMapService) {
|
|
4067
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
4068
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
4069
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
4070
|
+
const parsedServiceType = yield* pipe(
|
|
4071
|
+
serviceType(type, atLocation),
|
|
4072
|
+
orUndefined
|
|
4073
|
+
);
|
|
4074
|
+
if (parsedServiceType) {
|
|
4075
|
+
return {
|
|
4076
|
+
...parsedServiceType,
|
|
4077
|
+
className: atLocation.name,
|
|
4078
|
+
selfTypeNode,
|
|
4079
|
+
keyStringLiteral: wholeCall.arguments.length > 0 && ts.isStringLiteral(wholeCall.arguments[0]) ? wholeCall.arguments[0] : void 0
|
|
4080
|
+
};
|
|
4081
|
+
}
|
|
4082
|
+
}
|
|
4083
|
+
}
|
|
4084
|
+
}
|
|
4085
|
+
}
|
|
4086
|
+
}
|
|
4087
|
+
}
|
|
4088
|
+
return yield* typeParserIssue("Class does not extend ServiceMap.Service", void 0, atLocation);
|
|
4089
|
+
}),
|
|
4090
|
+
"TypeParser.extendsServiceMapService",
|
|
4091
|
+
(atLocation) => atLocation
|
|
4092
|
+
);
|
|
3979
4093
|
const isEffectSqlModelTypeSourceFile = cachedBy(
|
|
3980
4094
|
fn("TypeParser.isEffectSqlModelTypeSourceFile")(function* (sourceFile) {
|
|
3981
4095
|
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
|
@@ -4068,6 +4182,24 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
4068
4182
|
`TypeParser.isNodeReferenceToEffectLayerModuleApi(${memberName})`,
|
|
4069
4183
|
(node) => node
|
|
4070
4184
|
);
|
|
4185
|
+
const isServiceMapTypeSourceFile = cachedBy(
|
|
4186
|
+
fn("TypeParser.isServiceMapTypeSourceFile")(function* (sourceFile) {
|
|
4187
|
+
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
|
4188
|
+
if (!moduleSymbol) return yield* typeParserIssue("Node has no symbol", void 0, sourceFile);
|
|
4189
|
+
const serviceMapSymbol = typeChecker.tryGetMemberInModuleExports("ServiceMap", moduleSymbol);
|
|
4190
|
+
if (!serviceMapSymbol) return yield* typeParserIssue("ServiceMap not found", void 0, sourceFile);
|
|
4191
|
+
return sourceFile;
|
|
4192
|
+
}),
|
|
4193
|
+
"TypeParser.isServiceMapTypeSourceFile",
|
|
4194
|
+
(sourceFile) => sourceFile
|
|
4195
|
+
);
|
|
4196
|
+
const isNodeReferenceToServiceMapModuleApi = (memberName) => cachedBy(
|
|
4197
|
+
fn("TypeParser.isNodeReferenceToServiceMapModuleApi")(function* (node) {
|
|
4198
|
+
return yield* isNodeReferenceToExportOfPackageModule(node, "effect", isServiceMapTypeSourceFile, memberName);
|
|
4199
|
+
}),
|
|
4200
|
+
`TypeParser.isNodeReferenceToServiceMapModuleApi(${memberName})`,
|
|
4201
|
+
(node) => node
|
|
4202
|
+
);
|
|
4071
4203
|
const lazyExpression = cachedBy(
|
|
4072
4204
|
function(node) {
|
|
4073
4205
|
if (!ts.isArrowFunction(node) && !ts.isFunctionExpression(node)) {
|
|
@@ -4398,6 +4530,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
4398
4530
|
isNodeReferenceToEffectContextModuleApi,
|
|
4399
4531
|
isNodeReferenceToEffectSqlModelModuleApi,
|
|
4400
4532
|
isNodeReferenceToEffectLayerModuleApi,
|
|
4533
|
+
isNodeReferenceToEffectSchemaParserModuleApi,
|
|
4534
|
+
isServiceMapTypeSourceFile,
|
|
4535
|
+
isNodeReferenceToServiceMapModuleApi,
|
|
4401
4536
|
effectType,
|
|
4402
4537
|
strictEffectType,
|
|
4403
4538
|
layerType,
|
|
@@ -4413,6 +4548,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
4413
4548
|
unnecessaryEffectGen: unnecessaryEffectGen2,
|
|
4414
4549
|
effectSchemaType,
|
|
4415
4550
|
contextTag,
|
|
4551
|
+
serviceType,
|
|
4416
4552
|
pipeableType,
|
|
4417
4553
|
pipeCall,
|
|
4418
4554
|
singleArgCall,
|
|
@@ -4420,6 +4556,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
4420
4556
|
promiseLike,
|
|
4421
4557
|
extendsEffectTag,
|
|
4422
4558
|
extendsEffectService,
|
|
4559
|
+
extendsServiceMapService,
|
|
4423
4560
|
extendsContextTag,
|
|
4424
4561
|
extendsSchemaClass,
|
|
4425
4562
|
extendsSchemaTaggedClass,
|
|
@@ -4897,6 +5034,7 @@ var deterministicKeys = createDiagnostic({
|
|
|
4897
5034
|
typeParser.extendsEffectService(node),
|
|
4898
5035
|
orElse2(() => typeParser.extendsContextTag(node)),
|
|
4899
5036
|
orElse2(() => typeParser.extendsEffectTag(node)),
|
|
5037
|
+
orElse2(() => typeParser.extendsServiceMapService(node)),
|
|
4900
5038
|
map4(({ className, keyStringLiteral }) => ({ keyStringLiteral, className, target: "service" }))
|
|
4901
5039
|
),
|
|
4902
5040
|
orElse2(
|
|
@@ -6292,6 +6430,9 @@ More info and examples at https://effect.website/docs/requirements-management/la
|
|
|
6292
6430
|
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && ts.idText(node.expression.name) === "GenericTag") {
|
|
6293
6431
|
const nodeType = typeCheckerUtils.getTypeAtLocation(node);
|
|
6294
6432
|
if (nodeType) typesToCheck.push([nodeType, node]);
|
|
6433
|
+
} else if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.name) && ts.idText(node.expression.name) === "Service") {
|
|
6434
|
+
const nodeType = typeCheckerUtils.getTypeAtLocation(node);
|
|
6435
|
+
if (nodeType) typesToCheck.push([nodeType, node]);
|
|
6295
6436
|
} else if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {
|
|
6296
6437
|
const classSym = typeChecker.getSymbolAtLocation(node.name);
|
|
6297
6438
|
if (classSym) {
|
|
@@ -6305,6 +6446,7 @@ More info and examples at https://effect.website/docs/requirements-management/la
|
|
|
6305
6446
|
for (const [type, reportAt] of typesToCheck) {
|
|
6306
6447
|
yield* pipe(
|
|
6307
6448
|
typeParser.contextTag(type, node),
|
|
6449
|
+
orElse2(() => typeParser.serviceType(type, node)),
|
|
6308
6450
|
flatMap2(
|
|
6309
6451
|
({ Service }) => pipe(
|
|
6310
6452
|
parseLeakedRequirements(Service, node),
|
|
@@ -7079,6 +7221,7 @@ var nonObjectEffectServiceType = createDiagnostic({
|
|
|
7079
7221
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
7080
7222
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
7081
7223
|
const typeParser = yield* service(TypeParser);
|
|
7224
|
+
if (typeParser.supportedEffect() === "v4") return;
|
|
7082
7225
|
function isPrimitiveType(type) {
|
|
7083
7226
|
return typeCheckerUtils.unrollUnionMembers(type).some(
|
|
7084
7227
|
(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)
|
|
@@ -7363,6 +7506,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
|
7363
7506
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
7364
7507
|
const typeParser = yield* service(TypeParser);
|
|
7365
7508
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
7509
|
+
if (typeParser.supportedEffect() === "v4") return yield* fail("not applicable to Effect v4");
|
|
7366
7510
|
if (!ts.isClassDeclaration(node)) return yield* fail("not a class declaration");
|
|
7367
7511
|
const { Service, accessors: accessors2, className, kind } = yield* pipe(
|
|
7368
7512
|
map4(typeParser.extendsEffectService(node), (_) => ({ kind: "effectService", ..._ })),
|
|
@@ -7605,16 +7749,16 @@ var pushHoistedVariableStatement = fn("StructuralSchemaGen.pushHoistedVariableSt
|
|
|
7605
7749
|
);
|
|
7606
7750
|
}
|
|
7607
7751
|
);
|
|
7608
|
-
var createProcessingContext = (maxDepth = 200) => ({
|
|
7752
|
+
var createProcessingContext = (supportedEffect, maxDepth = 200) => ({
|
|
7609
7753
|
depth: 0,
|
|
7610
7754
|
maxDepth,
|
|
7611
|
-
hoistName: void 0
|
|
7755
|
+
hoistName: void 0,
|
|
7756
|
+
supportedEffect
|
|
7612
7757
|
});
|
|
7613
7758
|
var processType = fn(
|
|
7614
7759
|
"StructuralSchemaGen.processType"
|
|
7615
7760
|
)(
|
|
7616
|
-
function* (type,
|
|
7617
|
-
const processingContext = context || createProcessingContext();
|
|
7761
|
+
function* (type, processingContext) {
|
|
7618
7762
|
const { hoistedSchemas, nameToType, ts, typeChecker, usedGlobalIdentifiers } = yield* service(
|
|
7619
7763
|
StructuralSchemaGenContext
|
|
7620
7764
|
);
|
|
@@ -7749,7 +7893,7 @@ var processUnionType = fn(
|
|
|
7749
7893
|
const allLiterals = types.every(
|
|
7750
7894
|
(t) => t.flags & ts.TypeFlags.StringLiteral || t.flags & ts.TypeFlags.NumberLiteral || t.flags & ts.TypeFlags.BooleanLiteral
|
|
7751
7895
|
);
|
|
7752
|
-
if (allLiterals) {
|
|
7896
|
+
if (allLiterals && context.supportedEffect !== "v4") {
|
|
7753
7897
|
const literals = yield* all(
|
|
7754
7898
|
...types.map((t) => processType(t, context))
|
|
7755
7899
|
);
|
|
@@ -7759,7 +7903,13 @@ var processUnionType = fn(
|
|
|
7759
7903
|
}
|
|
7760
7904
|
return expr;
|
|
7761
7905
|
}).filter((arg) => arg !== void 0);
|
|
7762
|
-
return [
|
|
7906
|
+
return [
|
|
7907
|
+
createApiCall(
|
|
7908
|
+
"Literal",
|
|
7909
|
+
literalValues
|
|
7910
|
+
),
|
|
7911
|
+
false
|
|
7912
|
+
];
|
|
7763
7913
|
}
|
|
7764
7914
|
const members = yield* all(
|
|
7765
7915
|
...types.map((t) => processType(t, context))
|
|
@@ -7767,7 +7917,13 @@ var processUnionType = fn(
|
|
|
7767
7917
|
if (members.length === 1) {
|
|
7768
7918
|
return [members[0], false];
|
|
7769
7919
|
}
|
|
7770
|
-
return [
|
|
7920
|
+
return [
|
|
7921
|
+
createApiCall(
|
|
7922
|
+
"Union",
|
|
7923
|
+
context.supportedEffect === "v4" ? [ts.factory.createArrayLiteralExpression(members)] : members
|
|
7924
|
+
),
|
|
7925
|
+
false
|
|
7926
|
+
];
|
|
7771
7927
|
}
|
|
7772
7928
|
);
|
|
7773
7929
|
var processIntersectionType = fn(
|
|
@@ -7813,12 +7969,18 @@ var processTupleType = fn(
|
|
|
7813
7969
|
"StructuralSchemaGen.processTupleType"
|
|
7814
7970
|
)(
|
|
7815
7971
|
function* (type, context) {
|
|
7816
|
-
const { createApiCall, typeChecker } = yield* service(StructuralSchemaGenContext);
|
|
7972
|
+
const { createApiCall, ts, typeChecker } = yield* service(StructuralSchemaGenContext);
|
|
7817
7973
|
const typeArgs = typeChecker.getTypeArguments(type);
|
|
7818
7974
|
const elementSchemas = yield* all(
|
|
7819
7975
|
...typeArgs.map((t) => processType(t, context))
|
|
7820
7976
|
);
|
|
7821
|
-
return [
|
|
7977
|
+
return [
|
|
7978
|
+
createApiCall(
|
|
7979
|
+
"Tuple",
|
|
7980
|
+
context.supportedEffect === "v4" ? [ts.factory.createArrayLiteralExpression(elementSchemas)] : elementSchemas
|
|
7981
|
+
),
|
|
7982
|
+
false
|
|
7983
|
+
];
|
|
7822
7984
|
}
|
|
7823
7985
|
);
|
|
7824
7986
|
var processObjectType = fn(
|
|
@@ -7835,7 +7997,6 @@ var processObjectType = fn(
|
|
|
7835
7997
|
} = yield* service(
|
|
7836
7998
|
StructuralSchemaGenContext
|
|
7837
7999
|
);
|
|
7838
|
-
let hasRecords = false;
|
|
7839
8000
|
const properties = typeChecker.getPropertiesOfType(type);
|
|
7840
8001
|
const propertyAssignments = [];
|
|
7841
8002
|
for (const property of properties) {
|
|
@@ -7875,20 +8036,28 @@ var processObjectType = fn(
|
|
|
7875
8036
|
const args2 = [
|
|
7876
8037
|
ts.factory.createObjectLiteralExpression(propertyAssignments, propertyAssignments.length > 0)
|
|
7877
8038
|
];
|
|
8039
|
+
const records = [];
|
|
7878
8040
|
for (const indexInfo of indexInfos) {
|
|
7879
|
-
hasRecords = true;
|
|
7880
8041
|
const keyType = indexInfo.keyType;
|
|
7881
8042
|
const valueType = indexInfo.type;
|
|
7882
8043
|
const keySchema = yield* processType(keyType, context);
|
|
7883
8044
|
const valueSchema = yield* processType(valueType, context);
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
8045
|
+
records.push({ key: keySchema, value: valueSchema });
|
|
8046
|
+
}
|
|
8047
|
+
if (context.supportedEffect === "v4") {
|
|
8048
|
+
if (records.length > 0) {
|
|
8049
|
+
return [
|
|
8050
|
+
createApiCall("StructWithRest", [
|
|
8051
|
+
createApiCall("Struct", args2),
|
|
8052
|
+
ts.factory.createArrayLiteralExpression(
|
|
8053
|
+
records.map(({ key, value }) => createApiCall("Record", [key, value]))
|
|
8054
|
+
)
|
|
8055
|
+
]),
|
|
8056
|
+
propertyAssignments.length === 0
|
|
8057
|
+
];
|
|
8058
|
+
}
|
|
7890
8059
|
}
|
|
7891
|
-
if (
|
|
8060
|
+
if (records.length === 0 && context.hoistName) {
|
|
7892
8061
|
const ctx = yield* service(StructuralSchemaGenContext);
|
|
7893
8062
|
yield* pushHoistedStatement(
|
|
7894
8063
|
ctx,
|
|
@@ -7923,6 +8092,14 @@ var processObjectType = fn(
|
|
|
7923
8092
|
);
|
|
7924
8093
|
return [ctx.hoistedSchemas.get(type)(), true];
|
|
7925
8094
|
}
|
|
8095
|
+
for (const { key, value } of records) {
|
|
8096
|
+
args2.push(
|
|
8097
|
+
ts.factory.createObjectLiteralExpression([
|
|
8098
|
+
ts.factory.createPropertyAssignment("key", key),
|
|
8099
|
+
ts.factory.createPropertyAssignment("value", value)
|
|
8100
|
+
])
|
|
8101
|
+
);
|
|
8102
|
+
}
|
|
7926
8103
|
return [createApiCall("Struct", args2), propertyAssignments.length === 0];
|
|
7927
8104
|
}
|
|
7928
8105
|
);
|
|
@@ -8008,7 +8185,7 @@ var process = fn("StructuralSchemaGen.process")(
|
|
|
8008
8185
|
all(
|
|
8009
8186
|
...fromIterable(ctx.nameToType.entries()).map(
|
|
8010
8187
|
([name, type]) => pipe(
|
|
8011
|
-
processType(type),
|
|
8188
|
+
processType(type, createProcessingContext(typeParser.supportedEffect())),
|
|
8012
8189
|
orElse2(
|
|
8013
8190
|
(error) => succeed(ts.addSyntheticLeadingComment(
|
|
8014
8191
|
ts.factory.createIdentifier(""),
|
|
@@ -8590,6 +8767,7 @@ var runEffectInsideEffect = createDiagnostic({
|
|
|
8590
8767
|
const ts = yield* service(TypeScriptApi);
|
|
8591
8768
|
const typeParser = yield* service(TypeParser);
|
|
8592
8769
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
8770
|
+
if (typeParser.supportedEffect() === "v4") return;
|
|
8593
8771
|
const parseEffectMethod = (node, methodName) => pipe(
|
|
8594
8772
|
typeParser.isNodeReferenceToEffectModuleApi(methodName)(node),
|
|
8595
8773
|
map4(() => ({ node, methodName }))
|
|
@@ -8784,12 +8962,18 @@ var schemaStructWithTag = createDiagnostic({
|
|
|
8784
8962
|
});
|
|
8785
8963
|
|
|
8786
8964
|
// src/diagnostics/schemaSyncInEffect.ts
|
|
8787
|
-
var
|
|
8965
|
+
var syncToEffectMethodV3 = {
|
|
8788
8966
|
decodeSync: "decode",
|
|
8789
8967
|
decodeUnknownSync: "decodeUnknown",
|
|
8790
8968
|
encodeSync: "encode",
|
|
8791
8969
|
encodeUnknownSync: "encodeUnknown"
|
|
8792
8970
|
};
|
|
8971
|
+
var syncToEffectMethodV4 = {
|
|
8972
|
+
decodeSync: "decodeEffect",
|
|
8973
|
+
decodeUnknownSync: "decodeUnknownEffect",
|
|
8974
|
+
encodeSync: "encodeEffect",
|
|
8975
|
+
encodeUnknownSync: "encodeUnknownEffect"
|
|
8976
|
+
};
|
|
8793
8977
|
var schemaSyncInEffect = createDiagnostic({
|
|
8794
8978
|
name: "schemaSyncInEffect",
|
|
8795
8979
|
code: 43,
|
|
@@ -8798,8 +8982,10 @@ var schemaSyncInEffect = createDiagnostic({
|
|
|
8798
8982
|
apply: fn("schemaSyncInEffect.apply")(function* (sourceFile, report) {
|
|
8799
8983
|
const ts = yield* service(TypeScriptApi);
|
|
8800
8984
|
const typeParser = yield* service(TypeParser);
|
|
8985
|
+
const syncToEffectMethod = typeParser.supportedEffect() === "v3" ? syncToEffectMethodV3 : syncToEffectMethodV4;
|
|
8801
8986
|
const parseSchemaSyncMethod = (node, methodName) => pipe(
|
|
8802
8987
|
typeParser.isNodeReferenceToEffectParseResultModuleApi(methodName)(node),
|
|
8988
|
+
orElse2(() => typeParser.isNodeReferenceToEffectSchemaParserModuleApi(methodName)(node)),
|
|
8803
8989
|
map4(() => ({ node, methodName }))
|
|
8804
8990
|
);
|
|
8805
8991
|
const nodeToVisit = [];
|
|
@@ -8829,7 +9015,7 @@ var schemaSyncInEffect = createDiagnostic({
|
|
|
8829
9015
|
const effectMethodName = syncToEffectMethod[isSchemaSyncCall.value.methodName];
|
|
8830
9016
|
report({
|
|
8831
9017
|
location: node.expression,
|
|
8832
|
-
messageText: `Using ${nodeText} inside an Effect generator is not recommended. Use Schema.${effectMethodName} instead to get properly typed
|
|
9018
|
+
messageText: `Using ${nodeText} inside an Effect generator is not recommended. Use Schema.${effectMethodName} instead to get properly typed error channel.`,
|
|
8833
9019
|
fixes: []
|
|
8834
9020
|
});
|
|
8835
9021
|
}
|
|
@@ -8845,6 +9031,7 @@ var schemaUnionOfLiterals = createDiagnostic({
|
|
|
8845
9031
|
apply: fn("schemaUnionOfLiterals.apply")(function* (sourceFile, report) {
|
|
8846
9032
|
const ts = yield* service(TypeScriptApi);
|
|
8847
9033
|
const typeParser = yield* service(TypeParser);
|
|
9034
|
+
if (typeParser.supportedEffect() === "v4") return;
|
|
8848
9035
|
const nodeToVisit = [];
|
|
8849
9036
|
const appendNodeToVisit = (node) => {
|
|
8850
9037
|
nodeToVisit.push(node);
|