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
8 changes: 8 additions & 0 deletions .changeset/sharp-badgers-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@stackables/bridge-compiler": minor
"@stackables/bridge-parser": minor
"@stackables/bridge-core": minor
"@stackables/bridge": minor
---

New alias syntax alias name <- source.from ?? "full syntax" catch "supported"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The `.bridge` language is designed to be scannable.
| **Null Coalesce** | `o.name <- i.name \|\| "N/A"` | Alternative used if the current source resolves to `null`. |
| **Error Guard** | `o.price <- api.price catch 0` | Alternative used if the current source **throws** an exception. |
| **Ternary** | `o.val <- i.isPro ? a : b` | Evaluates condition; strictly pulls only the chosen branch. |
| **Node Alias** | `alias uc:i.name as name` | Evaluates an expression once and caches it as a local graph node. |
| **Node Alias** | `alias name <- uc:i.name` | Evaluates an expression once and caches it as a local graph node. |
| **Arrays** | `o <- items[] as it { }` | Iterates over an array, creating a local shadow scope for each element. |

**[Read the Full Language Guide](https://bridge.sdk42.com/reference/10-core-concepts/)**
Expand Down
2 changes: 1 addition & 1 deletion examples/without-graphql/should_i_go_outside.bridge
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bridge Query.should_i_go_outside {
g.q <- i.cityName
g.format = "json"

alias first:g as f
alias f <- first:g

w.latitude <- f.lat
w.longitude <- f.lon
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-compiler/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3454,7 +3454,7 @@ class CodegenContext {
return this.elementWireToExpr(w, elVar);
}
}
// Check if this is a pipe tool call (alias tool:source as name)
// Check if this is a pipe tool call (alias name <- tool:source)
if (isPull(w) && w.pipe) {
return this.elementWireToExpr(w, elVar);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/bridge-compiler/test/codegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ describe("AOT codegen: async array mapping", () => {
with output as o

o.items <- api.results[] as item {
alias enricher:item as e
alias e <- enricher:item
.name <- item.name ?? continue
.extra <- e.data
}
Expand Down Expand Up @@ -2107,7 +2107,7 @@ describe("AOT codegen: async array mapping", () => {
o <- api.groups[] as g {
.label <- g.name
.items <- g.items[] as sub {
alias enricher:sub as e
alias e <- enricher:sub
.value <- e.data
}
}
Expand Down Expand Up @@ -2145,7 +2145,7 @@ describe("AOT codegen: async array mapping", () => {
with output as o

o.items <- api.results[] as item {
alias enricher:item as e
alias e <- enricher:item
.name <- item.name ?? continue
.extra <- e.data catch "n/a"
}
Expand Down Expand Up @@ -2178,7 +2178,7 @@ describe("AOT codegen: async array mapping", () => {

o.title <- api.title
o.items <- api.items[] as item {
alias enricher:item as e
alias e <- enricher:item
.name <- item.name ?? continue
.extra <- e.data
}
Expand Down Expand Up @@ -2279,7 +2279,7 @@ bridge Query.catalog {
with output as o

o <- src.items[] as it {
alias enrich:it as e
alias e <- enrich:it
.id <- it.item_id
.label <- e.name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("buildTraversalManifest source locations", () => {
bridge Query.test {
with input as i
with output as o
alias i.empty.array.error catch i.empty.array.error as clean
alias clean <- i.empty.array.error catch i.empty.array.error
o.message <- i.empty.array?.error ?? i.empty.array.error catch clean
}
`);
Expand Down
16 changes: 10 additions & 6 deletions packages/bridge-parser/src/bridge-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
}
}

// Emit block-scoped local bindings: alias <source> as <name>
// Emit block-scoped local bindings: alias <name> <- <source>
for (const [alias, info] of localBindingsByAlias) {
// Ternary alias in element scope
if (info.ternaryWire) {
Expand Down Expand Up @@ -1679,7 +1679,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
const fallbackStr = serFallbacks(tw, sPipeOrRef);
const errf = serCatch(tw, sPipeOrRef);
lines.push(
`${indent}alias ${condStr} ? ${thenStr} : ${elseStr}${fallbackStr}${errf} as ${alias}`,
`${indent}alias ${alias} <- ${condStr} ? ${thenStr} : ${elseStr}${fallbackStr}${errf}`,
);
continue;
}
Expand Down Expand Up @@ -1769,7 +1769,11 @@ function serializeBridgeBlock(bridge: Bridge): string {
sourcePart = sRef(fromRef, true);
}
}
lines.push(`${indent}alias ${sourcePart} as ${alias}`);
const elemFb = serFallbacks(srcWire, sPipeOrRef);
const elemErrf = serCatch(srcWire, sPipeOrRef);
lines.push(
`${indent}alias ${alias} <- ${sourcePart}${elemFb}${elemErrf}`,
);
}

// Emit element-scoped tool declarations: with <tool> as <handle>
Expand Down Expand Up @@ -2219,7 +2223,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
}

// ── Top-level alias declarations ─────────────────────────────────────
// Emit `alias <source> as <name>` for __local bindings that are NOT
// Emit `alias <name> <- <source>` for __local bindings that are NOT
// element-scoped (those are handled inside serializeArrayElements).
for (const [alias, info] of localBindingsByAlias) {
// Ternary alias: emit `alias <cond> ? <then> : <else> [fallbacks] as <name>`
Expand All @@ -2237,7 +2241,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
const fallbackStr = serFallbacks(tw, sPipeOrRef);
const errf = serCatch(tw, sPipeOrRef);
lines.push(
`alias ${condStr} ? ${thenStr} : ${elseStr}${fallbackStr}${errf} as ${alias}`,
`alias ${alias} <- ${condStr} ? ${thenStr} : ${elseStr}${fallbackStr}${errf}`,
);
continue;
}
Expand Down Expand Up @@ -2294,7 +2298,7 @@ function serializeBridgeBlock(bridge: Bridge): string {
}
const aliasFb = serFallbacks(srcWire, sPipeOrRef);
const aliasErrf = serCatch(srcWire, sPipeOrRef);
lines.push(`alias ${sourcePart}${aliasFb}${aliasErrf} as ${alias}`);
lines.push(`alias ${alias} <- ${sourcePart}${aliasFb}${aliasErrf}`);
}
// Also emit wires reading from top-level __local bindings
for (const lw of localReadWires) {
Expand Down
Loading
Loading