Skip to main content

API Reference

Classes

Util

Utility functions.

Static Functions

NameDescription
base64DecodeConverts a string from base64 to UTF-8.
base64EncodeConverts a string from UTF-8 to base64.
envReturns the value of an environment variable.
nanoidGenerates a unique ID using the nanoid library.
sha256Computes the SHA256 hash of the given data.
sleepSuspends execution for a given duration.
tryEnvReturns the value of an environment variable.
uuidv4Generates a version 4 UUID.
waitUntilRun a predicate repeatedly, waiting until it returns true or until the timeout elapses.

base64Decode
bring util;

util.base64Decode(stringToDecode: str, url?: bool);

Converts a string from base64 to UTF-8.

stringToDecodeRequired
  • Type: str

base64 string to decode.


urlOptional
  • Type: bool

If true, the source is expected to be a URL-safe base64 string.


base64Encode
bring util;

util.base64Encode(stringToEncode: str, url?: bool);

Converts a string from UTF-8 to base64.

stringToEncodeRequired
  • Type: str

The name of the UTF-8 string to encode.


urlOptional
  • Type: bool

If true, a URL-safe base64 string is returned.


env
bring util;

util.env(name: str);

Returns the value of an environment variable.

Throws if not found or empty.

nameRequired
  • Type: str

The name of the environment variable.


nanoid
bring util;

util.nanoid(options?: NanoidOptions);

Generates a unique ID using the nanoid library.

@link https://github.com/ai/nanoid

optionsOptional

Optional options object for generating the ID.


sha256
bring util;

util.sha256(data: str);

Computes the SHA256 hash of the given data.

dataRequired
  • Type: str

The string to be hashed.


sleep
bring util;

util.sleep(delay: duration);

Suspends execution for a given duration.

delayRequired

The time to suspend execution.


tryEnv
bring util;

util.tryEnv(name: str);

Returns the value of an environment variable.

Returns nil if not found or empty.

nameRequired
  • Type: str

The name of the environment variable.


uuidv4
bring util;

util.uuidv4();

Generates a version 4 UUID.

waitUntil
bring util;

util.waitUntil(predicate: IPredicateHandler, props?: WaitUntilProps);

Run a predicate repeatedly, waiting until it returns true or until the timeout elapses.

predicateRequired

The function that will be evaluated.


propsOptional

Timeout and interval values, default to one 1m timeout and 0.1sec interval.


Structs

NanoidOptions

Options to generating a unique ID.

Initializer

bring util;

let NanoidOptions = util.NanoidOptions{ ... };

Properties

NameTypeDescription
alphabetstrCharacters that make up the alphabet to generate the ID, limited to 256 characters or fewer.
sizenumSize of ID.

alphabetOptional
alphabet: str;
  • Type: str

Characters that make up the alphabet to generate the ID, limited to 256 characters or fewer.


sizeOptional
size: num;
  • Type: num
  • Default: 21

Size of ID.


WaitUntilProps

Properties for util.waitUntil.

Initializer

bring util;

let WaitUntilProps = util.WaitUntilProps{ ... };

Properties

NameTypeDescription
intervaldurationInterval between predicate retries.
timeoutdurationThe timeout for keep trying predicate.

intervalOptional
interval: duration;

Interval between predicate retries.


timeoutOptional
timeout: duration;

The timeout for keep trying predicate.


Protocols

IPredicateHandler

Inflight client: @winglang/sdk.util.IPredicateHandlerClient

A predicate with an inflight "handle" method that can be passed to util.busyWait.

Properties

NameTypeDescription
nodeconstructs.NodeThe tree node.

nodeRequired
node: Node;
  • Type: constructs.Node

The tree node.


IPredicateHandlerClient

Inflight client for IPredicateHandler.

Methods

NameDescription
handleThe Predicate function that is called.

handle
inflight handle(): bool

The Predicate function that is called.