@iprokit/service
Version:
Powering distributed systems with simplicity and speed.
108 lines (107 loc) • 2.41 kB
TypeScript
/**
* @iProKit/Service
* Copyright (c) 2019-2025 Rutvik Katuri / iProTechs
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Signal is used for multi-stage communication.
* It is represented as a case-sensitive string.
*
* Example: `NEXT%ONE=A&TWO=B`
*
* A Signal consists of an event name and tags:
* - Event: `NEXT`
* - Tags: `ONE=A&TWO=B`
*/
export default class Signal {
/**
* Event name of the signal.
*/
readonly event: string;
/**
* Tags of the signal.
*/
readonly tags: Tags;
/**
* Creates an instance of `Signal`.
*
* @param event name of the signal.
* @param tags optional tags of the signal.
*/
constructor(event: string, tags?: Tags);
/**
* Gets a tag value.
*
* @param key tag key.
*/
get(key: string): string | undefined;
/**
* Returns `true` if the tag exists, `false` otherwise.
*
* @param key tag key.
*/
has(key: string): boolean;
/**
* Sets a tag.
*
* @param key tag key.
* @param value tag value.
*/
set(key: string, value: string): this;
/**
* Removes a tag.
*
* @param key tag key.
*/
delete(key: string): this;
/**
* Returns an array of tag keys.
*/
keys(): string[];
/**
* Returns an array of tag values.
*/
values(): (string | undefined)[];
/**
* Returns an array of key-value pairs of tags.
*/
entries(): [string, string | undefined][];
/**
* Returns the number of tags.
*/
get size(): number;
/**
* Returns the stringified version of the `Signal`.
*/
stringify(): string;
/**
* Returns the objectified version of a `Signal`.
*
* @param signal stringified version of a `Signal`.
*/
static objectify(signal: string): Signal;
/**
* Delimiter for the event, denoted by `%`.
*
* @example `event%tags`
*/
static readonly EVENT_DELIMITER: string;
/**
* Delimiter for tags, denoted by `&`.
*
* @example `tag1&tag2`
*/
static readonly TAGS_DELIMITER: string;
/**
* Delimiter for a key-value pair, denoted by `=`.
*
* @example `key=value`
*/
static readonly TAG_DELIMITER: string;
}
/**
* Tags associated with a `Signal`.
*/
export interface Tags {
[key: string]: string | undefined;
}