# Ottoman

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


# ApplyStrategy

Ƭ ApplyStrategy: boolean | THROW

desc Used when trying to apply a value to a given immutable property:

  • false -> Allow apply the new value
  • true -> Don't allow apply the new value
  • 'throw' -> Throw exception "ImmutableError: Field 'field_name' is immutable and current cast strategy is set to 'throw'"

# AutoFunction

Ƭ AutoFunction: function

# Type declaration:

▸ (): unknown


# CollectionDeepSearchOperatorType

Ƭ CollectionDeepSearchOperatorType: "$in" | "$within" | "$notIn" | "$notWithin"

Collection Deep Search Operators.


# CollectionRangePredicateDeepSearchExpressionType

Ƭ CollectionRangePredicateDeepSearchExpressionType: Record‹string, object›

Structure of the collection in within operator.

example

// Using $in
{ var: { $in: expr } }

// Using $within
{ var: { $within: expr } }

@var A string that evaluates to a string representing the variable name in the ANY/EVERY loop
@expr A string or expression that evaluates to a string representing the array to loop through
1
2
3
4
5
6
7
8

# CollectionRangePredicateExpressionType

Ƭ CollectionRangePredicateExpressionType: object

Structure of the collection range predicate expression.

# Type declaration:


# CollectionRangePredicateOperatorType

Ƭ CollectionRangePredicateOperatorType: "$any" | "$every"

Collection Range Predicate Operator.


# CollectionRangePredicateType

Ƭ CollectionRangePredicateType: object

Structure of the collection in within operator.

example

{ $any: { $expr: [{ search:{ $in: 'address' } }], $satisfies:{ address: '10' } } }
1

# Type declaration:


# CollectionSatisfiesOperatorType

Ƭ CollectionSatisfiesOperatorType: "$satisfies"

Collection SATISFIES Operator used within range predicates ( ANY / EVERY ).


# ComparisonEmptyOperatorType

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

List of Boolean comparison operators.


# ComparisonMultipleOperatorType

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

List of Range comparison operators.


# ComparisonSingleOperatorType

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

List of Numeric comparison operators.


# ComparisonSingleStringOperatorType

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

List of String comparison operators.


# ComparisonWhereExpr

Ƭ ComparisonWhereExpr: object | object

Structure of the comparison operators.

example

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

# CustomValidations

Ƭ CustomValidations: object

# Type declaration:


# DateFunction

Ƭ DateFunction: function

# Type declaration:

▸ (): Date | DateOption


# FactoryFunction

Ƭ FactoryFunction: function

# Type declaration:

▸ (name: any, options: any): IOttomanType

Parameters:

Name Type
name any
options any

# FieldMap

Ƭ FieldMap: object

# Type declaration:


# FieldWhereExpr

Ƭ FieldWhereExpr: object | object | Record‹any, any›

Structure of WHERE field expression

example

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

# FieldsBaseType

Ƭ FieldsBaseType: string | string[]


# FunctionsString

Ƭ FunctionsString: function

# Type declaration:

▸ (): string[]


# Hook

Ƭ Hook: object

# Type declaration:


# HookHandler

Ƭ HookHandler: function

# Type declaration:

▸ (IDocument: any): void

Parameters:

Name Type
IDocument any

# HookTypes

Ƭ HookTypes: HOOKS | "validate" | "save" | "update" | "remove"


# IDocument

Ƭ IDocument: Document & T


# ISelectAggType

Ƭ ISelectAggType: object

SELECT aggregation expression

example

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

# Type declaration:


# ISelectResultExprType

Ƭ ISelectResultExprType: object

SELECT result expression

example

 { $raw: { $field: { name: 'address' }, as: 'addr' } }
1

# Type declaration:


# ISelectReturnResultType

Ƭ ISelectReturnResultType: object

SELECT result expression

example

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

# Type declaration:


# ISelectType

Ƭ ISelectType: ISelectReturnResultType | ISelectResultExprType | ISelectAggType | ISelectFieldType

SELECT expression

example

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

# IndexType

Ƭ IndexType: "refdoc" | "n1ql" | "view"

Types of supported index statements


# LetExprType

Ƭ LetExprType: Record‹string, unknown›

LET expression


# LogicalOperatorType

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

List of Logical operators.


# LogicalWhereExpr

Ƭ LogicalWhereExpr: CollectionRangePredicateType | object | FieldWhereExpr‹T›

Structure of Logical WHERE expression

example

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

# ModelTypes

Ƭ ModelTypes: WhateverTypes & IModel‹T, R› & object


# MutationFunctionOptions

Ƭ MutationFunctionOptions: object

desc Used by the mutation functions to apply the defined strategy.

# Type declaration:


# NumberFunction

Ƭ NumberFunction: function

# Type declaration:

▸ (): number | MinmaxOption


# OttomanSchemaTypes

Ƭ OttomanSchemaTypes: "String" | "Boolean" | "Number" | "Date" | "Array" | "Reference" | "Embed" | "Mixed"

Should throw all errors detected.


# ParseResult

Ƭ ParseResult: object

# Type declaration:


# PathToN1QLExpressionType

