Skip to content

@codesoul-co/hypha-memory / mongo-structured-store

Using this module

Use the Mongo structured store module for persisting and reading data at this boundary. It exports 1 class, 1 function, 7 interfaces, 1 type.

Import from the package entrypoint

ts
import {
  MongoStructuredStoreProvider,
  normalizeMongoStructuredStoreError,
} from '@codesoul-co/hypha-memory';

import type {
  MongoCollectionLike,
  MongoCursorLike,
  MongoDatabaseLike,
  MongoOperationOptionsLike,
  MongoSessionLike,
  MongoStructuredStoreHealth,
  MongoStructuredStoreProviderOptions,
  MongoTransactionMode,
} from '@codesoul-co/hypha-memory';

Usage patterns

  • Use the 8 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 1 class as constructable runtime implementations. Each symbol entry lists its constructor and public methods.
  • The module exposes 1 function as direct operation entrypoints. Every overload, required/optional parameter, and return type is documented below.

Public exports

SymbolKindSignatureDescription
MongoStructuredStoreProviderclassnew MongoStructuredStoreProvider(options: MongoStructuredStoreProviderOptions, session?: MongoSessionLike | undefined): MongoStructuredStoreProviderMongo-backed StructuredStoreProvider without leaking a Mongo SDK into Memory contracts.
normalizeMongoStructuredStoreErrorfunctionnormalizeMongoStructuredStoreError(error: unknown, operation: string): import("./contracts").NormalizedMemoryErrorNormalize Mongo Structured Store Error function with 1 public call signature; parameters and return types are listed below.
MongoCollectionLikeinterfaceinterface MongoCollectionLikeMongo Collection Like interface with 6 public fields or methods.
MongoCursorLikeinterfaceinterface MongoCursorLikeMongo Cursor Like interface with 3 public fields or methods.
MongoDatabaseLikeinterfaceinterface MongoDatabaseLikeMongo Database Like interface with 3 public fields or methods.
MongoOperationOptionsLikeinterfaceinterface MongoOperationOptionsLikeMongo Operation Options Like interface with 1 public fields or methods.
MongoSessionLikeinterfaceinterface MongoSessionLikeMongo Session Like interface with 2 public fields or methods.
MongoStructuredStoreHealthinterfaceinterface MongoStructuredStoreHealthMongo Structured Store Health interface with 3 public fields or methods.
MongoStructuredStoreProviderOptionsinterfaceinterface MongoStructuredStoreProviderOptionsMongo Structured Store Provider Options interface with 3 public fields or methods.
MongoTransactionModetypetype MongoTransactionMode = 'required' | 'preferred' | 'disabled'Public type alias for Mongo Transaction Mode; the declaration contains its complete type expression.

MongoStructuredStoreProvider

Mongo-backed StructuredStoreProvider without leaking a Mongo SDK into Memory contracts.

  • Kind: class
  • Import: import { MongoStructuredStoreProvider } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export declare class MongoStructuredStoreProvider implements StructuredStoreProvider {
    constructor(options: MongoStructuredStoreProviderOptions, session?: MongoSessionLike | undefined);
    get<T>(table: string, id: string): Promise<T | null>;
    insert<T extends {
            id: string;
        }>(table: string, record: T): Promise<void>;
    update<T>(table: string, id: string, patch: Partial<T>): Promise<void>;
    compareAndSet<T>(table: string, id: string, expected: Partial<T>, patch: Partial<T>): Promise<boolean>;
    delete(table: string, id: string): Promise<void>;
    query<T>(table: string, query: StructuredQuery): Promise<T[]>;
    transaction<T>(operation: (tx: StructuredStoreProvider) => Promise<T>): Promise<T>;
    supportsTransactions(): boolean;
    initialize(collections: readonly string[]): Promise<void>;
    health(): Promise<MongoStructuredStoreHealth>;
}

Public members

