Creates a new ExecutionContext instance.
The adapter responsible for storing and managing context values
Adds a value to the context only if it doesn't already exist.
If the token already has a value, this operation is a no-op. Useful for initializing context values that should only be set once.
Token representing the context key
The value to add
This context instance for method chaining
Binds a function to this execution context.
Returns a new function that, when called, executes the original function within this context. Useful for passing context-bound functions to callbacks, event handlers, or async operations.
A new function that accepts the same arguments and runs within this context
Checks if an array context value contains a specific item or matches a predicate.
Token representing an array in the context
Either the exact value to find, or a predicate function to test items
true if the array contains the value or matches the predicate, false otherwise
Checks if a context value exists (is present in the context).
Token representing the value to check
true if the value exists, false otherwise
Retrieves a context value, or null if not found.
Token representing the value to retrieve
The context value, or null if not found
Retrieves a context value with a fallback default value.
Returns the stored value if it exists, otherwise returns the provided default. The default value can be a direct value or a lazily-evaluated function.
Token representing the value to retrieve
The default value to return if not found (can be a function)
The context value, or the default value if not found
Retrieves a context value, throwing an error if not found.
Use this when you expect the value to be present and want to fail fast if it's missing.
Token representing the value to retrieve
The context value
Checks if a context value is missing (not present in the context).
Token representing the value to check
true if the value is missing, false if it exists
Puts a value into the context, creating or overwriting any existing value.
This is the primary way to set or update a context value. It always succeeds regardless of whether the key existed before.
Token representing the context key
The value to store
This context instance for method chaining
Puts a numeric value in the context and decrements it.
If the key doesn't exist, initializes it with the specified initialValue, then decrements it. If it exists, decrements the current value. Respects the optional min floor.
Token representing a numeric value in the context
Optionalsettings: PutDecrementSettingsConfiguration for initialization and decrement behavior
This context instance for method chaining
Puts a numeric value in the context and increments it.
If the key doesn't exist, initializes it with the specified initialValue, then increments it. If it exists, increments the current value. Respects the optional max cap.
Token representing a numeric value in the context
Optionalsettings: PutIncrementSettingsConfiguration for initialization and increment behavior
This context instance for method chaining
Puts an array into the context and pushes values to it.
If the key doesn't exist, creates a new array with the provided values. If it exists, appends the provided values to the existing array. Enables accumulating arrays in the context.
Token representing an array in the context
The values to push to the array
This context instance for method chaining
Removes a value from the context.
After removal, the token will be missing from the context. Subsequent get() calls will return null.
Token representing the context key to remove
This context instance for method chaining
Executes a function within this execution context.
The function runs with this context active, making all stored context values accessible to the function and any functions it calls.
The return value of the executed function
Updates an existing context value only if it already exists.
If the token doesn't have a value, this operation is a no-op. Useful for safely updating values that should already be present.
Token representing the context key
The new value
This context instance for method chaining
Updates an existing numeric value in the context by decrementing it.
Only decrements if the value already exists. Respects the optional min floor.
Token representing a numeric value in the context
Optionalsettings: DecrementSettingsConfiguration for decrement behavior
This context instance for method chaining
Updates an existing numeric value in the context by incrementing it.
Only increments if the value already exists. Respects the optional max cap.
Token representing a numeric value in the context
Optionalsettings: IncrementSettingsConfiguration for increment behavior
This context instance for method chaining
Updates an existing array in the context by pushing values to it.
Only appends to the array if it already exists. If the value doesn't exist, this operation is a no-op.
Token representing an array in the context
The values to push to the array
This context instance for method chaining
Conditionally applies one or more operations to the context.
If the condition evaluates to true, executes all provided invokable functions with this context. The condition can be a direct boolean or a lazy-evaluated function. Useful for conditional context modifications.
This context instance for method chaining
IMPORT_PATH:
"@daiso-tech/core/execution-context"Manages execution context values and provides a way to execute functions within a context.
The ExecutionContext class serves as the main entry point for context management. It delegates all operations to an underlying context adapter that handles the actual storage and lifecycle of context values. This allows different adapter implementations (e.g., AsyncLocalStorage for Node.js) to manage context differently.
Provides methods to: