| 1 | export const SOCKET_USER_ENTRY = "user-entry"; |
| 2 | export const SERVICE_USER_WORKER = "user-worker"; |
| 3 | |
| 4 | /** |
| 5 | * Default date shared by deployed Workers, framework runners, previews, and |
| 6 | * internal isolates. |
| 7 | */ |
| 8 | export const DEFAULT_COMPATIBILITY_DATE = "2026-08-31"; |
| 9 | |
| 10 | export const NODEJS_COMPAT_DEFAULT_ON = "2026-08-04"; |
| 11 | |
| 12 | /** Apply language and runtime defaults while preserving explicit opt-outs. */ |
| 13 | export const withDefaultFlags = ( |
| 14 | flags: Array<string> | undefined, |
| 15 | { |
| 16 | date = DEFAULT_COMPATIBILITY_DATE, |
| 17 | python = flags?.includes("python_workers") ?? false, |
| 18 | isExternal = true, |
| 19 | bundle = true, |
| 20 | }: { |
| 21 | date?: string; |
| 22 | python?: boolean; |
| 23 | isExternal?: boolean; |
| 24 | bundle?: boolean; |
| 25 | } = {}, |
| 26 | ): Array<string> => { |
| 27 | // Prebuilt external Workers own their runtime configuration. In particular, |
| 28 | // adopting one with explicit flags must not inject Alchemy's build defaults. |
| 29 | // See https://github.com/alchemy-run/alchemy/issues/1721. |
| 30 | if (isExternal && !bundle && flags !== undefined) { |
| 31 | return [...flags]; |
| 32 | } |
| 33 | const defaults = new Set(flags); |
| 34 | if (python) { |
| 35 | defaults.add("python_workers"); |
| 36 | } else { |
| 37 | if (!defaults.has("legacy_module_registry")) { |
| 38 | defaults.add("new_module_registry"); |
| 39 | } |
| 40 | // Older external workers must not select Node's legacy v1 mode. |
| 41 | if ( |
| 42 | !defaults.has("no_nodejs_compat") && |
| 43 | date < NODEJS_COMPAT_DEFAULT_ON && |
| 44 | (!isExternal || date >= "2024-09-23") |
| 45 | ) { |
| 46 | defaults.add("nodejs_compat"); |
| 47 | } |
| 48 | } |
| 49 | if (!isExternal && date < "2024-10-14") { |
| 50 | defaults.add("handle_cross_request_promise_resolution"); |
| 51 | } |
| 52 | return [...defaults]; |
| 53 | }; |
| 54 | |
| 55 | export const defaultDurableObjectUniqueKey = ( |
| 56 | scriptName: string, |
| 57 | className: string, |
| 58 | ) => `${encodeURIComponent(scriptName)}-${encodeURIComponent(className)}`; |