Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions bynk-emit/src/emitter/workers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::emitter::{
BOUNDARY_CODEC_RUNTIME_IMPORTS, BYTES_RUNTIME_IMPORTS, JSON_CODEC_RUNTIME_IMPORTS, RuntimeUse,
inject_runtime_imports,
};
use crate::project::{ImportExt, LocaleNegotiationArgs, UnitTable, unit_table_uses_emit};
use crate::project::{ImportExt, LocaleNegotiationArgs, UnitTable};
use bynk_check::symbols::MessageBundleInfo;
use bynk_syntax::ast::*;

Expand Down Expand Up @@ -57,6 +57,14 @@ pub(crate) fn emit_worker_compose(
// the caller already resolved the cardinality, this function only acts).
locale_bundle: Option<&MessageBundleInfo>,
import_ext: ImportExt,
// #1187's slice 6 plumbing: `unit_table_uses_emit(table, callees)`,
// precomputed by the caller (`crate::project::RunChecks::Checked::
// unit_callees`'s own doc comment has the full grounding for what feeds
// it) — reads the checker's own already-resolved `Callee` classification
// instead of re-deriving `Events.emit` detection from raw AST syntax. A
// bare `bool`, not the `Callee` map itself: this function has exactly
// one use for it.
uses_emit: bool,
) -> (String, bool) {
let mut out = String::new();
let _ = writeln!(out, "// Generated by bynkc — do not edit by hand.");
Expand Down Expand Up @@ -199,8 +207,7 @@ pub(crate) fn emit_worker_compose(
// `deps.__eventsDispatch` that calls into it — mirrors `unit_table_uses_
// emit`'s Bundle-mode gate on `composeApp`'s `__eventsDispatch` closure,
// so the two targets agree on when the field exists.
let ctx_uses_emit = unit_table_uses_emit(table);
if ctx_uses_emit {
if uses_emit {
runtime_imports.push("dispatchToEventsFanout");
}
let _ = writeln!(
Expand Down Expand Up @@ -258,14 +265,14 @@ pub(crate) fn emit_worker_compose(
let bind = agent_binding_name(a);
let _ = writeln!(out, " {bind}: DurableObjectNamespace;");
}
if ctx_uses_emit {
if uses_emit {
let bind = agent_binding_name(EVENTS_FANOUT_CLASS_NAME);
let _ = writeln!(out, " {bind}: DurableObjectNamespace;");
}
let _ = writeln!(out, "}}");
writeln!(out).unwrap();

if !agent_names.is_empty() || ctx_uses_emit {
if !agent_names.is_empty() || uses_emit {
let _ = writeln!(
out,
"type DurableObjectNamespace = {{ idFromName(name: string): {{ toString(): string }}; get(id: any): any }};"
Expand Down Expand Up @@ -351,7 +358,7 @@ pub(crate) fn emit_worker_compose(
// release-at-commit event batch is handed to this context's own fan-out
// DO — `env.<bind>` is typed by the `Env` interface built above, one
// instance per publishing context.
if ctx_uses_emit {
if uses_emit {
let bind = agent_binding_name(EVENTS_FANOUT_CLASS_NAME);
deps_entries.push(format!(
"__eventsDispatch: (events: Array<{}>) => dispatchToEventsFanout(env.{bind}, events)",
Expand Down
5 changes: 4 additions & 1 deletion bynk-emit/src/emitter/workers_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub(crate) fn emit_worker_entry(
// `scheduled`/`queue`, so the two entry points need distinct compose
// calls, not one shared string.
needs_locale_request: bool,
// #1187's slice 6 plumbing — see `emit_worker_compose`'s own matching
// parameter (`emitter/workers.rs`) for the full grounding.
uses_emit: bool,
) -> String {
let mut out = String::new();
// Which conditional runtime helpers the entry's own inbound/outbound codecs
Expand Down Expand Up @@ -280,7 +283,7 @@ pub(crate) fn emit_worker_entry(
// requirement, for the fan-out DO — it lives in its own file
// (`events_fanout.ts`, not `handlers.ts`; a fan-out DO has no backing
// `AgentDecl` for `emit_agent` to emit it from).
if crate::project::unit_table_uses_emit(table) {
if uses_emit {
let _ = writeln!(
out,
"export {{ {} }} from \"./events_fanout.js\";",
Expand Down
10 changes: 8 additions & 2 deletions bynk-emit/src/emitter/wrangler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::fmt::Write as _;

use crate::project::{UnitTable, unit_table_uses_emit, worker_dir_name};
use crate::project::{UnitTable, worker_dir_name};

/// Compile-time pinned compatibility date. Cloudflare uses this to lock
/// Workers runtime behaviour. Bump cautiously when changing the runtime
Expand Down Expand Up @@ -61,6 +61,12 @@ pub(crate) fn emit_wrangler_toml(
// v0.10b/v0.44: every `from queue("name")` service's bound queue name,
// sorted+deduped (same reproducibility requirement as `crons`).
queues: &[String],
// #1187's slice 6 plumbing: `unit_table_uses_emit(table, callees)`,
// precomputed by the caller — passing a bare `bool` rather than the
// `Callee` map itself keeps this file's own hard-won zero `bynk_syntax::
// ast` footprint (#1191) intact; the map's own element type would have
// reintroduced exactly the literal spelling that slice removed.
uses_emit: bool,
) -> String {
let name = worker_dir_name(context);
let mut out = String::new();
Expand Down Expand Up @@ -101,7 +107,7 @@ pub(crate) fn emit_wrangler_toml(
// only cares that `index.ts` (this Worker's `main`) exports a class with
// this name, not which generated file it came from.
let mut class_names: Vec<String> = table.agents.keys().cloned().collect();
if unit_table_uses_emit(table) {
if uses_emit {
class_names.push(EVENTS_FANOUT_CLASS_NAME.to_string());
}
class_names.sort();
Expand Down
Loading