Skip to content

Function: lockNameOf() ​

lockNameOf(template, input): string

Build a lock name from a template, replacing each {field} with that field of the input ({a.b} reads a nested field). Synchronized uses it for its template names; a template without {} is returned as it is.

Parameters ​

template ​

string

The template, such as 'order:{id}' or 'user:{user.id}:export'.

input ​

unknown

The object whose fields fill the template (an action's validated input).

Returns ​

string

The lock name.

Throws ​

When a field of the template is missing, null, or an object (only strings, numbers and other primitives are accepted).

Example ​

typescript
import {lockNameOf} from 'lakutata/com/mutex'

console.log(lockNameOf('order:{id}', {id: 42})) //order:42
console.log(lockNameOf('user:{user.id}:export', {user: {id: 'u7'}})) //user:u7:export

Released under the MIT License.