11import SCRIPT_PIPELINE_OBJECT from "worker:pipelines/pipeline" ;
22import { z } from "zod" ;
33import { Service } from "../../runtime" ;
4- import { namespaceKeys , Plugin , ProxyNodeBinding } from "../shared" ;
4+ import {
5+ namespaceKeys ,
6+ Plugin ,
7+ ProxyNodeBinding ,
8+ remoteProxyClientWorker ,
9+ RemoteProxyConnectionString ,
10+ } from "../shared" ;
511
612export const PipelineOptionsSchema = z . object ( {
7- pipelines : z . union ( [ z . record ( z . string ( ) ) , z . string ( ) . array ( ) ] ) . optional ( ) ,
13+ pipelines : z
14+ . union ( [
15+ z . record ( z . string ( ) ) ,
16+ z . string ( ) . array ( ) ,
17+ z . record (
18+ z . object ( {
19+ pipeline : z . string ( ) ,
20+ remoteProxyConnectionString : z
21+ . custom < RemoteProxyConnectionString > ( )
22+ . optional ( ) ,
23+ } )
24+ ) ,
25+ ] )
26+ . optional ( ) ,
827} ) ;
928
1029export const PIPELINES_PLUGIN_NAME = "pipelines" ;
@@ -14,7 +33,7 @@ export const PIPELINE_PLUGIN: Plugin<typeof PipelineOptionsSchema> = {
1433options : PipelineOptionsSchema ,
1534getBindings ( options ) {
1635const pipelines = bindingEntries ( options . pipelines ) ;
17- return pipelines . map < Service > ( ( [ name , id ] ) => ( {
36+ return pipelines . map < Service > ( ( [ name , { id } ] ) => ( {
1837name,
1938service : { name : `${ SERVICE_PIPELINE_PREFIX } :${ id } ` } ,
2039} ) ) ;
@@ -29,18 +48,23 @@ export const PIPELINE_PLUGIN: Plugin<typeof PipelineOptionsSchema> = {
2948const pipelines = bindingEntries ( options . pipelines ) ;
3049
3150const services = [ ] ;
32- for ( const pipeline of pipelines ) {
51+ for ( const [ bindingName , pipeline ] of pipelines ) {
3352services . push ( {
34- name : `${ SERVICE_PIPELINE_PREFIX } :${ pipeline [ 1 ] } ` ,
35- worker : {
36- compatibilityDate : "2024-12-30" ,
37- modules : [
38- {
39- name : "pipeline.worker.js" ,
40- esModule : SCRIPT_PIPELINE_OBJECT ( ) ,
53+ name : `${ SERVICE_PIPELINE_PREFIX } :${ pipeline . id } ` ,
54+ worker : pipeline . remoteProxyConnectionString
55+ ? remoteProxyClientWorker (
56+ pipeline . remoteProxyConnectionString ,
57+ bindingName
58+ )
59+ : {
60+ compatibilityDate : "2024-12-30" ,
61+ modules : [
62+ {
63+ name : "pipeline.worker.js" ,
64+ esModule : SCRIPT_PIPELINE_OBJECT ( ) ,
65+ } ,
66+ ] ,
4167} ,
42- ] ,
43- } ,
4468} ) ;
4569}
4670
@@ -50,16 +74,41 @@ export const PIPELINE_PLUGIN: Plugin<typeof PipelineOptionsSchema> = {
5074
5175function bindingEntries (
5276namespaces ?:
53- | Record < string , { pipelineName : string } >
77+ | Record <
78+ string ,
79+ {
80+ pipeline : string ;
81+ remoteProxyConnectionString ?: RemoteProxyConnectionString ;
82+ }
83+ >
5484| string [ ]
5585| Record < string , string >
56- ) : [ bindingName : string , id : string ] [ ] {
86+ ) : [
87+ bindingName : string ,
88+ { id : string ; remoteProxyConnectionString ?: RemoteProxyConnectionString } ,
89+ ] [ ] {
5790if ( Array . isArray ( namespaces ) ) {
58- return namespaces . map ( ( bindingName ) => [ bindingName , bindingName ] ) ;
91+ return namespaces . map ( ( bindingName ) => [ bindingName , { id : bindingName } ] ) ;
5992} else if ( namespaces !== undefined ) {
60- return Object . entries ( namespaces ) . map ( ( [ name , opts ] ) => [
93+ return (
94+ Object . entries ( namespaces ) as [
95+ string ,
96+ (
97+ | string
98+ | {
99+ pipeline : string ;
100+ remoteProxyConnectionString ?: RemoteProxyConnectionString ;
101+ }
102+ ) ,
103+ ] [ ]
104+ ) . map ( ( [ name , opts ] ) => [
61105name ,
62- typeof opts === "string" ? opts : opts . pipelineName ,
106+ typeof opts === "string"
107+ ? { id : opts }
108+ : {
109+ id : opts . pipeline ,
110+ remoteProxyConnectionString : opts . remoteProxyConnectionString ,
111+ } ,
63112] ) ;
64113} else {
65114return [ ] ;
0 commit comments