Ƭ PathToN1QLExpressionType: "identifier" | "string_literal"


# PathToN1QLItemType

Ƭ PathToN1QLItemType: object

# Type declaration:


# PathToN1QLOperationType

Ƭ PathToN1QLOperationType: "member" | "subscript"


# PluginConstructor

Ƭ PluginConstructor: function

# Type declaration:

▸ (Schema: any): void

Parameters:

Name Type
Schema any

# PluginFunctions

Ƭ PluginFunctions: function

# Type declaration:

▸ (): void


# PopulateFieldsType

Ƭ PopulateFieldsType: FieldsBaseType | PopulateSelectType


# PopulateSelectBaseType

Ƭ PopulateSelectBaseType: object

# Type declaration:


# PopulateSelectType

Ƭ PopulateSelectType: object

# Type declaration:


# QueryBuildOptionsType

Ƭ QueryBuildOptionsType: object

Query build options

# Type declaration:

  • ignoreCase? : undefined | false | true

# RequiredFunction

Ƭ RequiredFunction: function

# Type declaration:

▸ (): boolean | RequiredOption


# ResultExprType

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

Result expressions of RAW | ELEMENT | VALUE type.


# ReturnResultType

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

Result expressions of ALL | DISTINCT type.


# SchemaDef

Ƭ SchemaDef: Record‹string, any›


# SchemaIndex

Ƭ SchemaIndex: Record‹string, object›


# SchemaQuery

Ƭ SchemaQuery: Record‹string, object›


# SortType

Ƭ SortType: "ASC" | "DESC"


# Status

Ƭ Status: "SUCCESS" | "FAILURE"

Status of Query Response.


# StringModifiersType

Ƭ StringModifiersType: "$ignoreCase"

List of String Modifiers.


# SupportFactoryTypes

Ƭ SupportFactoryTypes: object

# Type declaration:


# SupportTypes

Ƭ SupportTypes: object

# Type declaration:


# ValidatorFunction

Ƭ ValidatorFunction: function

# Type declaration:

▸ (value: unknown): void

Parameters:

Name Type
value unknown

# WhateverTypes

Ƭ WhateverTypes: object

# Type declaration:

  • [ key: string]: any

# Variables

# Const DEFAULT_COLLECTION

DEFAULT_COLLECTION: "_default" = "_default"

Default collection name.


# Const DEFAULT_ID_KEY

DEFAULT_ID_KEY: "id" = "id"

Key to add document metadata identifier This key will store the value of the key, key -> document, document.id === key


# Const DEFAULT_MAX_EXPIRY

DEFAULT_MAX_EXPIRY: 0 = 0


# Const DEFAULT_SCOPE

DEFAULT_SCOPE: "_default" = "_default"

Default scope name.


# Const KEY_GENERATOR_DELIMITER

KEY_GENERATOR_DELIMITER: "::" = "::"

Default KeyGeneratorDelimiter value.


# Const MODEL_KEY

MODEL_KEY: "_type" = "_type"

Default value for metadata key, to keep collection tracking eg. This model new Model('User', schema, options), will generate documents -> document._type = 'User'


# Let __ottoman

__ottoman: Ottoman

Store default connection.


# Let __ottomanInstances

__ottomanInstances: Ottoman[] = []


# Const __plugins

__plugins: PluginFunctions[] = []

Store global plugins.


# Const modelMetadataSymbol

modelMetadataSymbol: unique symbol = Symbol('modelMetadataSymbol')


# Const n1qlReservedWords

