Skip to main content

ottoman

Enumerations

Classes

Interfaces

Type Aliases

AggType

Ƭ AggType: "$arrayAgg" | "$avg" | "$mean" | "$count" | "$countn" | "$max" | "$median" | "$min" | "$stddev" | "$stddevPop" | "$stddevSamp" | "$sum" | "$variance" | "$variancePop" | "$varianceSamp" | "$varPop" | "$varSamp"

List of aggregation functions.

Defined in

query/interface/query.types.ts:13


ComparisonEmptyOperatorType

Ƭ ComparisonEmptyOperatorType: "$isNull" | "$isNotNull" | "$isMissing" | "$isNotMissing" | "$isValued" | "$isNotValued"

List of Boolean comparison operators.

Defined in

query/interface/query.types.ts:35


ComparisonMultipleOperatorType

Ƭ ComparisonMultipleOperatorType: "$btw" | "$notBtw"

List of Range comparison operators.

Defined in

query/interface/query.types.ts:53


ComparisonSingleOperatorType

Ƭ ComparisonSingleOperatorType: "$eq" | "$neq" | "$gt" | "$gte" | "$lt" | "$lte"

List of Numeric comparison operators.

Defined in

query/interface/query.types.ts:45


ComparisonSingleStringOperatorType

Ƭ ComparisonSingleStringOperatorType: "$like" | "$notLike"

List of String comparison operators.

Defined in

query/interface/query.types.ts:49


ComparisonWhereExpr

Ƭ ComparisonWhereExpr: { [key in ComparisonEmptyOperatorType | ComparisonSingleOperatorType | ComparisonMultipleOperatorType | ComparisonSingleStringOperatorType]?: string | number | boolean | (number | string)[] } | { [key in CollectionDeepSearchOperatorType]?: string | any[] }

Structure of the comparison operators.

Example

{ operator: value } -> e.g { $like: '%ottoman%' }

Defined in

query/interface/query.types.ts:129


IDocument

Ƭ IDocument<T>: CleanDocument & T

Type parameters

NameType
Tany

Defined in

model/document.ts:21


ISelectAggType

Ƭ ISelectAggType: { [key in AggType]?: ISelectFieldType }

SELECT aggregation expression

Example

 { $count: { $field: { name: 'address' }, as: 'addr' } } | { $count: { $field: 'address' } }

Defined in

query/interface/query.types.ts:194


ISelectType

Ƭ ISelectType: ISelectReturnResultType | ISelectResultExprType | ISelectAggType | ISelectFieldType

SELECT expression

Example

 { $all: { $field: { name: 'address' }, as: 'addr' }, $field: 'type', $field: { name: 'count' } }

Defined in

query/interface/query.types.ts:246


IndexType

Ƭ IndexType: "CREATE" | "BUILD" | "DROP" | "CREATE PRIMARY"

Types of supported index statements

Defined in

query/interface/query.types.ts:277


LetExprType

Ƭ LetExprType: Record<string, unknown>

LET expression

Defined in

query/interface/query.types.ts:251


LogicalOperatorType

Ƭ LogicalOperatorType: "$and" | "$or" | "$not"

List of Logical operators.

Defined in

query/interface/query.types.ts:58


LogicalWhereExpr

Ƭ LogicalWhereExpr<T>: CollectionRangePredicateType | { [key in LogicalOperatorType]?: (FieldWhereExpr<T> | CollectionRangePredicateType)[] } | FieldWhereExpr<T>

Structure of Logical WHERE expression

Example

{ field: { operator: value } } -> e.g { $or: [{ address: { $like: '%ottoman%' } }] }

Type parameters

NameType
Tany

Defined in

query/interface/query.types.ts:164


ModelTypes

Ƭ ModelTypes<T, R>: WhateverTypes & IModel<T, R> & (data: T, options?: CastOptions) => IDocument<T>

Type parameters

NameType
Tany
Rany

Defined in

model/model.types.ts:35


MutationFunctionOptions

Ƭ MutationFunctionOptions: Object

Desc

Used by the mutation functions to apply the defined strategy.

Type declaration

NameType
enforceRefCheck?boolean | "throw"
maxExpiry?number
strict?ApplyStrategy
transactionContext?TransactionAttemptContext

Defined in

utils/cast-strategy.ts:51


ResultExprType

Ƭ ResultExprType: "$raw" | "$element" | "$value"

Result expressions of RAW | ELEMENT | VALUE type.

Defined in

query/interface/query.types.ts:9


ReturnResultType

Ƭ ReturnResultType: "$all" | "$distinct"

Result expressions of ALL | DISTINCT type.

Defined in

query/interface/query.types.ts:5


SortType

Ƭ SortType: "ASC" | "DESC"

Defined in

query/interface/query.types.ts:1

Variables

AggDict

Const AggDict: Record<AggType, string>

Dictionary for handling aggregation functions.

Defined in

query/helpers/dictionary.ts:18


ResultExprDict

Const ResultExprDict: Record<ResultExprType, string>

Dictionary for handling result expressions of RAW | ELEMENT | VALUE type.

Defined in

query/helpers/dictionary.ts:41


ReturnResultDict

Const ReturnResultDict: Record<ReturnResultType, string>

Dictionary for handling result expressions of ALL | DISTINCT type.

Defined in

query/helpers/dictionary.ts:46

Functions

addValidators

addValidators(validators): void

Register custom validators to Schema validators register.

Function

Throws

Error

Example

   addValidators({
email: (value) => {
regexp = new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
if (!regexp.test(value)) {
throw new Error('Email address is invalid.')
}
}
});

const ContactSchema = new Schema({
name: String,
contact: { type: String, validator: 'email' }
});

Parameters

NameType
validatorsCustomValidations

Returns

void

Defined in

schema/helpers/fn-schema.ts:240


applyDefaultValue

applyDefaultValue(obj, schema): any

Apply default values defined on schema to an object instance.

Example

 const schema = { name: { type: String, default: 'John' }, hasChild: { type: Boolean, default: true } };
const obj: any = applyDefaultValue(obj, schema)

console.log(obj);

Parameters

NameTypeDescription
objanyreference to object instance
schemaSchema | SchemaDefdefinition will be used to determine default definitions

Returns

any

Defined in

schema/helpers/fn-schema.ts:196


buildIndexExpr

buildIndexExpr(collection, type, name, on?, where?, usingGSI?, withExpr?): string

Build a INDEX N1QL query from user-specified parameters. https://docs.couchbase.com/server/6.5/n1ql/n1ql-language-reference/createindex.html

Parameters

NameTypeDescription
collectionstringCollection name
typeIndexTypeINDEX clause types ('CREATE' | 'BUILD' | 'DROP' | 'CREATE PRIMARY')
namestring-
on?IIndexOnParams[]ON Clause
where?LogicalWhereExpr<any>WHERE Clause
usingGSI?booleanuse a Global Secondary Index (GSI)
withExpr?IIndexWithParamsWITH Clause

Returns

string

N1QL INDEX Query

Defined in

query/helpers/builders.ts:537


buildSelectExpr

buildSelectExpr(n1ql, clause): string

Recursive function to create N1QL queries.

Parameters

NameTypeDescription
n1qlstringN1QL Query String
clauseISelectTypeSELECT Clause

Returns

string

N1QL SELECT Query

Defined in

query/helpers/builders.ts:135


buildWhereClauseExpr

buildWhereClauseExpr(n1ql, clause, ignoreCase?): string

Recursive function to create WHERE N1QL expressions.

Parameters

NameTypeDefault valueDescription
n1qlstringundefinedN1QL Query String
clauseLogicalWhereExpr<any>undefinedWHERE Clause param
ignoreCasebooleanfalseApply ignoreCase

Returns

string

N1QL WHERE expression

Defined in

query/helpers/builders.ts:302


close

close(): Promise<void>

Returns

Promise<void>

Defined in

ottoman/ottoman.ts:583


connect

connect(connectOptions): Promise<void>

Parameters

NameType
connectOptionsstring | ConnectOptions

Returns

Promise<void>

Defined in

ottoman/ottoman.ts:577


getCollection

getCollection(collectionName?, scopeName?): Collection

Parameters

NameTypeDefault value
collectionNamestringDEFAULT_COLLECTION
scopeNamestringDEFAULT_SCOPE

Returns

Collection

Defined in

ottoman/ottoman.ts:590


getDefaultInstance

getDefaultInstance(): Ottoman

Returns

Ottoman

Defined in

ottoman/ottoman.ts:575


getModel

getModel(name): ModelTypes<any, any>

Parameters

NameType
namestring

Returns

ModelTypes<any, any>

Defined in

ottoman/ottoman.ts:589


getModelMetadata

getModelMetadata(modelConstructor): ModelMetadata

Parameters

NameType
modelConstructorany

Returns

ModelMetadata

Defined in

model/utils/model.utils.ts:19


getOttomanInstances

getOttomanInstances(): Ottoman[]

Returns

Ottoman[]

Defined in

ottoman/ottoman.ts:576


getProjectionFields

getProjectionFields(selectDot, select?, options?, modelKey?): Object

Parameters

NameTypeDefault value
selectDotstringundefined
selectstring | string[] | ISelectType[]''
optionsObject{}
options.noCollection?booleanundefined
modelKeystringMODEL_KEY

Returns

Object

NameType
fieldsstring[]
projectionstring

Defined in

utils/query/extract-select.ts:23


getValueByPath

getValueByPath<T>(obj, path): any

Type parameters

NameType
TRecord<string, any>

Parameters

NameType
objT
pathstring

