Module

for-couchdb

CouchDB adapter for Decaf.ts

View Source index.ts, line 12

Interfaces

CreateIndexRequest

Defines the structure and configuration for a new Mango index

MangoExecutionStats

Provides detailed metrics about query execution including document and key examination counts

MangoQuery

Interface for defining complete Mango queries with selectors, sorting, pagination, and other options

MangoResponse

Contains the matching documents and additional metadata about the query execution

Members

Object

# static constant CouchDBConst

String constants representing special values in CouchDB

Special constant values used in CouchDB queries

Properties:
Name Type Description
NULL string

String representation of null value

View Source query/constants.ts, line 53

Object

# static constant CouchDBGroupOperator

Constants for CouchDB logical operators used in Mango queries

Mapping of logical operator names to CouchDB Mango query operators

Properties:
Name Type Description
AND string

Logical AND operator ($and)

OR string

Logical OR operator ($or)

View Source query/constants.ts, line 39

CouchDBKeysType

# static constant CouchDBKeys

Collection of string constants for CouchDB document properties and operations

Key constants used in CouchDB operations

View Source constants.ts, line 24

Object

# static constant CouchDBOperator

Constants for CouchDB comparison operators used in Mango queries

Mapping of operator names to CouchDB Mango query operators

Properties:
Name Type Description
EQUAL string

Equality operator ($eq)

DIFFERENT string

Inequality operator ($ne)

BIGGER string

Greater than operator ($gt)

BIGGER_EQ string

Greater than or equal operator ($gte)

SMALLER string

Less than operator ($lt)

SMALLER_EQ string

Less than or equal operator ($lte)

NOT string

Negation operator ($not)

IN string

In array operator ($in)

REGEXP string

Regular expression operator ($regex)

View Source query/constants.ts, line 9

# static constant CouchDBQueryLimit

Maximum number of documents to return in a single query

Default query limit for CouchDB queries

View Source query/constants.ts, line 2

# static constant reservedAttributes

Matches any attribute that starts with an underscore

Regular expression to identify reserved attributes in CouchDB

View Source constants.ts, line 2

# inner constant VERSION

The version string of the for-couchdb package

Stores the current package version

View Source index.ts, line 17

Methods

# static generateIndexDoc(attribute, tableName, compositionsopt, orderopt, separatoropt) → {CreateIndexRequest}

Creates a complete CreateIndexRequest object for defining a CouchDB index based on specified parameters

Generates a CouchDB index configuration

sequenceDiagram participant Caller participant generateIndexDoc participant generateIndexName Caller->>generateIndexDoc: attribute, tableName, compositions, order, separator Note over generateIndexDoc: Create partial filter selector generateIndexDoc->>generateIndexDoc: Set up filter for tableName alt order is specified Note over generateIndexDoc: Create ordered fields array generateIndexDoc->>generateIndexDoc: Create orderProp for attribute generateIndexDoc->>generateIndexDoc: Map compositions to ordered props generateIndexDoc->>generateIndexDoc: Create sortedTable for table field generateIndexDoc->>generateIndexDoc: Combine all ordered fields else Note over generateIndexDoc: Create simple fields array generateIndexDoc->>generateIndexDoc: Use attribute, compositions, and table as strings end generateIndexDoc->>generateIndexName: Generate index name generateIndexName-->>generateIndexDoc: Return name Note over generateIndexDoc: Create final index request generateIndexDoc-->>Caller: Return CreateIndexRequest
Parameters:
Name Type Attributes Default Description
attribute string

The primary attribute for the index

tableName string

The name of the table

compositions Array.<string> <optional>

Optional additional attributes to include in the index

order OrderDirection <optional>

Optional sort order for the index

separator string <optional>
DefaultSeparator

The separator to use between parts of the index name

View Source utils.ts, line 108

The complete index configuration object

# static generateIndexName(attribute, tableName, compositionsopt, orderopt, separatoropt) → {string}

Creates a standardized name for a CouchDB index based on the table, attribute, compositions, and order

Generates a name for a CouchDB index

Parameters:
Name Type Attributes Default Description
attribute string

The primary attribute for the index

tableName string

The name of the table

compositions Array.<string> <optional>

Optional additional attributes to include in the index

order OrderDirection <optional>

Optional sort order for the index

separator string <optional>
DefaultSeparator

The separator to use between parts of the index name

View Source utils.ts, line 88

The generated index name

string

# static generateIndexes(models) → {Array.<CreateIndexRequest>}

Creates a set of CouchDB index configurations based on the metadata of the provided models

Generates CouchDB index configurations for models