n1qlReservedWords: string[] = [ 'ADVISE', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'ANY', 'ARRAY', 'AS', 'ASC', 'BEGIN', 'BETWEEN', 'BINARY', 'BOOLEAN', 'BREAK', 'BUCKET', 'BUILD', 'BY', 'CALL', 'CASE', 'CAST', 'CLUSTER', 'COLLATE', 'COLLECTION', 'COMMIT', 'CONNECT', 'CONTINUE', 'CORRELATED', 'COVER', 'CREATE', 'CURRENT', 'DATABASE', 'DATASET', 'DATASTORE', 'DECLARE', 'DECREMENT', 'DELETE', 'DERIVED', 'DESC', 'DESCRIBE', 'DISTINCT', 'DO', 'DROP', 'EACH', 'ELEMENT', 'ELSE', 'END', 'EVERY', 'EXCEPT', 'EXCLUDE', 'EXECUTE', 'EXISTS', 'EXPLAIN', 'FALSE', 'FETCH', 'FIRST', 'FLATTEN', 'FOLLOWING', 'FOR', 'FORCE', 'FROM', 'FTS', 'FUNCTION', 'GOLANG', 'GRANT', 'GROUP', 'GROUPS', 'GSI', 'HASH', 'HAVING', 'IF', 'IGNORE', 'ILIKE', 'IN', 'INCLUDE', 'INCREMENT', 'INDEX', 'INFER', 'INLINE', 'INNER', 'INSERT', 'INTERSECT', 'INTO', 'IS', 'JAVASCRIPT', 'JOIN', 'KEY', 'KEYS', 'KEYSPACE', 'KNOWN', 'LANGUAGE', 'LAST', 'LEFT', 'LET', 'LETTING', 'LIKE', 'LIMIT', 'LSM', 'MAP', 'MAPPING', 'MATCHED', 'MATERIALIZED', 'MERGE', 'MINUS', 'MISSING', 'NAMESPACE', 'NEST', 'NL', 'NO', 'NOT', 'NTH_VALUE', 'NULL', 'NULLS', 'NUMBER', 'OBJECT', 'OFFSET', 'ON', 'OPTION', 'OPTIONS [1]', 'OR', 'ORDER', 'OTHERS', 'OUTER', 'OVER', 'PARSE', 'PARTITION', 'PASSWORD', 'PATH', 'POOL', 'PRECEDING', 'PREPARE', 'PRIMARY', 'PRIVATE', 'PRIVILEGE', 'PROBE', 'PROCEDURE', 'PUBLIC', 'RANGE', 'RAW', 'REALM', 'REDUCE', 'RENAME', 'RESPECT', 'RETURN', 'RETURNING', 'REVOKE', 'RIGHT', 'ROLE', 'ROLLBACK', 'ROW', 'ROWS', 'SATISFIES', 'SCHEMA', 'SELECT', 'SELF', 'SEMI', 'SET', 'SHOW', 'SOME', 'START', 'STATISTICS', 'STRING', 'SYSTEM', 'THEN', 'TIES', 'TO', 'TRANSACTION', 'TRIGGER', 'TRUE', 'TRUNCATE', 'UNBOUNDED', 'UNDER', 'UNION', 'UNIQUE', 'UNKNOWN', 'UNNEST', 'UNSET', 'UPDATE', 'UPSERT', 'USE', 'USER', 'USING', 'VALIDATE', 'VALUE', 'VALUED', 'VALUES', 'VIA', 'VIEW', 'WHEN', 'WHERE', 'WHILE', 'WITH', 'WITHIN', 'WORK', 'XOR', ]


# Const replaceList

replaceList: string[] = ['ALL', 'DISTINCT', 'RAW', 'ELEMENT', 'VALUE']

# Functions

# Const KEY_GENERATOR

KEY_GENERATOR(__namedParameters: object): string

Default KeyGenerator function.

Parameters:

__namedParameters: object

Name Type
metadata any

Returns: string


# Const _buildModel

_buildModel(metadata: ModelMetadata): _Model

Parameters:

Name Type
metadata ModelMetadata

Returns: _Model


# Const _keyGenerator

_keyGenerator(keyGen: any, __namedParameters: object, delimeter: string): any

Internal KeyGenerator function.

Parameters:

keyGen: any

__namedParameters: object

Name Type
id any
metadata any

Default value delimeter: string= KEY_GENERATOR_DELIMITER

Returns: any


# addRefKeys

addRefKeys(refKeys: any, collection: any, key: any): AsyncGenerator‹any, void, unknown›

Parameters:

Name Type
refKeys any
collection any
key any

Returns: AsyncGenerator‹any, void, unknown›


# Const addTimestamp

addTimestamp(obj: any, field: any, currentTime: any): void

Parameters:

Name Type
obj any
field any
currentTime any

Returns: void


# Const addValidators

addValidators(validators: CustomValidations): 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' }
  });
1
2
3
4
5
6
7
8
9
10
11
12
13

Parameters:

Name Type
validators CustomValidations

Returns: void


# Const applyDefaultValue

applyDefaultValue(obj: any, schema: Schema | SchemaDef): 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);
1
2
3
4

Parameters:

Name Type Description
obj any reference to object instance
schema Schema | SchemaDef definition will be used to determine default definitions

Returns: any


# Const applyValidator

applyValidator(val: unknown, validator: ValidatorOption | ValidatorFunction | string | undefined, name?: undefined | string): string | void

Parameters:

Name Type
val unknown
validator ValidatorOption | ValidatorFunction | string | undefined
name? undefined | string

Returns: string | void


# Const arrayDiff

arrayDiff(arr1: any, arr2: any): any

Parameters:

Name Type
arr1 any
arr2 any

Returns: any


# Const arrayTypeFactory

arrayTypeFactory(name: string, item: CoreType): ArrayType

Parameters:

Name Type
name string
item CoreType

Returns: ArrayType


# Const booleanTypeFactory

booleanTypeFactory(key: string, opts: CoreTypeOptions): BooleanType

Parameters:

Name Type
key string
opts CoreTypeOptions

Returns: BooleanType


# Const buildFields

buildFields(obj: Schema | SchemaDef, strict: boolean): FieldMap

Build the fields using the given definition. If the [[obj]] is a schema instance, the data will be taken from the fields provided.

function

throws {Error}

example

  const fields = buildFields({ name: String, hasChild: { type: Boolean, default: true } });
1

Parameters:

Name Type Default Description
obj Schema | SchemaDef - the definition or schema instance
strict boolean true will drop all properties not defined in the schema

Returns: FieldMap


# Const buildFieldsRefKey

buildFieldsRefKey(fields: string[], prefix: string): string

Parameters:

