1+ import * as Context from "effect/Context" ;
12import type { Effect } from "effect/Effect" ;
23import type { Layer } from "effect/Layer" ;
34import type { Capability } from "./capability.ts" ;
@@ -13,20 +14,37 @@ export const isBinding = (b: any): b is Binding<any, any, any> =>
1314
1415export type AnyBinding < F extends Runtime = any > = Binding < F , any , any > ;
1516
16- export interface Binding <
17+ export type Binding <
1718 Run extends Runtime ,
1819 Cap extends Capability = Capability ,
19- Tag = Cap [ "type" ] ,
20- > {
20+ Tag extends string = Cap [ "type" ] ,
21+ > = {
2122 runtime : Run ;
2223 capability : Cap ;
23- tag : Tag ;
24+ tag : BindingTag < Run , Cap , Tag > ;
25+ } ;
26+
27+ export interface BindingTag <
28+ Run extends Runtime ,
29+ Cap extends Capability ,
30+ Tag extends string ,
31+ > extends Context . Tag <
32+ `${Run [ "type" ] } (${Cap [ "type" ] } , ${Tag } )`,
33+ BindingService <
34+ Run ,
35+ Extract < Extract < Cap [ "resource" ] , Resource > [ "parent" ] , Resource > ,
36+ Run [ "props" ]
37+ >
38+ > {
39+ /** @internal phantom */
40+ tagName : Tag ;
2441}
2542
2643export const Binding = < F extends ( resource : any , props ?: any ) => AnyBinding > (
2744 runtime : ReturnType < F > [ "runtime" ] ,
2845 resource : new ( ) => ReturnType < F > [ "capability" ] [ "resource" ] ,
29- tag : ReturnType < F > [ "tag" ] ,
46+ tag : ReturnType < F > [ "tag" ] [ "tagName" ] ,
47+ // _tag: ReturnType<F>,
3048) : F & BindingDeclaration < ReturnType < F > [ "runtime" ] , F > => {
3149 type Runtime = ReturnType < F > [ "runtime" ] ;
3250 type Tag = ReturnType < F > [ "tag" ] ;
@@ -93,13 +111,13 @@ export type BindingService<
93111 } ,
94112 to : Props ,
95113 target : Target ,
96- ) => Effect . Effect < Partial < Props > | void , never , AttachReq > ;
114+ ) => Effect < Partial < Props > | void , never , AttachReq > ;
97115 detach ?: (
98116 resource : {
99117 id : string ;
100118 attr : R [ "attr" ] ;
101119 props : R [ "props" ] ;
102120 } ,
103121 from : Props ,
104- ) => Effect . Effect < void , never , DetachReq > ;
122+ ) => Effect < void , never , DetachReq > ;
105123} ;
0 commit comments