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

The object containing values to accumulate

View Source repository/Context.ts, line 256

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

View Source repository/Context.ts, line 280

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

View Source repository/Context.ts, line 269

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

sequenceDiagram participant C as Context participant M as Model participant A as Args C->>C: Receive operation request C->>M: Validate model constructor C->>C: Create child context C->>A: Process operation args A->>C: Return context args C->>C: Apply overrides C->>C: Return final context
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

View Source repository/Context.ts, line 337

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

View Source repository/Context.ts, line 292

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

View Source repository/Context.ts, line 307

Promise resolving to new context

Promise.<C>