MemberKindSignatureDescription
compareAndSetmethodcompareAndSet<T>(table: string, id: string, expected: Partial<T>, patch: Partial<T>): Promise<boolean>Public method; parameters and return type are shown in the signature.
constructorconstructor(options: MongoStructuredStoreProviderOptions, session?: MongoSessionLike | undefined): MongoStructuredStoreProviderCreates an instance of this class.
deletemethoddelete(table: string, id: string): Promise<void>Public method; parameters and return type are shown in the signature.
getmethodget<T>(table: string, id: string): Promise<T | null>Public method; parameters and return type are shown in the signature.
healthmethodhealth(): Promise<MongoStructuredStoreHealth>Public method; parameters and return type are shown in the signature.
initializemethodinitialize(collections: readonly string[]): Promise<void>Public method; parameters and return type are shown in the signature.
insertmethodinsert<T extends { id: string; }>(table: string, record: T): Promise<void>Public method; parameters and return type are shown in the signature.
querymethodquery<T>(table: string, query: StructuredQuery): Promise<T[]>Public method; parameters and return type are shown in the signature.
supportsTransactionsmethodsupportsTransactions(): booleanPublic method; parameters and return type are shown in the signature.
transactionmethodtransaction<T>(operation: (tx: StructuredStoreProvider) => Promise<T>): Promise<T>Public method; parameters and return type are shown in the signature.
updatemethodupdate<T>(table: string, id: string, patch: Partial<T>): Promise<void>Public method; parameters and return type are shown in the signature.

normalizeMongoStructuredStoreError

Normalize Mongo Structured Store Error function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { normalizeMongoStructuredStoreError } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export declare function normalizeMongoStructuredStoreError(error: unknown, operation: string): import("./contracts").NormalizedMemoryError;

Call signature

text
normalizeMongoStructuredStoreError(error: unknown, operation: string): import("./contracts").NormalizedMemoryError

Parameters

ParameterTypeRequiredDescription
errorunknownYesRequired parameter; accepted values are defined by the type column.
operationstringYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: NormalizedMemoryError
  • Description: The return contract is defined by the type shown above.

MongoCollectionLike

Mongo Collection Like interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { MongoCollectionLike } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export interface MongoCollectionLike {
    findOne<T>(filter: Record<string, unknown>, options?: MongoOperationOptionsLike): Promise<T | null>;
    insertOne<T extends object>(document: T, options?: MongoOperationOptionsLike): Promise<unknown>;
    updateOne(filter: Record<string, unknown>, update: {
        $set: Record<string, unknown>;
    }, options?: MongoOperationOptionsLike): Promise<{
        matchedCount?: number;
    }>;
    deleteOne(filter: Record<string, unknown>, options?: MongoOperationOptionsLike): Promise<{
        deletedCount?: number;
    }>;
    find<T>(filter: Record<string, unknown>, options?: MongoOperationOptionsLike): MongoCursorLike<T>;
    createIndex?(keys: Record<string, 1 | -1>, options?: {
        unique?: boolean;
        name?: string;
    }): Promise<unknown>;
}

Contract members

MemberKindSignatureDescription
createIndexmethodcreateIndex?(keys: Record<string, 1 | -1>, options?: { unique?: boolean; name?: string; }): Promise<unknown>Public method; parameters and return type are shown in the signature.
deleteOnemethoddeleteOne(filter: Record<string, unknown>, options?: MongoOperationOptionsLike): Promise<{ deletedCount?: number; }>Public method; parameters and return type are shown in the signature.
findmethodfind<T>(filter: Record<string, unknown>, options?: MongoOperationOptionsLike): MongoCursorLike<T>Public method; parameters and return type are shown in the signature.
findOnemethodfindOne<T>(filter: Record<string, unknown>, options?: MongoOperationOptionsLike): Promise<T | null>Public method; parameters and return type are shown in the signature.
insertOnemethodinsertOne<T extends object>(document: T, options?: MongoOperationOptionsLike): Promise<unknown>Public method; parameters and return type are shown in the signature.
updateOnemethodupdateOne(filter: Record<string, unknown>, update: { $set: Record<string, unknown>; }, options?: MongoOperationOptionsLike): Promise<{ matchedCount?: number; }>Public method; parameters and return type are shown in the signature.