Returns

any

Defined in

utils/getValueByPath.ts:3


is

is(val, type): boolean

Checking if a value is a specific type or constructor

Parameters

NameType
valany
typeany

Returns

boolean

Defined in

utils/is-type.ts:8


isDocumentNotFoundError

isDocumentNotFoundError(exception): boolean

Return a boolean value if an exception is DocumentNotFoundError.

Parameters

NameType
exceptionany

Returns

boolean

Defined in

utils/is-not-found.ts:6


isSchemaFactoryType

isSchemaFactoryType(value, factory): boolean

Checking if a value is a factory supported by Ottoman.

Parameters

NameTypeDescription
valueany
factoryanyList of Schema Factories

Returns

boolean

Defined in

utils/is-type.ts:24


isSchemaTypeSupported

isSchemaTypeSupported(val): boolean

Checking if a value is a type supported by Ottoman.

Parameters

NameType
valany

Returns

boolean

Defined in

utils/is-type.ts:15


model

model<T, R>(name, schema, options?): ModelTypes<T, R>

Type parameters

NameType
Tany
RT

Parameters

NameType
namestring
schemaSchema | Record<string, unknown>
options?ModelOptions

Returns

ModelTypes<T, R>

Defined in

ottoman/ottoman.ts:592


parseStringSelectExpr

parseStringSelectExpr(expr): string[]

Convert select expression into an Array of selection keys

Parameters

NameType
exprstring

Returns

string[]

Defined in

query/utils.ts:20


registerGlobalPlugin

registerGlobalPlugin(...plugins): void

Register a global plugin.

Parameters

NameType
...pluginsany[]

Returns

void

Defined in

plugins/global-plugin-handler.ts:13


registerType

registerType(name, factory): void

Register a custom type to Schema supported types.

Function

Throws

Error

Example

   registerType(Int8.name, (fieldName, opts) => new Int8(fieldName, opts.required));

Parameters

NameType
namestring
factoryFactoryFunction

Returns

void

Defined in

schema/helpers/fn-schema.ts:211


searchQuery

searchQuery(indexName, query, options?): StreamableRowPromise<SearchResult, SearchRow, SearchMetaData>

Parameters

NameType
indexNamestring
querySearchQuery
options?SearchQueryOptions

Returns

StreamableRowPromise<SearchResult, SearchRow, SearchMetaData>

Defined in

ottoman/ottoman.ts:598


selectBuilder

selectBuilder(collection, select, letExpr?, where?, orderBy?, limit?, offset?, useExpr?, groupByExpr?, lettingExpr?, havingExpr?, plainJoinExpr?, ignoreCase?): string

Build a SELECT N1QL query from user-specified parameters. https://docs.couchbase.com/server/6.5/n1ql/n1ql-language-reference/select-syntax.html

Parameters

NameTypeDescription
collectionstringCollection name
selectstring | ISelectType[]SELECT Clause
letExpr?LetExprTypeLET Clause
where?LogicalWhereExpr<any>WHERE Clause
orderBy?Record<string, SortType>ORDER BY Clause
limit?numberLIMIT Clause
offset?numberOFFSET Clause
useExpr?string[]USE Clause
groupByExpr?IGroupBy[]GROUP BY Clause
lettingExpr?LetExprTypeLETTING Clause
havingExpr?LogicalWhereExpr<any>HAVING Clause
plainJoinExpr?stringPLAIN JOIN string definition
ignoreCase?booleanboolean to ignore case

Returns

string

N1QL SELECT Query

Defined in

query/helpers/builders.ts:62


set

set(key, value): void

Parameters

NameType
keystring
valuestring | number | boolean

Returns

void

Defined in

utils/environment-set.ts:3


setValueByPath

setValueByPath<T>(object, path, value): void

Type parameters

NameType
TRecord<string, any>

Parameters

NameType
objectT
pathstring
valueany

Returns

void

Defined in

utils/setValueByPath.ts:3


start

start(): Promise<void>

Returns

Promise<void>

Defined in

ottoman/ottoman.ts:588


validate

validate(data, schema, options?): any

Validate data using the schema definition.

Throws

BuildSchemaError, ValidationError

Example

   const data = {
name: "John",
age: "50"
};
const schema = new Schema({
name: String,
age: {type: Number, intVal: true}
});
const strictSchema = new Schema({
name: String,
age: {type: Number, intVal: true}
},
{
validationStrategy: VALIDATION_STRATEGY.STRICT
});
console.log(castSchema(data, schema)); // Print { name: "John", age: 50 }
console.log(castSchema(data, strictSchema)); // Throw "Property age must be of type Number"

Parameters

NameTypeDescription
dataanythat is going to be validated
schemaSchema | SchemaDefthat will be used to validate
optionsCastOptions

Returns

any

Defined in

schema/helpers/fn-schema.ts:152