API Reference
Classes
Util
Utility functions.
Static Functions
Name | Description |
---|---|
base64Decode | Converts a string from base64 to UTF-8. |
base64Encode | Converts a string from UTF-8 to base64. |
env | Returns the value of an environment variable. |
nanoid | Generates a unique ID using the nanoid library. |
sha256 | Computes the SHA256 hash of the given data. |
sleep | Suspends execution for a given duration. |
tryEnv | Returns the value of an environment variable. |
uuidv4 | Generates a version 4 UUID. |
waitUntil | Run 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.
stringToDecode
Required
- Type: str
base64 string to decode.
url
Optional
- 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.
stringToEncode
Required
- Type: str
The name of the UTF-8 string to encode.
url
Optional
- 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.
name
Required
- 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
options
Optional
- Type: NanoidOptions
Optional options object for generating the ID.
sha256
bring util;
util.sha256(data: str);
Computes the SHA256 hash of the given data.
data
Required
- Type: str
The string to be hashed.
sleep
bring util;
util.sleep(delay: duration);
Suspends execution for a given duration.
delay
Required
- Type: duration
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.
name
Required
- 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.
predicate
Required
- Type: IPredicateHandler
The function that will be evaluated.
props
Optional
- Type: WaitUntilProps
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
Name | Type | Description |
---|---|---|
alphabet | str | Characters that make up the alphabet to generate the ID, limited to 256 characters or fewer. |
size | num | Size of ID. |
alphabet
Optional
alphabet: str;
- Type: str
Characters that make up the alphabet to generate the ID, limited to 256 characters or fewer.
size
Optional
size: num;
- Type: num
- Default: 21
Size of ID.
WaitUntilProps
Properties for util.waitUntil
.
Initializer
bring util;
let WaitUntilProps = util.WaitUntilProps{ ... };
Properties
Name | Type | Description |
---|---|---|
interval | duration | Interval between predicate retries. |
timeout | duration | The timeout for keep trying predicate. |
interval
Optional
interval: duration;
- Type: duration
- Default: 0.1s
Interval between predicate retries.
timeout
Optional
timeout: duration;
- Type: duration
- Default: 1m
The timeout for keep trying predicate.
Protocols
IPredicateHandler
Extends: IResource
Implemented By: IPredicateHandler
Inflight client: @winglang/sdk.util.IPredicateHandlerClient
A predicate with an inflight "handle" method that can be passed to util.busyWait
.
Properties
Name | Type | Description |
---|---|---|
node | constructs.Node | The tree node. |
node
Required
node: Node;
- Type: constructs.Node
The tree node.
IPredicateHandlerClient
- Implemented By: IPredicateHandlerClient
Inflight client for IPredicateHandler
.
Methods
Name | Description |
---|---|
handle | The Predicate function that is called. |
handle
inflight handle(): bool
The Predicate function that is called.