# new Context(cache)
The Context class provides a mechanism for managing repository operations with flags, parent-child relationships, and state accumulation. It allows for hierarchical context chains and maintains operation-specific configurations while supporting type safety through generics.
A context management class for handling repository operations.
Parameters:
Name | Type | Description |
---|---|---|
cache |
ObjectAccumulator.<F>
|
The internal cache storing accumulated values |
Example
```typescript
// Creating a new context with repository flags
const context = new Context<RepositoryFlags>();
// Accumulating values
const enrichedContext = context.accumulate({
writeOperation: true,
affectedTables: ['users'],
operation: OperationKeys.CREATE
});
// Accessing values
const isWrite = enrichedContext.get('writeOperation'); // true
const tables = enrichedContext.get('affectedTables'); // ['users']
```
Classes
- Context
The Context class provides a mechanism for managing repository operations with flags, parent-child relationships, and state accumulation. It allows for hierarchical context chains and maintains operation-specific configurations while supporting type safety through generics.
Methods
# accumulate(value)
Merges the provided value object with the existing context state, creating a new immutable cache state.
Accumulates new values into the context.
Parameters:
Name | Type | Description |
---|---|---|
value |
V
|
The object containing values to accumulate |
A new context instance with accumulated values
# child(operation, modelopt) → {C}
Generates a new context instance with current context as parent
Creates a child context
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
operation |
OperationKeys
|
The operation type |
|
model |
Constructor.<M>
|
<optional> |
Optional model constructor |
New child context instance
C
# get(key)
Attempts to get a value from the current context's cache. If not found, traverses up the parent context chain.
Retrieves a value from the context by key.
Parameters:
Name | Type | Description |
---|---|---|
key |
K
|
The key to retrieve from the context |
If the key is not found in the context chain
Error
The value associated with the key
# async static args(operation, model, args, contextualopt, overridesopt) → {Promise.<ContextArgs>}
Creates a context args object with the specified operation parameters
Prepares arguments for context operations
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
operation |
OperationKeys.DELETE
|
The operation type |
|
model |
Constructor.<M>
|
The model constructor |
|
args |
Array.<any>
|
Operation arguments |
|
contextual |
Contextual.<F>
|
<optional> |
Optional contextual object |
overrides |
Partial.<F>
|
<optional> |
Optional flag overrides |
Promise resolving to context arguments
Promise.<ContextArgs>
# static childFrom(context, overridesopt) → {C}
Generates a new context instance with parent reference
Creates a child context from another context
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
context |
C
|
The parent context |
|
overrides |
Partial.<F>
|
<optional> |
Optional flag overrides |
New child context instance
C
# async static from(operation, overrides, model, args) → {Promise.<C>}
Generates a context instance for specific operation
Creates a new context from operation parameters
Parameters:
Name | Type | Description |
---|---|---|
operation |
OperationKeys.DELETE
|
The operation type |
overrides |
Partial.<F>
|
Flag overrides |
model |
Constructor.<M>
|
The model constructor |
args |
any
|
Operation arguments |
Promise resolving to new context
Promise.<C>