@@ -484,15 +484,30 @@ export function make(
484
484
Nano . fn ( "TypeParser.importedSchemaModule" ) ( function * (
485
485
node : ts . Node
486
486
) {
487
+ // should be an expression
488
+ if ( ! ts . isIdentifier ( node ) ) {
489
+ return yield * typeParserIssue ( "Node is not an expression" , undefined , node )
490
+ }
487
491
const type = typeChecker . getTypeAtLocation ( node )
488
492
// if the type has a property "Class" that is a function
489
493
const propertySymbol = typeChecker . getPropertyOfType ( type , "Class" )
490
494
if ( ! propertySymbol ) {
491
495
return yield * typeParserIssue ( "Type has no 'Class' property" , type , node )
492
496
}
493
- // should be an expression
494
- if ( ! ts . isExpression ( node ) ) {
495
- return yield * typeParserIssue ( "Node is not an expression" , type , node )
497
+ const sourceFile = tsUtils . getSourceFileOfNode ( node )
498
+ if ( ! sourceFile ) {
499
+ return yield * typeParserIssue ( "Node is not in a source file" , undefined , node )
500
+ }
501
+ const schemaIdentifier = tsUtils . findImportedModuleIdentifierByPackageAndNameOrBarrel (
502
+ sourceFile ,
503
+ "effect" ,
504
+ "Schema"
505
+ )
506
+ if ( ! schemaIdentifier ) {
507
+ return yield * typeParserIssue ( "Schema module not found" , undefined , node )
508
+ }
509
+ if ( ts . idText ( node ) !== schemaIdentifier ) {
510
+ return yield * typeParserIssue ( "Node is not a schema module reference" , undefined , node )
496
511
}
497
512
// return the node itself
498
513
return node
@@ -512,8 +527,23 @@ export function make(
512
527
return yield * typeParserIssue ( "Type has no 'Tag' property" , type , node )
513
528
}
514
529
// should be an expression
515
- if ( ! ts . isExpression ( node ) ) {
516
- return yield * typeParserIssue ( "Node is not an expression" , type , node )
530
+ if ( ! ts . isIdentifier ( node ) ) {
531
+ return yield * typeParserIssue ( "Node is not an identifier" , type , node )
532
+ }
533
+ const sourceFile = tsUtils . getSourceFileOfNode ( node )
534
+ if ( ! sourceFile ) {
535
+ return yield * typeParserIssue ( "Node is not in a source file" , undefined , node )
536
+ }
537
+ const contextIdentifier = tsUtils . findImportedModuleIdentifierByPackageAndNameOrBarrel (
538
+ sourceFile ,
539
+ "effect" ,
540
+ "Context"
541
+ )
542
+ if ( ! contextIdentifier ) {
543
+ return yield * typeParserIssue ( "Context module not found" , undefined , node )
544
+ }
545
+ if ( ts . idText ( node ) !== contextIdentifier ) {
546
+ return yield * typeParserIssue ( "Node is not a context module reference" , undefined , node )
517
547
}
518
548
// return the node itself
519
549
return node
@@ -557,9 +587,24 @@ export function make(
557
587
return yield * typeParserIssue ( "Type has no 'TaggedError' property" , type , node )
558
588
}
559
589
// should be an expression
560
- if ( ! ts . isExpression ( node ) ) {
590
+ if ( ! ts . isIdentifier ( node ) ) {
561
591
return yield * typeParserIssue ( "Node is not an expression" , type , node )
562
592
}
593
+ const sourceFile = tsUtils . getSourceFileOfNode ( node )
594
+ if ( ! sourceFile ) {
595
+ return yield * typeParserIssue ( "Node is not in a source file" , undefined , node )
596
+ }
597
+ const dataIdentifier = tsUtils . findImportedModuleIdentifierByPackageAndNameOrBarrel (
598
+ sourceFile ,
599
+ "effect" ,
600
+ "Data"
601
+ )
602
+ if ( ! dataIdentifier ) {
603
+ return yield * typeParserIssue ( "Data module not found" , undefined , node )
604
+ }
605
+ if ( ts . idText ( node ) !== dataIdentifier ) {
606
+ return yield * typeParserIssue ( "Node is not a data module reference" , undefined , node )
607
+ }
563
608
// return the node itself
564
609
return node
565
610
} ) ,
@@ -1029,8 +1074,10 @@ export function make(
1029
1074
ts . isPropertyAccessExpression ( schemaIdentifier ) && ts . isIdentifier ( schemaIdentifier . name ) &&
1030
1075
ts . idText ( schemaIdentifier . name ) === "Class"
1031
1076
) {
1077
+ const expressionType = typeChecker . getTypeAtLocation ( expression )
1032
1078
const parsedSchemaModule = yield * pipe (
1033
- importedSchemaModule ( schemaIdentifier . expression ) ,
1079
+ effectSchemaType ( expressionType , expression ) ,
1080
+ Nano . flatMap ( ( ) => importedSchemaModule ( schemaIdentifier . expression ) ) ,
1034
1081
Nano . option
1035
1082
)
1036
1083
if ( Option . isSome ( parsedSchemaModule ) ) {
@@ -1081,8 +1128,10 @@ export function make(
1081
1128
ts . isPropertyAccessExpression ( schemaIdentifier ) && ts . isIdentifier ( schemaIdentifier . name ) &&
1082
1129
ts . idText ( schemaIdentifier . name ) === "TaggedClass"
1083
1130
) {
1131
+ const expressionType = typeChecker . getTypeAtLocation ( expression )
1084
1132
const parsedSchemaModule = yield * pipe (
1085
- importedSchemaModule ( schemaIdentifier . expression ) ,
1133
+ effectSchemaType ( expressionType , expression ) ,
1134
+ Nano . flatMap ( ( ) => importedSchemaModule ( schemaIdentifier . expression ) ) ,
1086
1135
Nano . option
1087
1136
)
1088
1137
if ( Option . isSome ( parsedSchemaModule ) ) {
@@ -1141,8 +1190,10 @@ export function make(
1141
1190
ts . isPropertyAccessExpression ( schemaIdentifier ) && ts . isIdentifier ( schemaIdentifier . name ) &&
1142
1191
ts . idText ( schemaIdentifier . name ) === "TaggedError"
1143
1192
) {
1193
+ const expressionType = typeChecker . getTypeAtLocation ( expression )
1144
1194
const parsedSchemaModule = yield * pipe (
1145
- importedSchemaModule ( schemaIdentifier . expression ) ,
1195
+ effectSchemaType ( expressionType , expression ) ,
1196
+ Nano . flatMap ( ( ) => importedSchemaModule ( schemaIdentifier . expression ) ) ,
1146
1197
Nano . option
1147
1198
)
1148
1199
if ( Option . isSome ( parsedSchemaModule ) ) {
@@ -1306,8 +1357,10 @@ export function make(
1306
1357
ts . isPropertyAccessExpression ( schemaIdentifier ) && ts . isIdentifier ( schemaIdentifier . name ) &&
1307
1358
ts . idText ( schemaIdentifier . name ) === "TaggedRequest"
1308
1359
) {
1360
+ const expressionType = typeChecker . getTypeAtLocation ( expression )
1309
1361
const parsedSchemaModule = yield * pipe (
1310
- importedSchemaModule ( schemaIdentifier . expression ) ,
1362
+ effectSchemaType ( expressionType , expression ) ,
1363
+ Nano . flatMap ( ( ) => importedSchemaModule ( schemaIdentifier . expression ) ) ,
1311
1364
Nano . option
1312
1365
)
1313
1366
if ( Option . isSome ( parsedSchemaModule ) ) {
0 commit comments