Class

Context

Context(cache)

Constructor

# 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.

sequenceDiagram participant C as Client participant Ctx as Context participant Cache as ObjectAccumulator C->>Ctx: new Context() Ctx->>Cache: create cache C->>Ctx: accumulate(value) Ctx->>Cache: accumulate(value) Cache-->>Ctx: updated cache Ctx-->>C: updated context C->>Ctx: get(key) Ctx->>Cache: get(key) alt Key exists in cache Cache-->>Ctx: value else Key not found Ctx->>Ctx: check parent context alt Parent exists Ctx->>Parent: get(key) Parent-->>Ctx: value else No parent Ctx-->>C: throw error end end Ctx-->>C: requested value
Parameters:
Name Type Description
cache ObjectAccumulator.<F>

The internal cache storing accumulated values

View Source repository/Context.ts, line 72

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

View Source repository/Context.ts, line 188

# 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

View Source repository/Context.ts, line 195

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>

View Source repository/Context.ts, line 226

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>

View Source repository/Context.ts, line 203

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

View Source repository/Context.ts, line 214

Promise.<C>