Name Type
fields string[]
prefix string

Returns: string


# Const buildIndexExpr

buildIndexExpr(collection: string, type: IndexType, name: string, on?: IIndexOnParams[], where?: LogicalWhereExpr, usingGSI?: undefined | false | true, withExpr?: IIndexWithParams): string

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

Parameters:

Name Type Description
collection string Collection name
type IndexType INDEX clause types ('CREATE'
name string -
on? IIndexOnParams[] ON Clause
where? LogicalWhereExpr WHERE Clause
usingGSI? undefined | false | true use a Global Secondary Index (GSI)
withExpr? IIndexWithParams WITH Clause

Returns: string

N1QL INDEX Query


# Const buildIndexQuery

buildIndexQuery(Model: any, fields: any, indexFnName: any, indexOptions: object): (Anonymous function)

View index function factory.

Parameters:

Name Type Default
Model any -
fields any -
indexFnName any -
indexOptions object {}

Returns: (Anonymous function)


# Const buildMapViewIndexFn

buildMapViewIndexFn(metadata: ModelMetadata, fields: any): string

Parameters:

Name Type
metadata ModelMetadata
fields any

Returns: string


# Const buildRefKey

buildRefKey(fields: string[], values: string[], prefix: string): string

Parameters:

Name Type
fields string[]
values string[]
prefix string

Returns: string


# Const buildSelectArrayExpr

buildSelectArrayExpr(clause: ISelectType[]): string

Create N1QL queries from SELECT array params.

Parameters:

Name Type Description
clause ISelectType[] SELECT Clause

Returns: string

N1QL SELECT Query


# Const buildSelectExpr

buildSelectExpr(n1ql: string, clause: ISelectType): string

Recursive function to create N1QL queries.

Parameters:

Name Type Description
n1ql string N1QL Query String
clause ISelectType SELECT Clause

Returns: string

N1QL SELECT Query


# Const buildViewIndexQuery

buildViewIndexQuery(ottoman: Ottoman, designDocName: any, indexName: any, fields: any, Model: any): (Anonymous function)

Index function factory.

Parameters:

Name Type
ottoman Ottoman
designDocName any
indexName any
fields any
Model any

Returns: (Anonymous function)


# Const buildViewRefdoc

buildViewRefdoc(metadata: ModelMetadata, Model: any, fields: any, prefix: any): (Anonymous function)

Parameters:

Name Type
metadata ModelMetadata
Model any
fields any
prefix any

Returns: (Anonymous function)


# Const buildWhereClauseExpr

buildWhereClauseExpr(n1ql: string, clause: LogicalWhereExpr, ignoreCase: boolean): string

Recursive function to create WHERE N1QL expressions.

Parameters:

Name Type Default Description
n1ql string - N1QL Query String
clause LogicalWhereExpr - WHERE Clause param
ignoreCase boolean false Apply ignoreCase

Returns: string

N1QL WHERE expression


# Const buildWhereExpr

buildWhereExpr(expr?: LogicalWhereExpr, clause: string, ignoreCase: boolean): string

Create WHERE N1QL Expressions. https://docs.couchbase.com/server/6.5/n1ql/n1ql-language-reference/where.html (opens new window)

Parameters:

Name Type Default Description
expr? LogicalWhereExpr - -
clause string "WHERE" WHERE Clause
ignoreCase boolean false Apply ignore case

Returns: string

N1QL WHERE Expression


# Const canBePopulated

canBePopulated(populate: string, fields: string[]): boolean

Determine if a given field can be populated.

Parameters:

Name Type
populate string
fields string[]

Returns: boolean


# Const cast

cast(data: any, schema: any, options: CastOptions): any

Parameters:

Name Type Default
data any -
schema any -
options CastOptions {
strategy: CAST_STRATEGY.DEFAULT_OR_DROP,
strict: true,
skip: [],

} |

Returns: any


# Const checkCastStrategy

checkCastStrategy(value: unknown, strategy: CAST_STRATEGY, type: CoreType | IOttomanType): unknown

Parameters:

Name Type
value unknown
strategy CAST_STRATEGY
type CoreType | IOttomanType

Returns: unknown


# Const close

close(): Promise‹void›

Returns: Promise‹void›


# Const connect

connect(connectOptions: ConnectOptions | string): void

Parameters:

Name Type
connectOptions ConnectOptions | string

Returns: void


# Const createCollection

createCollection(__namedParameters: object): any

Parameters:

__namedParameters: object

Name Type
collectionManager any
collectionName any
maxExpiry any
scopeName any

Returns: any


# Const createMany

createManyT›(metadata: ModelMetadata): (Anonymous function)

Async Function: Create many documents at once

Type parameters:

T

Parameters:

Name Type
metadata ModelMetadata

Returns: (Anonymous function)

(ManyQueryResponse)[(/classes/queryresponse.html)]


# Const dateTypeFactory

dateTypeFactory(name: string, opts: DateTypeOptions & CoreTypeOptions): DateType

Parameters:

Name Type
name string
opts DateTypeOptions & CoreTypeOptions

Returns: DateType


# Const delay

delay(timems: any): Promise‹unknown›

Parameters:

Name Type
timems any

Returns: Promise‹unknown›


# Const embedTypeFactory

embedTypeFactory(name: string, schema: Schema): EmbedType

Parameters:

Name Type
name string
schema Schema

Returns: EmbedType


# Const ensureArrayItemsType

ensureArrayItemsType(array: any, field: any, strategy: any): any

Parameters:

Name Type
array any
field any
strategy any

Returns: any


# Const ensureN1qlIndexes

ensureN1qlIndexes(ottoman: Ottoman, n1qlIndexes: any): Promise‹boolean›

Creates the register index in the Database Server. In addition, creates one index as primary for the bucketName and one for every Ottoman model.

Parameters:

Name Type
ottoman Ottoman
n1qlIndexes any

Returns: Promise‹boolean›


# Const ensureTypes

ensureTypes(item: any, field: IOttomanType, strategy?: CAST_STRATEGY): unknown

Parameters:

Name Type
item any
field IOttomanType
strategy? CAST_STRATEGY

Returns: unknown


# Const ensureViewIndexes

ensureViewIndexes(ottoman: Ottoman, indexes: any): Promise‹undefined | true›

Parameters:

Name Type
ottoman Ottoman
indexes any

Returns: Promise‹undefined | true›


# Const escapeFromClause

escapeFromClause(str: string): string

Parameters:

Name Type
str string

Returns: string


# Const execHooks

execHooks(schema: any, hookType: "preHooks" | "postHooks", hookAction: any, document?: any): Promise‹void›

Executes hooks in a chain, passing previous result to the next hook in chain.

Parameters:

Name Type
schema any
hookType "preHooks" | "postHooks"
hookAction any
document? any

Returns: Promise‹void›


# Const execPopulation

execPopulation(rows: any, toPopulate: string, connection: any, modelName: string, deep?: any, lean: boolean): Promise‹any[]›

Populate a given field through an array with references.

Parameters:

Name Type Default
rows any -
toPopulate string -
connection any -
modelName string -
deep? any -
lean boolean false

Returns: Promise‹any[]›


# Const execPopulationFromObject

execPopulationFromObject(rows: any, populate: any, deep?: any, lean: boolean): Promise‹any[]›

Parameters:

Name Type Default
rows any -
populate any -
deep? any -
lean boolean false

Returns: Promise‹any[]›


# Const extractConnectionString

extractConnectionString(connectOptions: string): ConnectOptions

Parameters:

Name Type
connectOptions string

Returns: ConnectOptions


# Const extractDataFromModel

extractDataFromModel(document: any): any

Get a Model instance and return a JavaScript Object.

Parameters:

Name Type
document any

Returns: any


# Const extractIndexFieldNames

extractIndexFieldNames(gsi: object): string[]

Parameters:

gsi: object

Name Type
fields string[]

Returns: string[]


# Const extractPopulate

extractPopulate(populate: FindOptions["populate"]): string[]

Extract the values to be populated.

Parameters:

Name Type
populate FindOptions["populate"]

Returns: string[]


# Const extractPopulateFieldsFromObject

extractPopulateFieldsFromObject(__namedParameters: object): string[]

Parameters:

__namedParameters: object

Name Type
populate undefined | string | string[] | PopulateSelectType
select undefined | string | string[]

Returns: string[]


# Const extractSchemaReferencesFields

extractSchemaReferencesFields(schema: Schema): any

Parameters:

Name Type
schema Schema

Returns: any


# Const extractSchemaReferencesFromGivenFields

extractSchemaReferencesFromGivenFields(fields: any, schema: Schema): any

Parameters:

Name Type
fields any
schema Schema

Returns: any


# Const extractSelect

extractSelect(select: string | string[], options: object, excludeMeta: boolean, modelKey: string): string[]

Parameters:

select: string | string[]

Default value options: object= {}

Name Type
noCollection? undefined | false | true

Default value excludeMeta: boolean= false

modelKey: string

Returns: string[]


# Const generateUUID

generateUUID(): any

Returns: any


# Const getCollection

getCollection(collectionName: string, scopeName: string): Collection‹›

Parameters:

Name Type Default
collectionName string DEFAULT_COLLECTION
scopeName string DEFAULT_SCOPE

Returns: Collection‹›


# Const getDefaultInstance

getDefaultInstance(): Ottoman‹›

Returns: Ottoman‹›


# Const getGlobalPlugins

getGlobalPlugins(): PluginFunctions[]

Return all global plugins

Returns: PluginFunctions[]


# Const getMetadata

getMetadata(noCollection?: undefined | false | true, modelKey?: undefined | string): string[]

Parameters:

Name Type
noCollection? undefined | false | true
modelKey? undefined | string

Returns: string[]


# Const getModel

getModel(name: string): ModelTypes‹any, any›

Parameters:

Name Type
name string

Returns: ModelTypes‹any, any›


# Const getModelMetadata

getModelMetadata(modelConstructor: any): ModelMetadata

Parameters:

Name Type
modelConstructor any

Returns: ModelMetadata


# Const getModelRefKeys

getModelRefKeys(data: any, prefix: any, ottoman: any): string[]

Parameters:

Name Type
data any
prefix any
ottoman any

Returns: string[]


# Const getOttomanInstances

getOttomanInstances(): Ottoman‹›[]

Returns: Ottoman‹›[]


# Const getProjectionFields

getProjectionFields(selectDot: string, select: ISelectType[] | string | string[], options: object, modelKey: string): object

Parameters:

selectDot: string

Default value select: ISelectType[] | string | string[]= ""

Default value options: object= {}

Name Type
noCollection? undefined | false | true

Default value modelKey: string= MODEL_KEY

Returns: object

  • fields: string[]

  • projection: string


# Const getSchemaType

getSchemaType(fieldName: any, schema: any): any

Parameters:

Name Type
fieldName any
schema any

Returns: any


# Const indexFieldsName

indexFieldsName(fields: string[]): string

Parameters:

Name Type
fields string[]

Returns: string


# Const is

is(val: any, type: any): boolean

Checking if a value is a specific type or constructor

Parameters:

Name Type Description
val any -
type any

Returns: boolean


# Const isDateValid

isDateValid(val: any): boolean

Parameters:

Name Type
val any

Returns: boolean


# Const isDebugMode

isDebugMode(): boolean

Returns: boolean


# Const isDocumentNotFoundError

isDocumentNotFoundError(exception: any): boolean

Return a boolean value if an exception is DocumentNotFoundError.

Parameters:

Name Type
exception any

Returns: boolean


# Const isMetadataKey

isMetadataKey(key: string): boolean

Parameters:

Name Type
key string

Returns: boolean


# Const isModel

isModel(model: any): boolean

Parameters:

Name Type
model any

Returns: boolean


# Const isNumber

isNumber(val: unknown): boolean

Parameters:

Name Type
val unknown

Returns: boolean


# Const isOttomanType

isOttomanType(object: any): boolean

Parameters:

Name Type
object any

Returns: boolean


# Const isPopulateAnObject

isPopulateAnObject(fieldsName?: PopulateFieldsType): boolean

Parameters:

Name Type
fieldsName? PopulateFieldsType

Returns: boolean


# Const isSchemaFactoryType

isSchemaFactoryType(value: any, factory: any): boolean

Checking if a value is a factory supported by Ottoman.

Parameters:

Name Type Description
value any -
factory any List of Schema Factories

Returns: boolean


# Const isSchemaTypeSupported

isSchemaTypeSupported(val: any): boolean

Checking if a value is a type supported by Ottoman.

Parameters:

Name Type Description
val any

Returns: boolean


# isValidDelimiter

isValidDelimiter(str: any): boolean

Parameters:

Name Type
str any

Returns: boolean


# Const jpParse

jpParse(pathStr: string): any

Parameters:

Name Type
pathStr string

Returns: any


# Const mergeHooks

mergeHooks(hook: Record‹string, unknown[]›, other: Record‹string, unknown[]›): object

Parameters:

Name Type
hook Record‹string, unknown[]›
other Record‹string, unknown[]›

Returns: object


# Const mixedTypeFactory

mixedTypeFactory(name: string, otps: CoreTypeOptions): MixedType

Parameters:

Name Type
name string
otps CoreTypeOptions

Returns: MixedType


# Const model

modelT, R›(name: string, schema: Schema | Record‹string, unknown›, options?: ModelOptions): ModelTypes‹T›

Type parameters:

T

R

Parameters:

Name Type
name string
schema Schema | Record‹string, unknown›
options? ModelOptions

Returns: ModelTypes‹T›


# Const nonenumerable

nonenumerable(target: any, propertyKey: string): void

Set a given property of the target to be non-enumerable Will not be listed on Object.keys and will be excluded by spread operator

Parameters:

Name Type
target any
propertyKey string

Returns: void


# Const numberTypeFactory

numberTypeFactory(name: string, otps: CoreTypeOptions & NumberTypeOptions): NumberType

Parameters:

Name Type
name string
otps CoreTypeOptions & NumberTypeOptions

Returns: NumberType


# parseError

parseError(e: CouchbaseError, info: any): void

Parameters:

Name Type
e CouchbaseError
info any

Returns: void


# Const parseStringSelectExpr

parseStringSelectExpr(expr: string): string[]

Convert select expression into an Array of selection keys

Parameters:

Name Type
expr string

Returns: string[]


# Const pathToN1QL

pathToN1QL(path: PathToN1QLItemType[]): string

Parameters:

Name Type
path PathToN1QLItemType[]

Returns: string


# Const pipe

pipe(...fns: any[]): (Anonymous function)

Performs left-to-right function composition for asynchronous functions.

Parameters:

Name Type
...fns any[]

Returns: (Anonymous function)


# Const queryBuildIndexDefered

queryBuildIndexDefered(indexName: any, fields: any, metadata: ModelMetadata, on: string): string

Parameters:

Name Type
indexName any
fields any
metadata ModelMetadata
on string

Returns: string


# Const queryBuildIndexes

queryBuildIndexes(on: any, indexesName: string[]): string

Parameters:

Name Type
on any
indexesName string[]

Returns: string


# Const queryForIndexOttomanType

queryForIndexOttomanType(ottomanType: string, on: string, collectionKey: string): string

Parameters:

Name Type
ottomanType string
on string
collectionKey string

Returns: string


# Const referenceTypeFactory

referenceTypeFactory(name: string, opts: ReferenceOptions): ReferenceType

Parameters:

Name Type
name string
opts ReferenceOptions

Returns: ReferenceType


# Const registerGlobalPlugin

registerGlobalPlugin(...plugins: any[]): void

Register a global plugin.

Parameters:

Name Type
...plugins any[]

Returns: void


# Const registerType

registerType(name: string, factory: FactoryFunction): void

Register a custom type to Schema supported types.

function

throws Error

example

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

Parameters:

Name Type
name string
factory FactoryFunction

Returns: void


# Const remove

remove(id: any, collection: any, options?: RemoveOptions): Promise‹any›

Removes a document by id from a given collection.

Parameters:

Name Type
id any
collection any
options? RemoveOptions

Returns: Promise‹any›


# Const removeMany

removeMany(metadata: ModelMetadata): (Anonymous function)

Async Function: Deletes all of the documents that match conditions from the collection. Allows use of filters and options.

Parameters:

Name Type
metadata ModelMetadata

Returns: (Anonymous function)

(ManyQueryResponse)[(/classes/queryresponse.html)]


# removeRefKeys

removeRefKeys(refKeys: any, collection: any): AsyncGenerator‹any, void, unknown›

Parameters:

Name Type
refKeys any
collection any

Returns: AsyncGenerator‹any, void, unknown›


# Const selectBuilder

selectBuilder(collection: string, select: ISelectType[] | string, letExpr?: LetExprType, where?: LogicalWhereExpr, orderBy?: Record‹string, SortType›, limit?: undefined | number, offset?: undefined | number, useExpr?: string[], groupByExpr?: IGroupBy[], lettingExpr?: LetExprType, havingExpr?: LogicalWhereExpr, plainJoinExpr?: undefined | string, ignoreCase?: undefined | false | true): string

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

Parameters:

Name Type Description
collection string Collection name
select ISelectType[] | string SELECT Clause
letExpr? LetExprType LET Clause
where? LogicalWhereExpr WHERE Clause
orderBy? Record‹string, SortType ORDER BY Clause
limit? undefined | number LIMIT Clause
offset? undefined | number OFFSET Clause
useExpr? string[] USE Clause
groupByExpr? IGroupBy[] GROUP BY Clause
lettingExpr? LetExprType LETTING Clause
havingExpr? LogicalWhereExpr HAVING Clause
plainJoinExpr? undefined | string PLAIN JOIN string definition
ignoreCase? undefined | false | true boolean to ignore case

Returns: string

N1QL SELECT Query


# Const set

set(key: string, value: number | string | boolean): void

Parameters:

Name Type
key string
value number | string | boolean

Returns: void


# Const setModelMetadata

setModelMetadata(modelConstructor: any, metadata: ModelMetadata): ModelMetadata

Parameters:

Name Type
modelConstructor any
metadata ModelMetadata

Returns: ModelMetadata


# Const start

start(): Promise‹void›

Returns: Promise‹void›


# Const store

store(key: any, data: any, options: StoreOptions, collection: any): Promise‹any›

Stores a Document: Updates a document if CAS value is defined, otherwise it inserts a new document. CAS is a value representing the current state of an item/document in the Couchbase Server. Each modification of the document changes it's CAS value.

Parameters:

Name Type
key any
data any
options StoreOptions
collection any

Returns: Promise‹any›


# Const stringTypeFactory

stringTypeFactory(key: string, opts: StringTypeOptions): StringType

Parameters:

Name Type
key string
opts StringTypeOptions

Returns: StringType


# Const stringifyValues

stringifyValues(value: unknown): string

Parameters:

Name Type
value unknown

Returns: string


# Const tryCreateCollection

tryCreateCollection(__namedParameters: object, retries: number, delayMS: number): Promise‹void›

Parameters:

__namedParameters: object

Name Type
collectionManager any
collectionName any
maxExpiry any
scopeName any

Default value retries: number= 3

Default value delayMS: number= 5000

Returns: Promise‹void›


# Const updateMany

updateMany(metadata: ModelMetadata): (Anonymous function)

Async Function: Update all of the documents that match conditions from the collection. Allows use of filters and options.

Parameters:

Name Type
metadata ModelMetadata

Returns: (Anonymous function)

(ManyQueryResponse)[(/classes/queryresponse.html)]


# Const updateRefdocIndexes

updateRefdocIndexes(refKeys: object, key: string | null, collection: any): Promise‹void›

Parameters:

refKeys: object

Name Type
add string[]
remove string[]

key: string | null

collection: any

Returns: Promise‹void›


# Const validate

validate(data: any, schema: Schema | SchemaDef, options: CastOptions): 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"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

Parameters:

Name Type Default Description
data any - that is going to be validated
schema Schema | SchemaDef - that will be used to validate
options CastOptions {
strategy: CAST_STRATEGY.THROW,
strict: true,
skip: [],

} | - |

Returns: any


# Const validateDelimiter

validateDelimiter(delimiter: string): void

Parameters:

Name Type
delimiter string

Returns: void


# Const validateMaxDate

validateMaxDate(value: Date, max: Date | DateOption, property: string): string | void

Parameters:

Name Type
value Date
max Date | DateOption
property string

Returns: string | void


# Const validateMaxLimit

validateMaxLimit(val: number, max: number | MinmaxOption | undefined, property: string): string | void

Parameters:

Name Type
val number
max number | MinmaxOption | undefined
property string

Returns: string | void


# Const validateMinDate

validateMinDate(value: Date, min: Date | DateOption, property: string): string | void

Parameters:

Name Type
value Date
min Date | DateOption
property string

Returns: string | void


# Const validateMinLimit

validateMinLimit(val: number, min: number | MinmaxOption | undefined, property: string): string | void

Parameters:

Name Type
val number
min number | MinmaxOption | undefined
property string

Returns: string | void


# Const verifyWhereObjectKey

verifyWhereObjectKey(clause: LogicalWhereExpr): boolean

Parameters:

Name Type
clause LogicalWhereExpr

Returns: boolean

# Object literals

# Const AggDict

#AggDict: object

Dictionary for handling aggregation functions.

# $arrayAgg

$arrayAgg: string = "ARRAY_AGG"

# $avg

$avg: string = "AVG"

# $count

$count: string = "COUNT"

# $countn

$countn: string = "COUNTN"

# $max

$max: string = "MAX"

# $mean

$mean: string = "MEAN"

# $median

$median: string = "MEDIAN"

# $min

$min: string = "MIN"

# $stddev

$stddev: string = "STDDEV"

# $stddevPop

$stddevPop: string = "STDDEV_POP"

# $stddevSamp

$stddevSamp: string = "STDDEV_SAMP"

# $sum

$sum: string = "SUM"

# $varPop

$varPop: string = "VAR_POP"

# $varSamp

$varSamp: string = "VAR_SAMP"

# $variance

$variance: string = "VARIANCE"

# $variancePop

$variancePop: string = "VARIANCE_POP"

# $varianceSamp

$varianceSamp: string = "VARIANCE_SAMP"


# Const CollectionDeepSearchOperatorDict

#CollectionDeepSearchOperatorDict: object

Dictionary for handling collection ( [NOT] IN | WITHIN ) operators.

# $in

$in: string = "IN"

# $notIn

$notIn: string = "NOT IN"

# $notWithin

$notWithin: string = "NOT WITHIN"

# $within

$within: string = "WITHIN"


# Const CollectionRangePredicateOperatorDict

#CollectionRangePredicateOperatorDict: object

Dictionary for handling collection of range predicates operators.

# $any

$any: string = "ANY"

# $every

$every: string = "EVERY"


# Const CollectionSatisfiesOperatorDict

#CollectionSatisfiesOperatorDict: object

Dictionary for handling collection Satisfies operators.

# $satisfies

$satisfies: string = "SATISFIES"


# Const ComparisonEmptyOperatorDict

#ComparisonEmptyOperatorDict: object

Dictionary for handling Boolean comparison operators.

# $isMissing

$isMissing: string = "IS MISSING"

# $isNotMissing

$isNotMissing: string = "IS NOT MISSING"

# $isNotNull

$isNotNull: string = "IS NOT NULL"

# $isNotValued

$isNotValued: string = "IS NOT VALUED"

# $isNull

$isNull: string = "IS NULL"

# $isValued

$isValued: string = "IS VALUED"


# Const ComparisonMultipleOperatorDict

#ComparisonMultipleOperatorDict: object

Dictionary for handling Range comparison operators.

# $btw

$btw: string = "BETWEEN"

# $notBtw

$notBtw: string = "NOT BETWEEN"


# Const ComparisonSingleOperatorDict

#ComparisonSingleOperatorDict: object

Dictionary for handling Numeric comparison operators.

# $eq

$eq: string = "="

# $gt

$gt: string = ">"

# $gte

$gte: string = ">="

# $lt

$lt: string = "<"

# $lte

$lte: string = "<="

# $neq

$neq: string = "!="


# Const ComparisonSingleStringOperatorDict

#ComparisonSingleStringOperatorDict: object

Dictionary for handling String comparison operators.

# $like

$like: string = "LIKE"

# $notLike

$notLike: string = "NOT LIKE"


# Const LogicalOperatorDict

#LogicalOperatorDict: object

Dictionary for handling Logical operators.

# $and

$and: string = "AND"

# $not

$not: string = "NOT"

# $or

$or: string = "OR"


# Const ResultExprDict

#ResultExprDict: object

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

# $element

$element: string = "ELEMENT"

# $raw

$raw: string = "RAW"

# $value

$value: string = "VALUE"


# Const ReturnResultDict

#ReturnResultDict: object

Dictionary for handling result expressions of ALL | DISTINCT type.

# $all

$all: string = "ALL"

# $distinct

$distinct: string = "DISTINCT"