# 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
|
# get(key) → {any}
Retrieves a value from the context by key.
Retrieves a value from the context by key.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string
|
any
# async static args(operation, model, args, contextualopt, overridesopt) → {Promise.<ContextArgs.<F, C>>}
Prepares arguments for context operations
.Prepares arguments for context operations
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
operation |
OperationKeys.CREATE
|
OperationKeys.READ
|
OperationKeys.UPDATE
|
OperationKeys.DELETE
|
||
model |
Constructor.<M>
|
||
args |
Array
|
||
contextual |
Contextual.<F>
|
<optional> |
|
overrides |
Partial.<F>
|
<optional> |
Promise.<ContextArgs.<F, C>>
# static childFrom(context, overridesopt) → {C}
Creates a child context from another context
.Creates a child context from another context
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
context |
C
|
||
overrides |
Partial.<F>
|
<optional> |
C
# async static from(operation, overrides, model, args) → {Promise.<C>}
Creates a new context from operation parameters
.Creates a new context from operation parameters
Parameters:
| Name | Type | Description |
|---|---|---|
operation |
OperationKeys.CREATE
|
OperationKeys.READ
|
OperationKeys.UPDATE
|
OperationKeys.DELETE
|
|
overrides |
Partial.<F>
|
|
model |
Constructor.<M>
|
|
args |
Array
|
Promise.<C>