MongoCursorLike

Mongo Cursor Like interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { MongoCursorLike } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export interface MongoCursorLike<T> {
    sort?(order: Record<string, 1 | -1>): MongoCursorLike<T>;
    limit?(limit: number): MongoCursorLike<T>;
    toArray(): Promise<T[]>;
}

Contract members

MemberKindSignatureDescription
limitmethodlimit?(limit: number): MongoCursorLike<T>Public method; parameters and return type are shown in the signature.
sortmethodsort?(order: Record<string, 1 | -1>): MongoCursorLike<T>Public method; parameters and return type are shown in the signature.
toArraymethodtoArray(): Promise<T[]>Public method; parameters and return type are shown in the signature.

MongoDatabaseLike

Mongo Database Like interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { MongoDatabaseLike } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export interface MongoDatabaseLike {
    collection(name: string): MongoCollectionLike;
    startSession?(): MongoSessionLike;
    command?(command: Record<string, unknown>): Promise<unknown>;
}

Contract members

MemberKindSignatureDescription
collectionmethodcollection(name: string): MongoCollectionLikePublic method; parameters and return type are shown in the signature.
commandmethodcommand?(command: Record<string, unknown>): Promise<unknown>Public method; parameters and return type are shown in the signature.
startSessionmethodstartSession?(): MongoSessionLikePublic method; parameters and return type are shown in the signature.

MongoOperationOptionsLike

Mongo Operation Options Like interface with 1 public fields or methods.

  • Kind: interface
  • Import: import type { MongoOperationOptionsLike } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export interface MongoOperationOptionsLike {
    session?: MongoSessionLike;
}

Contract members

MemberKindSignatureDescription
sessionpropertysession?: MongoSessionLikePublic property; its type, readonly modifier and optionality are shown in the signature.

MongoSessionLike

Mongo Session Like interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { MongoSessionLike } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export interface MongoSessionLike {
    withTransaction<T>(operation: () => Promise<T>): Promise<T>;
    endSession(): Promise<void>;
}

Contract members

MemberKindSignatureDescription
endSessionmethodendSession(): Promise<void>Public method; parameters and return type are shown in the signature.
withTransactionmethodwithTransaction<T>(operation: () => Promise<T>): Promise<T>Public method; parameters and return type are shown in the signature.

MongoStructuredStoreHealth

Mongo Structured Store Health interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { MongoStructuredStoreHealth } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export interface MongoStructuredStoreHealth {
    status: 'healthy' | 'degraded' | 'unhealthy';
    transactions: boolean;
    message?: string;
}

Contract members

MemberKindSignatureDescription
messagepropertymessage?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
statuspropertystatus: "healthy" | "degraded" | "unhealthy"Public property; its type, readonly modifier and optionality are shown in the signature.
transactionspropertytransactions: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.

MongoStructuredStoreProviderOptions

Mongo Structured Store Provider Options interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { MongoStructuredStoreProviderOptions } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export interface MongoStructuredStoreProviderOptions {
    database: MongoDatabaseLike;
    transactionMode?: MongoTransactionMode;
    collectionPrefix?: string;
}

Contract members

MemberKindSignatureDescription
collectionPrefixpropertycollectionPrefix?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
databasepropertydatabase: MongoDatabaseLikePublic property; its type, readonly modifier and optionality are shown in the signature.
transactionModepropertytransactionMode?: MongoTransactionModePublic property; its type, readonly modifier and optionality are shown in the signature.

MongoTransactionMode

Public type alias for Mongo Transaction Mode; the declaration contains its complete type expression.

  • Kind: type
  • Import: import type { MongoTransactionMode } from '@codesoul-co/hypha-memory';
  • Source module: mongo-structured-store

Declaration

text
export type MongoTransactionMode = 'required' | 'preferred' | 'disabled';