@@ -3,7 +3,7 @@ import fs from "fs/promises";
33import { Request , Response } from "undici" ;
44import { z } from "zod" ;
55import { Awaitable , JsonSchema } from "../../helpers" ;
6- import { Service , Worker_Binding , Worker_Module } from "../../runtime" ;
6+ import { Service , Worker_Binding , Worker_Module , kVoid } from "../../runtime" ;
77import { BINDING_SERVICE_LOOPBACK , Plugin } from "../shared" ;
88import {
99 ModuleDefinitionSchema ,
@@ -107,6 +107,10 @@ const SERVICE_USER_PREFIX = `${CORE_PLUGIN_NAME}:user`;
107107// Service prefix for custom fetch functions defined in `serviceBindings` option
108108const SERVICE_CUSTOM_PREFIX = `${ CORE_PLUGIN_NAME } :custom` ;
109109
110+ export function getUserServiceName ( name = "" ) {
111+ return `${ SERVICE_USER_PREFIX } :${ name } ` ;
112+ }
113+
110114export const HEADER_PROBE = "MF-Probe" ;
111115export const HEADER_CUSTOM_SERVICE = "MF-Custom-Service" ;
112116
@@ -141,12 +145,7 @@ export const SCRIPT_CUSTOM_SERVICE = `addEventListener("fetch", (event) => {
141145 event.respondWith(${ BINDING_SERVICE_LOOPBACK } .fetch(request));
142146})` ;
143147
144- const now = new Date ( ) ;
145- const fallbackCompatibilityDate = [
146- now . getFullYear ( ) ,
147- ( now . getMonth ( ) + 1 ) . toString ( ) . padStart ( 2 , "0" ) ,
148- now . getDate ( ) . toString ( ) . padStart ( 2 , "0" ) ,
149- ] . join ( "-" ) ;
148+ const FALLBACK_COMPATIBILITY_DATE = "2000-01-01" ;
150149
151150export const CORE_PLUGIN : Plugin <
152151 typeof CoreOptionsSchema ,
@@ -208,6 +207,7 @@ export const CORE_PLUGIN: Plugin<
208207 workerBindings,
209208 workerIndex,
210209 sharedOptions,
210+ durableObjectClassNames,
211211 } ) {
212212 // Define core/shared services.
213213 // Services get de-duped by name, so only the first worker's
@@ -224,23 +224,29 @@ export const CORE_PLUGIN: Plugin<
224224 serviceWorkerScript : SCRIPT_ENTRY ,
225225 compatibilityDate : "2022-09-01" ,
226226 bindings : serviceEntryBindings ,
227- compatibilityDate : "2022-09-01" ,
228227 } ,
229228 } ,
230229 ] ;
231230
232231 // Define regular user worker if script is set
233232 const workerScript = getWorkerScript ( options ) ;
234233 if ( workerScript !== undefined ) {
235- const name = `${ SERVICE_USER_PREFIX } :${ options . name ?? "" } ` ;
234+ const name = getUserServiceName ( options . name ) ;
235+ const classNames = durableObjectClassNames . get ( name ) ?? [ ] ;
236+
236237 services . push ( {
237238 name,
238239 worker : {
239240 ...workerScript ,
240241 compatibilityDate :
241- options . compatibilityDate ?? fallbackCompatibilityDate ,
242+ options . compatibilityDate ?? FALLBACK_COMPATIBILITY_DATE ,
242243 compatibilityFlags : options . compatibilityFlags ,
243244 bindings : workerBindings ,
245+ durableObjectNamespaces : classNames . map ( ( className ) => ( {
246+ className,
247+ uniqueKey : className ,
248+ } ) ) ,
249+ durableObjectStorage : { inMemory : kVoid } ,
244250 } ,
245251 } ) ;
246252 serviceEntryBindings . push ( {
0 commit comments