sequenceDiagram participant Caller participant generateIndexes participant generateIndexName participant Repository Caller->>generateIndexes: models Note over generateIndexes: Create base table index generateIndexes->>generateIndexName: [CouchDBKeys.TABLE] generateIndexName-->>generateIndexes: tableName generateIndexes->>generateIndexes: Create table index config loop For each model generateIndexes->>Repository: Get indexes metadata Repository-->>generateIndexes: index metadata loop For each index in metadata Note over generateIndexes: Extract index properties generateIndexes->>Repository: Get table name Repository-->>generateIndexes: tableName Note over generateIndexes: Define nested generate function generateIndexes->>generateIndexes: Call generate() for default order Note over generateIndexes: Create index name and config alt Has directions loop For each direction generateIndexes->>generateIndexes: Call generate(direction) Note over generateIndexes: Create ordered index config end end end end generateIndexes-->>Caller: Array of index configurations
Parameters:
Name Type Description
models

Array of model constructors to generate indexes for

View Source indexes/generator.ts, line 24

Array of CouchDB index configurations

Array.<CreateIndexRequest>

# static reAuth(con, user, pass) → {Promise.<any>}

Refreshes the authentication for a CouchDB connection using the provided credentials

Re-authenticates a connection to CouchDB

Parameters:
Name Type Description
con any

The CouchDB connection object

user string

The username for authentication

pass string

The password for authentication

View Source utils.ts, line 6

A promise that resolves to the authentication result

Promise.<any>

# static testReservedAttributes(attr) → {RegExpMatchArray|null}

Checks if an attribute name starts with an underscore, which indicates it's a reserved attribute in CouchDB

Tests if an attribute name is reserved in CouchDB

Parameters:
Name Type Description
attr string

The attribute name to test

View Source utils.ts, line 76

The match result or null if no match

RegExpMatchArray | null

# static translateOperators(operator) → {MangoOperator}

Converts Decaf.ts core operators to their equivalent CouchDB Mango query operators

Translates core operators to CouchDB Mango operators

sequenceDiagram participant Caller participant translateOperators participant CouchDBOperator participant CouchDBGroupOperator Caller->>translateOperators: operator translateOperators->>CouchDBOperator: Check for match alt Found in CouchDBOperator CouchDBOperator-->>translateOperators: Return matching operator translateOperators-->>Caller: Return MangoOperator else Not found translateOperators->>CouchDBGroupOperator: Check for match alt Found in CouchDBGroupOperator CouchDBGroupOperator-->>translateOperators: Return matching operator translateOperators-->>Caller: Return MangoOperator else Not found translateOperators-->>Caller: Throw QueryError end end
Parameters:
Name Type Description
operator GroupOperator | Operator

The core operator to translate

View Source query/translate.ts, line 4

If no translation exists for the given operator

QueryError

The equivalent CouchDB Mango operator

MangoOperator

# static wrapDocumentScope(con, dbName, user, pass) → {any}

Creates a proxy around a CouchDB database connection that automatically re-authenticates before each operation

Wraps a CouchDB database connection with automatic re-authentication

sequenceDiagram participant Client participant wrapDocumentScope participant DB participant reAuth Client->>wrapDocumentScope: con, dbName, user, pass wrapDocumentScope->>DB: con.use(dbName) Note over wrapDocumentScope: Wrap DB methods with re-auth loop For each method (insert, get, put, destroy, find) wrapDocumentScope->>wrapDocumentScope: Store original method wrapDocumentScope->>wrapDocumentScope: Define new method with re-auth end wrapDocumentScope->>wrapDocumentScope: Add NATIVE property with con value wrapDocumentScope-->>Client: Return wrapped DB Note over Client: Later when client uses DB methods Client->>DB: Any wrapped method call DB->>reAuth: Authenticate before operation reAuth-->>DB: Authentication complete DB->>DB: Call original method DB-->>Client: Return result
Parameters:
Name Type Description
con any

The CouchDB connection object

dbName string

The name of the database to use

user string

The username for authentication

pass string

The password for authentication

View Source utils.ts, line 19

The wrapped database connection object

any

Type Definitions

Object

# CouchDBKeysType

Collection of string constants for CouchDB document properties and operations

Key constants used in CouchDB operations

Properties:
Name Type Description
SEPARATOR string

Separator used for combining table name and ID

ID string

CouchDB document ID field

REV string

CouchDB document revision field

DELETED string

CouchDB deleted document marker

TABLE string

Table name marker

SEQUENCE string

Sequence marker

DDOC string

Design document marker

NATIVE string

Native marker

INDEX string

Index marker

View Source constants.ts, line 9

string

# MangoOperator

Union type of all possible operators that can be used in Mango queries

Operators available in Mango queries

View Source types.ts, line 112

number | string | Date | boolean | object | null

# MangoValue

Union type of all possible value types that can be used in Mango queries

Represents the possible value types in a Mango query

View Source types.ts, line 105

string | Array.<string> | Object

# SortOrder

Type for defining sort order in Mango queries

Represents a sort order specification in Mango queries

Properties:
Name Type Description
{...} "asc" | "desc"
See:

View Source types.ts, line 120