Skip to content

Function: channelName()

channelName(value): string

Derive a legal Postgres channel name from whatever a caller used to identify the channel.

Callers think in terms of what the channel IS - an app name, a tenant id, a [env, feature] pair, a config object - and none of those are identifiers. Rejecting them pushed the sanitizing onto every call site, which is how two services end up disagreeing about whether the channel is my-app, my_app, or myApp and silently never hear each other.

The parts are tokenized and joined into an identifier, then a short hash of the ORIGINAL parts is appended. The hash is what makes the mapping trustworthy: tokenizing alone is lossy, so my-app and my_app and myApp would collapse onto one channel, and a name long enough to hit NAMEDATALEN would collide with anything sharing its leading tokens. With the suffix, the readable part stays readable and distinct inputs stay distinct.

Deterministic across processes and runs, which is the whole point - two services given the same parts must land on the same channel without coordinating. Hash inputs are structure-aware, so ["a", "b"] and ["a_b"] differ, and object key order does not.

unknown

string