Socket
Socket
Sign inDemoInstall

aerospike

Package Overview
Dependencies
Maintainers
3
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aerospike - npm Package Compare versions

Comparing version 3.11.0 to 3.12.0

lib/cdt_context.js

8

benchmarks/main.js

@@ -189,6 +189,6 @@ // *****************************************************************************

stats.interval({
'read': intervalStats[0],
'write': intervalStats[1],
'query': intervalStats[2],
'scan': intervalStats[3]
read: intervalStats[0],
write: intervalStats[1],
query: intervalStats[2],
scan: intervalStats[3]
})

@@ -195,0 +195,0 @@ if (!argv.silent) {

@@ -23,17 +23,17 @@ // *****************************************************************************

var TABLE_CHARS = {
'top': '',
top: '',
'top-mid': '',
'top-left': '',
'top-right': '',
'bottom': '',
bottom: '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
'left': '',
left: '',
'left-mid': '',
'mid': '',
mid: '',
'mid-mid': '',
'right': '',
right: '',
'right-mid': '',
'middle': ''
middle: ''
}

@@ -44,5 +44,5 @@

'padding-right': 0,
'head': ['blue'],
'border': ['grey'],
'compact': true
head: ['blue'],
border: ['grey'],
compact: true
}

@@ -49,0 +49,0 @@

@@ -29,6 +29,6 @@ {

"cli-table": "^0.3.1",
"winston": "^2.4.0",
"yargs": "^10.1.1"
"winston": "^3.2.1",
"yargs": "^14.0.0"
},
"main": "main.js"
}

@@ -42,17 +42,17 @@ // *****************************************************************************

const TABLE_CHARS = {
'top': '',
top: '',
'top-mid': '',
'top-left': '',
'top-right': '',
'bottom': '',
bottom: '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
'left': '',
left: '',
'left-mid': '',
'mid': '',
mid: '',
'mid-mid': '',
'right': '',
right: '',
'right-mid': '',
'middle': ''
middle: ''
}

@@ -63,5 +63,5 @@

'padding-right': 0,
'head': ['blue'],
'border': ['grey'],
'compact': true
head: ['blue'],
border: ['grey'],
compact: true
}

@@ -101,3 +101,3 @@

.map(op => {
let elapsed = op[OPERATION_TIME_DIFF]
const elapsed = op[OPERATION_TIME_DIFF]
return Math.floor(duration(elapsed))

@@ -145,6 +145,7 @@ })

function calculateTPS (transactions) {
var seconds = totalDuration / 1000
Object.keys(transactions).forEach(function (stat) {
transactions[stat]['tps'] = transactions[stat]['count'] / seconds
})
const seconds = totalDuration / 1000
for (const key in transactions) {
const stat = transactions[key]
stat.tps = stat.count / seconds
}
}

@@ -175,3 +176,3 @@

envTable.push({ 'Node.js Version': process.versions.node })
envTable.push({ 'UV_THREADPOOL_SIZE': process.env.UV_THREADPOOL_SIZE || '-' })
envTable.push({ UV_THREADPOOL_SIZE: process.env.UV_THREADPOOL_SIZE || '-' })

@@ -187,7 +188,7 @@ printTable(envTable, print, prefix)

configTable.push({ 'operations': config.operations })
configTable.push({ 'iterations': config.iterations === undefined ? 'undefined' : config.iterations })
configTable.push({ 'processes': config.processes })
configTable.push({ 'promises': !!config.promises })
configTable.push({ 'time': config.time === undefined ? 'undefined' : timeUnits(config.time) })
configTable.push({ operations: config.operations })
configTable.push({ iterations: config.iterations === undefined ? 'undefined' : config.iterations })
configTable.push({ processes: config.processes })
configTable.push({ promises: !!config.promises })
configTable.push({ time: config.time === undefined ? 'undefined' : timeUnits(config.time) })

@@ -209,23 +210,15 @@ printTable(configTable, print, prefix)

})
var columns = Object.keys(transactions)
const columns = Object.keys(transactions).map(key => transactions[key])
var row = columns.map(function (col) {
return numberFormat(transactions[col]['count'], 0)
})
table.push({ 'Total': row })
const totals = columns.map(col => numberFormat(col.count, 0))
table.push({ Total: totals })
row = columns.map(function (col) {
return numberFormat(transactions[col]['tps'], 0)
})
table.push({ 'TPS': row })
const avgTps = columns.map(col => numberFormat(col.tps, 0))
table.push({ TPS: avgTps })
row = columns.map(function (col) {
return numberFormat(transactions[col]['min_tps'], 0)
})
table.push({ 'Min TPS': row })
const minTps = columns.map(col => numberFormat(col.min_tps, 0))
table.push({ 'Min TPS': minTps })
row = columns.map(function (col) {
return numberFormat(transactions[col]['max_tps'], 0)
})
table.push({ 'Max TPS': row })
const maxTps = columns.map(col => numberFormat(col.max_tps, 0))
table.push({ 'Max TPS': maxTps })

@@ -264,3 +257,3 @@ printTable(table, print, prefix)

function stop () {
let elapsed = process.hrtime(startTime)
const elapsed = process.hrtime(startTime)
totalDuration = duration(elapsed)

@@ -276,5 +269,5 @@ }

var stats = trans[statName] = trans[statName] || { count: 0, max_tps: 0, min_tps: Infinity }
stats['count'] += tx
if (tx > stats['max_tps']) stats['max_tps'] = tx
if (tx < stats['min_tps']) stats['min_tps'] = tx
stats.count += tx
if (tx > stats.max_tps) stats.max_tps = tx
if (tx < stats.min_tps) stats.min_tps = tx
}

@@ -317,3 +310,3 @@

nodejs: process.versions.node,
'UV_THREADPOOL_SIZE': process.env.UV_THREADPOOL_SIZE || null
UV_THREADPOOL_SIZE: process.env.UV_THREADPOOL_SIZE || null
},

@@ -320,0 +313,0 @@ configuration: {

@@ -74,6 +74,6 @@ // *****************************************************************************

let defaultPolicy = {
const defaultPolicy = {
totalTimeout: argv.timeout
}
let config = {
const config = {
policies: {

@@ -165,5 +165,5 @@ read: defaultPolicy,

function get (key, done) {
let timeStart = process.hrtime()
const timeStart = process.hrtime()
client.get(key, function (error) {
let status = (error && error.code) || 0
const status = (error && error.code) || 0
done(status, process.hrtime(timeStart), READ)

@@ -174,3 +174,3 @@ })

function getPromise (key, done) {
let timeStart = process.hrtime()
const timeStart = process.hrtime()
client.get(key)

@@ -187,5 +187,5 @@ .then(() => done(0, process.hrtime(timeStart), READ))

function put (options, done) {
let timeStart = process.hrtime()
const timeStart = process.hrtime()
client.put(options.key, options.record, metadata, function (error) {
let status = (error && error.code) || 0
const status = (error && error.code) || 0
done(status, process.hrtime(timeStart), WRITE)

@@ -196,3 +196,3 @@ })

function putPromise (options, done) {
let timeStart = process.hrtime()
const timeStart = process.hrtime()
client.put(options.key, options.record, metadata)

@@ -199,0 +199,0 @@ .then(() => done(0, process.hrtime(timeStart), WRITE))

@@ -7,2 +7,13 @@ # Changelog

## [3.12.0] - 2019-08-31
* **New Features**
* Support for operations on nested lists & maps. Requires server version 4.6 or later. [#307](https://github.com/aerospike/aerospike-client-nodejs/pull/307)
* **Updates**
* Update C client library to [v4.6.7](http://www.aerospike.com/download/client/c/notes.html#4.6.7).
* Support Debian 10. Drop support for Debian 7.
* Fix tests for certain out-of-bounds list operations due to changed error code sent by server v4.6.
* Update dev dependecies: standard v14, yargs v14, nyc
## [3.11.0] - 2019-05-22

@@ -9,0 +20,0 @@

#!/usr/bin/env node
// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -25,3 +25,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

const batch = argv.keys.map(key => {
let request = {
const request = {
key: new Aerospike.Key(argv.namespace, argv.set, key)

@@ -39,4 +39,4 @@ }

for (let result of batchResults) {
let record = result.record
for (const result of batchResults) {
const record = result.record
console.info(record.key.key, ':', result.status === Aerospike.status.OK

@@ -51,3 +51,3 @@ ? record.bins : 'NOT FOUND')

exports.builder = {
'bins': {
bins: {
describe: 'List of bins to fetch for each record',

@@ -54,0 +54,0 @@ type: 'array',

#!/usr/bin/env node
// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -34,3 +34,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

async function infoAny (client, request) {
let response = await client.infoAny(request)
const response = await client.infoAny(request)
if (response) {

@@ -44,3 +44,3 @@ console.info(response.trim())

async function infoAll (client, request) {
let responses = await client.infoAll(request)
const responses = await client.infoAll(request)
if (responses.some((response) => response.info)) {

@@ -57,3 +57,3 @@ responses.map((response) => {

async function infoHost (client, request, host) {
let response = await client.info(request, host)
const response = await client.info(request, host)
if (response) {

@@ -70,3 +70,3 @@ console.info(response.trim())

exports.builder = {
'any': {
any: {
describe: 'Send request to a single, randomly selected cluster node',

@@ -77,3 +77,3 @@ type: 'boolean',

},
'all': {
all: {
describe: 'Send request to all cluster nodes',

@@ -84,3 +84,3 @@ type: 'boolean',

},
'addr': {
addr: {
describe: 'Send request to specified cluster node',

@@ -87,0 +87,0 @@ type: 'string',

#!/usr/bin/env node
// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -28,3 +28,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

const i = shared.random.int(1, 10)
let ops = [
const ops = [
lists.append('values', i),

@@ -31,0 +31,0 @@ op.read('values'),

@@ -15,4 +15,4 @@ {

"aerospike": "file:..",
"yargs": "^12.0.1"
"yargs": "^14.0.0"
}
}
#!/usr/bin/env node
// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -33,3 +33,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

function buildMeta (argv) {
let meta = { }
const meta = { }
if (argv.ttl) {

@@ -42,3 +42,3 @@ meta.ttl = argv.ttl

function buildPolicy (argv) {
let policy = { }
const policy = { }
if (argv.create) {

@@ -66,3 +66,3 @@ policy.exists = Aerospike.policy.exists.CREATE

},
'create': {
create: {
describe: 'Create a new record',

@@ -73,3 +73,3 @@ group: 'Command:',

},
'replace': {
replace: {
describe: 'Replace an existing record',

@@ -80,3 +80,3 @@ group: 'Command:',

},
'update': {
update: {
describe: 'Update an existing record',

@@ -83,0 +83,0 @@ group: 'Command:',

#!/usr/bin/env node
// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -56,3 +56,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

let udf = {}
const udf = {}
udf.module = argv.udf.shift()

@@ -69,3 +69,3 @@ udf.func = argv.udf.shift()

let udf = udfParams(argv)
const udf = udfParams(argv)
if (udf && argv.background) {

@@ -87,3 +87,3 @@ await queryBackground(query, udf)

async function queryBackground (query, udf) {
let job = await query.background(udf.module, udf.func, udf.args)
const job = await query.background(udf.module, udf.func, udf.args)
console.info('Running query in background - Job ID:', job.jobID)

@@ -93,3 +93,3 @@ }

async function queryApply (query, udf) {
let result = await query.apply(udf.module, udf.func, udf.args)
const result = await query.apply(udf.module, udf.func, udf.args)
console.info('Query result:', result)

@@ -102,3 +102,3 @@ }

exports.builder = {
'bins': {
bins: {
describe: 'List of bins to fetch for each record',

@@ -108,3 +108,3 @@ type: 'array',

},
'equal': {
equal: {
desc: 'Applies an equal filter to the query',

@@ -115,3 +115,3 @@ group: 'Command:',

},
'range': {
range: {
desc: 'Applies a range filter to the query',

@@ -122,3 +122,3 @@ group: 'Command:',

},
'geoWithinRadius': {
geoWithinRadius: {
desc: 'Applies a geospatial "within-radius" filter to the query',

@@ -129,3 +129,3 @@ group: 'Command:',

},
'udf': {
udf: {
desc: 'UDF module, function & arguments to apply to the query',

@@ -135,3 +135,3 @@ group: 'Command:',

},
'background': {
background: {
desc: 'Run the query in the background (with Record UDF)',

@@ -138,0 +138,0 @@ group: 'Command:',

#!/usr/bin/env node
// *****************************************************************************
// Copyright 2018 Aerospike, Inc.
// Copyright 2018-2019 Aerospike, Inc.
//

@@ -21,3 +21,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

const VERSION = require('../package.json')['version']
const VERSION = require('../package.json').version
const commands = [

@@ -24,0 +24,0 @@ 'add',

#!/usr/bin/env node
// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -28,3 +28,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

let udf = {}
const udf = {}
udf.module = argv.udf.shift()

@@ -37,3 +37,3 @@ udf.func = argv.udf.shift()

function buildScanOptions (argv) {
let options = {
const options = {
percent: argv.percent,

@@ -67,3 +67,3 @@ concurrent: argv.concurrent

async function scan (client, argv) {
let options = buildScanOptions(argv)
const options = buildScanOptions(argv)
const scan = client.scan(argv.namespace, argv.set, options)

@@ -74,3 +74,3 @@ if (argv.bins) {

let udf = udfParams(argv)
const udf = udfParams(argv)
if (udf && argv.background) {

@@ -90,3 +90,3 @@ await scanBackground(scan, udf)

async function scanBackground (query, udf) {
let job = await scan.background(udf.module, udf.func, udf.args)
const job = await scan.background(udf.module, udf.func, udf.args)
console.info('Running scan in background - Job ID:', job.jobID)

@@ -99,3 +99,3 @@ }

exports.builder = {
'bins': {
bins: {
describe: 'List of bins to fetch for each record',

@@ -105,3 +105,3 @@ type: 'array',

},
'priority': {
priority: {
describe: 'Scan priority',

@@ -111,3 +111,3 @@ choices: ['auto', 'low', 'medium', 'high'],

},
'percent': {
percent: {
describe: 'Run scan on given percentage of records',

@@ -118,3 +118,3 @@ type: 'number',

},
'concurrent': {
concurrent: {
describe: 'Scan all cluster nodes in parallel',

@@ -125,3 +125,3 @@ type: 'boolean',

},
'udf': {
udf: {
desc: 'UDF module, function & arguments to apply to the query',

@@ -131,3 +131,3 @@ group: 'Command:',

},
'background': {
background: {
desc: 'Run the scan in the background (with Record UDF)',

@@ -134,0 +134,0 @@ group: 'Command:',

@@ -26,3 +26,3 @@ // *****************************************************************************

return binStrs.reduce((bins, current) => {
let [name, value] = current.split('=')
const [name, value] = current.split('=')
bins[name] = str2num(value)

@@ -34,4 +34,4 @@ return bins

exports.printRecord = function (record) {
let key = record.key.key || record.key.digest.toString('hex')
const key = record.key.key || record.key.digest.toString('hex')
console.info('%s: %s', key, util.inspect(record.bins))
}

@@ -31,3 +31,3 @@ // *****************************************************************************

function defaultConfig (argv) {
let defaultPolicy = {
const defaultPolicy = {
totalTimeout: argv.timeout

@@ -34,0 +34,0 @@ }

@@ -35,5 +35,5 @@ // *****************************************************************************

let example = process.argv[1]
let runner = path.join(example, '../run.js')
let cmd = path.basename(example, '.js')
const example = process.argv[1]
const runner = path.join(example, '../run.js')
const cmd = path.basename(example, '.js')

@@ -40,0 +40,0 @@ process.argv.splice(1, 1, runner, cmd)

#!/usr/bin/env node
// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -66,3 +66,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

builder: {
'type': {
type: {
choices: ['numeric', 'string', 'geo2dsphere'],

@@ -69,0 +69,0 @@ hidden: true

#!/usr/bin/env node
// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -24,4 +24,4 @@ // Licensed under the Apache License, Version 2.0 (the "License")

async function udfRegister (client, argv) {
let module = argv.module
let job = await client.udfRegister(module)
const module = argv.module
const job = await client.udfRegister(module)
await job.waitUntilDone()

@@ -32,4 +32,4 @@ console.info('UDF module registered successfully')

async function udfRemove (client, argv) {
let module = path.basename(argv.module)
let job = await client.udfRemove(module)
const module = path.basename(argv.module)
const job = await client.udfRemove(module)
await job.waitUntilDone()

@@ -36,0 +36,0 @@ console.info('UDF module removed successfully')

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -95,2 +95,12 @@ // Licensed under the Apache License, Version 2.0 (the "License")

/**
* The {@link module:aerospike/cdt|cdt} module provides the {@link CdtContext}
* class for operations on nested lists and maps.
*
* @summary {@link module:aerospike/cdt|aerospike/cdt} module
*/
exports.cdt = {
Context: require('./cdt_context')
}
/**
* The {@link module:aerospike/maps|maps} module defines operations on the Maps

@@ -102,3 +112,3 @@ * complex data type.

*/
let maps = exports.maps = require('./maps')
const maps = exports.maps = require('./maps')
// copy maps related enums into maps module

@@ -124,3 +134,3 @@ Object.keys(as.maps).forEach(key => {

*/
let policy = exports.policy = require('./policy')
const policy = exports.policy = require('./policy')

@@ -428,3 +438,3 @@ // short-cuts to the policy classes defined under the policy module

let Client = exports.Client
const Client = exports.Client

@@ -431,0 +441,0 @@ /**

@@ -282,3 +282,3 @@ // *****************************************************************************

let cmd = new Commands.BatchExists(this, [keys, policy], callback)
const cmd = new Commands.BatchExists(this, [keys, policy], callback)
return cmd.execute()

@@ -336,3 +336,3 @@ }

let cmd = new Commands.BatchGet(this, [keys, policy], callback)
const cmd = new Commands.BatchGet(this, [keys, policy], callback)
return cmd.execute()

@@ -392,3 +392,3 @@ }

let cmd = new Commands.BatchRead(this, [records, policy], callback)
const cmd = new Commands.BatchRead(this, [records, policy], callback)
return cmd.execute()

@@ -448,3 +448,3 @@ }

let cmd = new Commands.BatchSelect(this, [keys, bins, policy], callback)
const cmd = new Commands.BatchSelect(this, [keys, bins, policy], callback)
return cmd.execute()

@@ -531,6 +531,6 @@ }

let eventsCb = eventsCallback.bind(this)
const eventsCb = eventsCallback.bind(this)
this.as_client.setupEventCb(eventsCb)
let cmd = new Commands.Connect(this)
const cmd = new Commands.Connect(this)
return cmd.execute()

@@ -653,3 +653,3 @@ .then(() => {

let args = [
const args = [
options.ns,

@@ -664,3 +664,3 @@ options.set,

let cmd = new Commands.IndexCreate(this, args, callback)
const cmd = new Commands.IndexCreate(this, args, callback)
cmd.convertResult = () => new IndexJob(this, options.ns, options.index)

@@ -872,3 +872,3 @@ return cmd.execute()

let cmd = new Commands.Apply(this, [key, udfArgs, policy], callback)
const cmd = new Commands.Apply(this, [key, udfArgs, policy], callback)
return cmd.execute()

@@ -917,3 +917,3 @@ }

let cmd = new Commands.Exists(this, [key, policy], callback)
const cmd = new Commands.Exists(this, [key, policy], callback)
return cmd.execute()

@@ -954,3 +954,3 @@ }

let cmd = new Commands.Get(this, key, [policy], callback)
const cmd = new Commands.Get(this, key, [policy], callback)
return cmd.execute()

@@ -989,3 +989,3 @@ }

let cmd = new Commands.IndexRemove(this, [namespace, index, policy], callback)
const cmd = new Commands.IndexRemove(this, [namespace, index, policy], callback)
return cmd.execute()

@@ -1038,3 +1038,3 @@ }

let cmd = new Commands.InfoHost(this, [request, host, policy], callback)
const cmd = new Commands.InfoHost(this, [request, host, policy], callback)
return cmd.execute()

@@ -1082,3 +1082,3 @@ }

let cmd = new Commands.InfoAny(this, [request, policy], callback)
const cmd = new Commands.InfoAny(this, [request, policy], callback)
return cmd.execute()

@@ -1129,3 +1129,3 @@ }

let cmd = new Commands.InfoForeach(this, [request, policy], callback)
const cmd = new Commands.InfoForeach(this, [request, policy], callback)
return cmd.execute()

@@ -1168,3 +1168,3 @@ }

let cmd = new Commands.InfoNode(this, [request, node.name, policy], callback)
const cmd = new Commands.InfoNode(this, [request, node.name, policy], callback)
return cmd.execute()

@@ -1242,3 +1242,3 @@ }

let cmd = new Commands.Operate(this, key, [operations, metadata, policy], callback)
const cmd = new Commands.Operate(this, key, [operations, metadata, policy], callback)
return cmd.execute()

@@ -1317,3 +1317,3 @@ }

Client.prototype[op] = function (key, bins, metadata, policy, callback) {
let ops = Object.keys(bins).map(bin => operations[op](bin, bins[bin]))
const ops = Object.keys(bins).map(bin => operations[op](bin, bins[bin]))
return this.operate(key, ops, metadata, policy, callback)

@@ -1387,3 +1387,3 @@ }

let cmd = new Commands.Put(this, key, [bins, meta, policy], callback)
const cmd = new Commands.Put(this, key, [bins, meta, policy], callback)
return cmd.execute()

@@ -1449,3 +1449,3 @@ }

let cmd = new Commands.Remove(this, key, [policy], callback)
const cmd = new Commands.Remove(this, key, [policy], callback)
return cmd.execute()

@@ -1507,3 +1507,3 @@ }

let cmd = new Commands.Select(this, key, [bins, policy], callback)
const cmd = new Commands.Select(this, key, [bins, policy], callback)
return cmd.execute()

@@ -1548,3 +1548,3 @@ }

let cmd = new Commands.Truncate(this, [ns, set, beforeNanos, policy], callback)
const cmd = new Commands.Truncate(this, [ns, set, beforeNanos, policy], callback)
return cmd.execute()

@@ -1609,5 +1609,5 @@ }

let cmd = new Commands.UdfRegister(this, [udfPath, udfType, policy], callback)
const cmd = new Commands.UdfRegister(this, [udfPath, udfType, policy], callback)
cmd.convertResult = () => {
let module = path.basename(udfPath)
const module = path.basename(udfPath)
return new UdfJob(this, module, UdfJob.REGISTER)

@@ -1695,3 +1695,3 @@ }

let cmd = new Commands.UdfRemove(this, [udfModule, policy], callback)
const cmd = new Commands.UdfRemove(this, [udfModule, policy], callback)
cmd.convertResult = () => new UdfJob(this, udfModule, UdfJob.UNREGISTER)

@@ -1698,0 +1698,0 @@ return cmd.execute()

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -34,3 +34,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

return results.map(result => {
let record = new Record(result.key, result.bins, result.meta)
const record = new Record(result.key, result.bins, result.meta)
return new BatchResult(result.status, record)

@@ -37,0 +37,0 @@ })

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -101,4 +101,4 @@ // Licensed under the Apache License, Version 2.0 (the "License")

convertResponse (err, arg1, arg2, arg3) {
let error = this.convertError(err)
let result = this.convertResult(arg1, arg2, arg3)
const error = this.convertError(err)
const result = this.convertResult(arg1, arg2, arg3)
return [error, result]

@@ -163,9 +163,9 @@ }

process (cb) {
let asCallback = (err, arg1, arg2, arg3) => {
let tmp = this.convertResponse(err, arg1, arg2, arg3)
let error = tmp[0]
let result = tmp[1]
const asCallback = (err, arg1, arg2, arg3) => {
const tmp = this.convertResponse(err, arg1, arg2, arg3)
const error = tmp[0]
const result = tmp[1]
return cb(error, result)
}
let asArgs = this.args.concat([asCallback])
const asArgs = this.args.concat([asCallback])
this.client.asExec(this.asCommand(), asArgs)

@@ -176,3 +176,3 @@ }

sendError (message) {
let error = new AerospikeError(message, this)
const error = new AerospikeError(message, this)
if (this.expectsPromise()) {

@@ -179,0 +179,0 @@ return Promise.reject(error)

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -4,0 +4,0 @@ // Licensed under the Apache License, Version 2.0 (the "License")

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -44,5 +44,5 @@ // Licensed under the Apache License, Version 2.0 (the "License")

if (!bins) return EndOfStream
let key = Key.fromASKey(asKey)
const key = Key.fromASKey(asKey)
return new Record(key, bins, meta)
}
}
// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -487,4 +487,4 @@ // Licensed under the Apache License, Version 2.0 (the "License")

setDefaultPolicies (policies) {
for (let type in policies) {
let values = policies[type]
for (const type in policies) {
const values = policies[type]
this.policies[type] = policy.createPolicy(type, values)

@@ -501,3 +501,3 @@ }

[inspect] () {
let copy = Object.assign({}, this)
const copy = Object.assign({}, this)
if (this.password !== undefined) {

@@ -504,0 +504,0 @@ Object.assign(copy, { password: '[FILTERED]' })

@@ -112,4 +112,4 @@ // *****************************************************************************

} else {
let message = this.formatMessage(asError.message, asError.code)
let error = new AerospikeError(message, command)
const message = this.formatMessage(asError.message, asError.code)
const error = new AerospikeError(message, command)
this.copyASErrorProperties(error, asError)

@@ -139,3 +139,3 @@ return error

setStackTrace (stack) {
let firstLine = `${this.name}: ${this.message}`
const firstLine = `${this.name}: ${this.message}`
stack = stack.replace(/^.*$/m, firstLine)

@@ -142,0 +142,0 @@ Object.defineProperty(this, 'stack', { value: stack })

// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -49,3 +49,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

/**
* @class SindexFilterPredicate
* @class module:aerospike/filter~SindexFilterPredicate
* @classdesc Secondary index filter predicate to limit the scope of a {@link Query}.

@@ -132,3 +132,3 @@ *

exports.range = function (bin, min, max, indexType) {
let dataType = as.indexDataType.NUMERIC
const dataType = as.indexDataType.NUMERIC
return new RangePredicate(bin, min, max, dataType, indexType)

@@ -148,3 +148,3 @@ }

exports.equal = function (bin, value) {
let dataType = dataTypeOf(value)
const dataType = dataTypeOf(value)
return new EqualPredicate(bin, value, dataType)

@@ -169,3 +169,3 @@ }

exports.contains = function (bin, value, indexType) {
let dataType = dataTypeOf(value)
const dataType = dataTypeOf(value)
return new EqualPredicate(bin, value, dataType, indexType)

@@ -243,3 +243,3 @@ }

exports.geoWithinRadius = function (bin, lon, lat, radius, indexType) {
let circle = GeoJSON.Circle(lon, lat, radius)
const circle = GeoJSON.Circle(lon, lat, radius)
return new GeoPredicate(bin, circle.toString(), indexType)

@@ -266,4 +266,4 @@ }

exports.geoContainsPoint = function (bin, lon, lat, indexType) {
let point = GeoJSON.Point(lon, lat)
const point = GeoJSON.Point(lon, lat)
return new GeoPredicate(bin, point.toString(), indexType)
}
// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -76,3 +76,3 @@ // Licensed under the Apache License, Version 2.0 (the 'License')

return sindexInfo.every(info => info['load_pct'] === 100)
return sindexInfo.every(info => info.load_pct === 100)
}

@@ -86,3 +86,3 @@

IndexJob.prototype.info = function () {
let sindex = 'sindex/' + this.namespace + '/' + this.indexName
const sindex = 'sindex/' + this.namespace + '/' + this.indexName
return this.client.infoAll(sindex)

@@ -89,0 +89,0 @@ .catch(error => {

// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -70,6 +70,6 @@ // Licensed under the Apache License, Version 2.0 (the 'License')

if (!info) return {}
let infoHash = parseKeyValue(info, '\n', '\t')
const infoHash = parseKeyValue(info, '\n', '\t')
Object.keys(infoHash).forEach(key => {
let separators = getSeparators(key)
let value = infoHash[key]
const separators = getSeparators(key)
const value = infoHash[key]
infoHash[key] = deepSplitString(value, separators)

@@ -148,3 +148,3 @@ })

function getSeparators (key) {
let pattern = Object.keys(separators).find(p => minimatch(key, p))
const pattern = Object.keys(separators).find(p => minimatch(key, p))
const seps = separators[pattern] || defaultSeparators

@@ -197,3 +197,3 @@ return seps.slice() // return a copy of the array

} else {
let list = input.split(sep)
const list = input.split(sep)
if (list[list.length - 1].length === 0) {

@@ -217,8 +217,8 @@ list.pop()

*/
let separators = {
'bins': [';:', splitBins],
const separators = {
bins: [';:', splitBins],
'bins/*': [splitBins],
'namespace/*': [';='],
'service': [';'],
'sindex': [';', ':='],
service: [';'],
sindex: [';', ':='],
'sindex/*': [';', ':='],

@@ -228,3 +228,3 @@ 'sindex/*/**': [';='],

'get-dc-config': [';', ':='],
'sets': [';', ':='],
sets: [';', ':='],
'sets/*': [';', ':='],

@@ -234,3 +234,3 @@ 'sets/*/**': [chop, ':='] // remove trailing ';' to return single object rather than list of objects

let defaultSeparators = [smartParse]
const defaultSeparators = [smartParse]

@@ -237,0 +237,0 @@ /**********************************************************

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -54,3 +54,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

let timer = null
let poll = function () {
const poll = function () {
statusFunction()

@@ -133,3 +133,3 @@ .then(done => {

let cmd = new Commands.JobInfo(this.client, [this.jobID, this.module, policy], callback)
const cmd = new Commands.JobInfo(this.client, [this.jobID, this.module, policy], callback)
return cmd.execute()

@@ -136,0 +136,0 @@ }

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -53,8 +53,9 @@ // Licensed under the Apache License, Version 2.0 (the "License")

const opcodes = as.operations
const Context = require('./cdt_context')
const AerospikeError = require('./error')
/**
* @summary List operation
* @class module:aerospike/lists~ListOperation
*
* @description Use the methods in the {@link module:aerospike/lists|lists}
* @classdesc Use the methods in the {@link module:aerospike/lists|lists}
* module to create list operations for use with the {@link Client#operate}

@@ -107,2 +108,60 @@ * command.

/**
* @summary By setting the context, the list operation will be executed on a
* nested list, instead of the bin value itself.
*
* @param { CdtContext | function } context - Either a Context object, or a
* function which accepts a Context object.
* @returns { ListOperation } The list operation itself.
*
* @since v3.12.0
*
* @example <caption>Fetch the 1st element of the 2nd nested list</caption>
*
* const Aerospike = require('aerospike')
* const lists = Aerospike.lists
* const key = new Aerospike.Key('test', 'demo', 'listsTest')
*
* Aerospike.connect().then(async (client) => {
* await client.put(key, { list: [[32, 5, 85], [16, 22]] })
* const ops = [
* lists.get('list', 0)
* .withContext((ctx) => ctx.addListIndex(1))
* ]
* const result = await client.operate(key, ops)
* console.info('Result:', result.bins.list) // => Result: 16
* client.close()
* })
*
* @example <caption>Fetch the last element of the nested list stored under the 'nested' map key</caption>
*
* const Aerospike = require('aerospike')
* const lists = Aerospike.lists
* const Context = Aerospike.cdt.Context
* const key = new Aerospike.Key('test', 'demo', 'listsTest')
*
* Aerospike.connect().then(async (client) => {
* await client.put(key, { map: { nested: [32, 5, 85, 16, 22] } })
* const context = new Context().addMapKey('nested')
* const ops = [
* lists.get('map', -1)
* .withContext(context)
* ]
* const result = await client.operate(key, ops)
* console.info('Result:', result.bins.map) // => Result: 22
* client.close()
* })
*/
withContext (contextOrFunction) {
if (contextOrFunction instanceof Context) {
this.context = contextOrFunction
} else if (typeof contextOrFunction === 'function') {
this.context = new Context()
contextOrFunction(this.context)
} else {
throw new AerospikeError('Context param must be a CDT Context or a function that accepts a context')
}
return this
}
/**
* @summary Inverts the selection of items for certain list operations.

@@ -905,2 +964,3 @@ * @description For <code>getBy\*</code> and <code>removeBy\*</code> list

* @param {any} value - The new value to assigned to the list element.
* @param {ListPolicy} [policy] - Optional list policy.
* @returns {Object} Operation that can be passed to the {@link Client#operate} command.

@@ -933,7 +993,4 @@ *

*/
exports.set = function (bin, index, value) {
var op = new ListOperation(opcodes.LIST_SET, bin)
op.index = index
op.value = value
return op
exports.set = function (bin, index, value, policy) {
return new ListOperation(opcodes.LIST_SET, bin, { index, value, policy })
}

@@ -940,0 +997,0 @@

// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -22,2 +22,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

const policy = require('./policy')
const Context = require('./cdt_context')

@@ -103,5 +104,5 @@ /**

/**
* @summary Map operation
* @class module:aerospike/maps~MapOperation
*
* @description Use the methods in the {@link module:aerospike/maps|maps}
* @classdesc Use the methods in the {@link module:aerospike/maps|maps}
* module to create map operations for use with the {@link Client#operate}

@@ -153,2 +154,60 @@ * command.

}
/**
* @summary By setting the context, the map operation will be executed on a
* nested map, instead of the bin value itself.
*
* @param { CdtContext | function } context - Either a CdtContext object, or a
* function which accepts a CdtContext object.
* @returns { MapOperation } The map operation itself.
*
* @since v3.12.0
*
* @example <caption>Fetch the value with the key 'b' from the 2nd nested map</caption>
*
* const Aerospike = require('aerospike')
* const maps = Aerospike.maps
* const key = new Aerospike.Key('test', 'demo', 'mapsTest')
*
* Aerospike.connect().then(async (client) => {
* await client.put(key, { maps: [{ a: 1, b: 2 }, { b: 3, c: 4 }] })
* const ops = [
* maps.getByKey('maps', 'b')
* .withContext((ctx) => ctx.addListIndex(1))
* .andReturn(maps.returnType.VALUE)
* ]
* const result = await client.operate(key, ops)
* console.info('Result:', result.bins.maps) // => Result: 3
* client.close()
* })
*
* @example <caption>Fetch the value with the key 'b' from the nested map under the key 'alpha'</caption>
*
* const Aerospike = require('./')
* const maps = Aerospike.maps
* const Context = Aerospike.cdt.Context
* const key = new Aerospike.Key('test', 'demo', 'listsTest')
*
* Aerospike.connect().then(async (client) => {
* await client.put(key, { maps: { alpha: { a: 1, b: 2 }, beta: { b: 3, c: 4 } } })
* const context = new Context().addMapKey('alpha')
* const ops = [
* maps.getByKey('maps', 'b')
* .withContext(context)
* .andReturn(maps.returnType.VALUE)
* ]
* const result = await client.operate(key, ops)
* console.info('Result:', result.bins.maps) // => Result: 2
* client.close()
* })
*/
withContext (contextOrFunction) {
if (typeof contextOrFunction === 'object') {
this.context = contextOrFunction
} else if (typeof contextOrFunction === 'function') {
this.context = new Context()
contextOrFunction(this.context)
}
return this
}
}

@@ -155,0 +214,0 @@

@@ -51,3 +51,3 @@ // *****************************************************************************

*/
this.socketTimeout = props['socketTimeout']
this.socketTimeout = props.socketTimeout

@@ -70,5 +70,5 @@ /**

*/
this.totalTimeout = props['totalTimeout']
this.totalTimeout = props.totalTimeout
if (this.totalTimeout === undefined) {
this.totalTimeout = props['timeout']
this.totalTimeout = props.timeout
}

@@ -92,3 +92,3 @@

*/
this.maxRetries = props['maxRetries']
this.maxRetries = props.maxRetries
}

@@ -95,0 +95,0 @@ }

@@ -95,3 +95,3 @@ // *****************************************************************************

*/
this.maxCommandsInProcess = props['maxCommandsInProcess']
this.maxCommandsInProcess = props.maxCommandsInProcess

@@ -115,3 +115,3 @@ /**

*/
this.maxCommandsInQueue = props['maxCommandsInQueue']
this.maxCommandsInQueue = props.maxCommandsInQueue

@@ -125,3 +125,3 @@ /**

*/
this.queueInitialCapacity = props['queueInitialCapacity']
this.queueInitialCapacity = props.queueInitialCapacity
}

@@ -128,0 +128,0 @@ }

@@ -41,5 +41,5 @@ // *****************************************************************************

*/
this.totalTimeout = props['totalTimeout']
this.totalTimeout = props.totalTimeout
if (this.totalTimeout === undefined) {
this.totalTimeout = props['timeout']
this.totalTimeout = props.timeout
}

@@ -52,3 +52,3 @@

*/
this.sendAsIs = props['sendAsIs']
this.sendAsIs = props.sendAsIs

@@ -60,3 +60,3 @@ /**

*/
this.checkBounds = props['checkBounds']
this.checkBounds = props.checkBounds
}

@@ -63,0 +63,0 @@ }

@@ -40,3 +40,3 @@ // *****************************************************************************

*/
this.order = props['order']
this.order = props.order

@@ -50,3 +50,3 @@ /**

*/
this.writeFlags = props['writeFlags']
this.writeFlags = props.writeFlags
}

@@ -53,0 +53,0 @@ }

@@ -40,3 +40,3 @@ // *****************************************************************************

*/
this.order = props['order']
this.order = props.order

@@ -55,3 +55,3 @@ /**

*/
this.writeMode = props['writeMode']
this.writeMode = props.writeMode

@@ -69,3 +69,3 @@ /**

*/
this.writeFlags = props['writeFlags']
this.writeFlags = props.writeFlags
}

@@ -72,0 +72,0 @@ }

// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -4,0 +4,0 @@ // Licensed under the Apache License, Version 2.0 (the "License")

@@ -21,14 +21,14 @@ // *****************************************************************************

let ApplyPolicy = require('./policies/apply_policy')
let BatchPolicy = require('./policies/batch_policy')
let CommandQueuePolicy = require('./policies/command_queue_policy')
let InfoPolicy = require('./policies/info_policy')
let ListPolicy = require('./policies/list_policy')
let MapPolicy = require('./policies/map_policy')
let OperatePolicy = require('./policies/operate_policy')
let QueryPolicy = require('./policies/query_policy')
let ReadPolicy = require('./policies/read_policy')
let RemovePolicy = require('./policies/remove_policy')
let ScanPolicy = require('./policies/scan_policy')
let WritePolicy = require('./policies/write_policy')
const ApplyPolicy = require('./policies/apply_policy')
const BatchPolicy = require('./policies/batch_policy')
const CommandQueuePolicy = require('./policies/command_queue_policy')
const InfoPolicy = require('./policies/info_policy')
const ListPolicy = require('./policies/list_policy')
const MapPolicy = require('./policies/map_policy')
const OperatePolicy = require('./policies/operate_policy')
const QueryPolicy = require('./policies/query_policy')
const ReadPolicy = require('./policies/read_policy')
const RemovePolicy = require('./policies/remove_policy')
const ScanPolicy = require('./policies/scan_policy')
const WritePolicy = require('./policies/write_policy')

@@ -352,3 +352,3 @@ /**

}
let Klass = policyClass(type)
const Klass = policyClass(type)
if (values instanceof Klass) {

@@ -355,0 +355,0 @@ return values

@@ -41,3 +41,3 @@ // *****************************************************************************

/**
* @class PredicateExpression
* @class module:aerospike/predexp~PredicateExpression
*

@@ -44,0 +44,0 @@ * Sequences of predicate expressions are used limit the results of query

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -416,3 +416,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

Query.prototype.foreach = function (policy, dataCb, errorCb, endCb) {
let stream = new RecordStream(this.client)
const stream = new RecordStream(this.client)
if (dataCb) stream.on('data', dataCb)

@@ -422,3 +422,3 @@ if (errorCb) stream.on('error', errorCb)

let args = [this.ns, this.set, this, policy]
const args = [this.ns, this.set, this, policy]
let cmd

@@ -452,4 +452,4 @@ if (this.udf) {

return new Promise((resolve, reject) => {
let stream = this.foreach(policy)
let results = []
const stream = this.foreach(policy)
const results = []
stream.on('error', reject)

@@ -492,3 +492,3 @@ stream.on('end', () => resolve(results))

let cmd = new Commands.QueryApply(this.client, [this.ns, this.set, this, policy], callback)
const cmd = new Commands.QueryApply(this.client, [this.ns, this.set, this, policy], callback)
return cmd.execute()

@@ -537,5 +537,5 @@ }

let cmd = new Commands.QueryBackground(this.client, [this.ns, this.set, this, policy, queryID], callback)
const cmd = new Commands.QueryBackground(this.client, [this.ns, this.set, this, policy, queryID], callback)
cmd.convertResult = () => {
let module = this.filters.length > 0 ? 'query' : 'scan'
const module = this.filters.length > 0 ? 'query' : 'scan'
return new Job(this.client, queryID, module)

@@ -542,0 +542,0 @@ }

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -223,3 +223,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

let cmd = new Commands.ScanBackground(this.client, [this.ns, this.set, this, policy, scanID], callback)
const cmd = new Commands.ScanBackground(this.client, [this.ns, this.set, this, policy, scanID], callback)
cmd.convertResult = () => new Job(this.client, scanID, 'scan')

@@ -248,4 +248,4 @@ return cmd.execute()

var scanID = Job.safeRandomJobID()
let args = [this.ns, this.set, this, policy, scanID]
let cmd = new Commands.Scan(stream, args)
const args = [this.ns, this.set, this, policy, scanID]
const cmd = new Commands.Scan(stream, args)
cmd.execute()

@@ -252,0 +252,0 @@

@@ -235,8 +235,17 @@ // *****************************************************************************

/**
* Feature is only supported in the Aerospike Enterprise edition.
* Attempt to use an Enterprise feature on a Community server or a server
* without the applicable feature key.
* @const {number}
*/
exports.ERR_FAIL_ENTERPRISE_ONLY = exports.AEROSPIKE_ERR_FAIL_ENTERPRISE_ONLY = as.status.AEROSPIKE_ERR_FAIL_ENTERPRISE_ONLY
exports.ERR_ENTERPRISE_ONLY = exports.AEROSPIKE_ERR_ENTERPRISE_ONLY = as.status.AEROSPIKE_ERR_ENTERPRISE_ONLY
// TODO: Remove ERR_FAIL_ENTERPRISE_ONLY - this is kept for backwards compatibility only.
exports.ERR_FAIL_ENTERPRISE_ONLY = exports.AEROSPIKE_ERR_FAIL_ENTERPRISE_ONLY = as.status.AEROSPIKE_ERR_ENTERPRISE_ONLY
/**
* The operation cannot be applied to the current bin value on the server.
* @const {number}
*/
exports.ERR_OP_NOT_APPLICABLE = exports.AEROSPIKE_ERR_OP_NOT_APPLICABLE = as.status.AEROSPIKE_ERR_OP_NOT_APPLICABLE
/**
* There are no more records left for query.

@@ -560,5 +569,8 @@ * @const {number}

case exports.ERR_FAIL_ENTERPRISE_ONLY:
return 'Feature is only supported in the Aerospike Enterprise edition.'
case exports.ERR_ENTERPRISE_ONLY:
return 'Attempt to use an Enterprise feature on a Community server or a server without the applicable feature key.'
case exports.ERR_OP_NOT_APPLICABLE:
return 'The operation cannot be applied to the current bin value on the server.'
case exports.QUERY_END:

@@ -565,0 +577,0 @@ return 'There are no more records left for query.'

// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -68,7 +68,7 @@ // Licensed under the Apache License, Version 2.0 (the 'License')

UdfJob.prototype.hasCompleted = function (info) {
let filename = this.udfModule
let existsOnNode = Object.keys(info).map(
const filename = this.udfModule
const existsOnNode = Object.keys(info).map(
node => info[node]['udf-list'].some(
module => module.filename === filename))
let expected = this.command === UdfJob.REGISTER
const expected = this.command === UdfJob.REGISTER
return existsOnNode.every(exists => exists === expected)

@@ -75,0 +75,0 @@ }

// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -19,54 +19,29 @@ // Licensed under the Apache License, Version 2.0 (the "License")

const net = require('net')
const HOST_RE = /^(\[[0-9a-f:]+]|(?:\d{1,3}\.){3}\d{1,3}|[a-z][a-z0-9\-.]+)(?::([a-z][a-z0-9\-.]+))?(?::(\d+))?$/i
function hostToString (host) {
let hostStr
if (net.isIPv6(host.addr)) {
hostStr = `[${host.addr}]`
} else {
hostStr = host.addr
function parseHostString (hostString) {
const parts = hostString.match(HOST_RE)
if (!parts) {
throw new Error('Invalid host address: ' + hostString)
}
if (host.port) {
hostStr = hostStr.concat(':', host.port)
}
const host = {}
return hostStr
}
function hostsToString (hosts) {
if (typeof hosts === 'string') {
return hosts
let addr = parts[1]
if (addr.startsWith('[') && addr.endsWith(']')) {
addr = addr.substr(1, addr.length - 2)
}
host.addr = addr
return hosts.map(hostToString).join(',')
}
function parseHostString (hostString) {
var parts = hostString.match(HOST_RE)
if (!parts) {
throw new Error('Invalid host address: ' + hostString)
}
var host = {}
host.addr = parts[1]
var tlsName = parts[2]
const tlsName = parts[2]
if (tlsName) {
host.tls = tlsName
}
var port = parts[3]
const port = parts[3]
host.port = port ? Number.parseInt(port, 10) : 3000
return host
}
function parseHostsString (str) {
return str
.split(',')
.map(function (str) { return str.trim() })
.filter(function (x) { return !!x })
.map(parseHostString)
}
function print (err, result) {

@@ -81,6 +56,4 @@ if (err) {

module.exports = {
hostsToString: hostsToString,
parseHostString: parseHostString,
parseHostsString: parseHostsString,
print: print
}
{
"name": "aerospike",
"version": "3.11.0",
"version": "3.12.0",
"description": "Aerospike Client Library",

@@ -33,3 +33,4 @@ "keywords": [

"test": "mocha",
"posttest": "standard",
"lint": "standard",
"posttest": "npm run lint",
"coverage": "nyc npm test && nyc --reporter=lcov report",

@@ -45,3 +46,3 @@ "codecov": "codecov",

"minimatch": "^3.0.4",
"nan": "^2.13.2"
"nan": "^2.14.0"
},

@@ -55,10 +56,10 @@ "devDependencies": {

"ink-docstrap": "^1.3.0",
"jsdoc": "^3.5.5",
"jsdoc": "^3.6.2",
"mocha": "^6.1.4",
"mocha-clean": "^1.0.0",
"nyc": "^13.3.0",
"nyc": "^14.1.1",
"semver": "^6.0.0",
"standard": "^12.0",
"standard": "^14.0.0",
"tmp": "^0.1",
"yargs": "^13.2.2"
"yargs": "^14.0.0"
},

@@ -65,0 +66,0 @@ "standard": {

@@ -16,3 +16,3 @@ # Aerospike Node.js Client [![travis][travis-image]][travis-url] [![codecov][codecov-image]][codecov-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url]

(LTS). It supports the following operating systems: CentOS/RHEL 6/7, Debian
7/8/9, Ubuntu 14.04/16.04/18.04, as well as many Linux destributions compatible
8/9/10, Ubuntu 14.04/16.04/18.04, as well as many Linux destributions compatible
with one of these OS releases. macOS and Windows are also supported.

@@ -19,0 +19,0 @@

@@ -29,7 +29,7 @@ // *****************************************************************************

describe('client.apply()', function () {
let client = helper.client
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/apply/' })()
const client = helper.client
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/apply/' })()
before(() => helper.udf.register('udf.lua')
.then(() => client.put(key, { 'foo': 'bar' }, { ttl: 1000 })))
.then(() => client.put(key, { foo: 'bar' }, { ttl: 1000 })))

@@ -58,6 +58,6 @@ after(() => helper.udf.remove('udf.lua')

it('should invoke an UDF with apply policy', function (done) {
let policy = new Aerospike.ApplyPolicy({
const policy = new Aerospike.ApplyPolicy({
totalTimeout: 1500
})
let udf = {
const udf = {
module: 'udf',

@@ -64,0 +64,0 @@ funcname: 'withArguments',

@@ -41,3 +41,3 @@ // *****************************************************************************

.then(records => {
let keys = records.map(record => record.key)
const keys = records.map(record => record.key)
return client.batchExists(keys)

@@ -44,0 +44,0 @@ })

@@ -41,3 +41,3 @@ // *****************************************************************************

.then(records => {
let keys = records.map(record => record.key)
const keys = records.map(record => record.key)
return client.batchGet(keys)

@@ -47,3 +47,3 @@ .then(results => {

results.forEach(result => {
let putRecord = records.find(record => record.key.key === result.record.key.key)
const putRecord = records.find(record => record.key.key === result.record.key.key)
expect(result.status).to.equal(Aerospike.status.OK)

@@ -50,0 +50,0 @@ expect(result.record.bins).to.eql(putRecord.bins)

@@ -50,3 +50,3 @@ // *****************************************************************************

it('returns the status whether each key was found or not', function (done) {
let batchRecords = [
const batchRecords = [
{ key: new Key(helper.namespace, helper.set, 'test/batch_read/1') },

@@ -62,6 +62,6 @@ { key: new Key(helper.namespace, helper.set, 'test/batch_read/3') },

expect(results.length).to.equal(5)
let found = results.filter(
const found = results.filter(
result => result.status === Aerospike.status.OK)
expect(found.length).to.equal(3)
let notFound = results.filter(
const notFound = results.filter(
result => result.status === Aerospike.status.ERR_RECORD_NOT_FOUND)

@@ -142,3 +142,3 @@ expect(notFound.length).to.equal(2)

results.forEach(function (result) {
let record = result.record
const record = result.record
switch (record.key.key) {

@@ -176,3 +176,3 @@ case 'test/batch_read/1':

.then(results => {
let bins = results[0].record.bins
const bins = results[0].record.bins
expect(bins.i).to.be.a('number')

@@ -179,0 +179,0 @@ expect(bins.s).to.be.a('string')

@@ -41,3 +41,3 @@ // *****************************************************************************

.then(records => {
let keys = records.map(record => record.key)
const keys = records.map(record => record.key)
return client.batchSelect(keys, ['i', 's'])

@@ -44,0 +44,0 @@ })

@@ -151,3 +151,3 @@ // *****************************************************************************

it('client should emit nodeAdded events when connecting', function (done) {
let client = new Client(helper.config)
const client = new Client(helper.config)
client.once('nodeAdded', event => {

@@ -161,3 +161,3 @@ client.close()

it('client should emit events on cluster state changes', function (done) {
let client = new Client(helper.config)
const client = new Client(helper.config)
client.once('event', event => {

@@ -164,0 +164,0 @@ expect(event.name).to.equal('nodeAdded')

@@ -26,3 +26,3 @@ // *****************************************************************************

it('queues commands it cannot process immediately', function () {
let test = function (Aerospike, config, done) {
const test = function (Aerospike, config, done) {
config = Object.assign(config, { log: { level: Aerospike.log.OFF } })

@@ -32,3 +32,3 @@ Aerospike.setupGlobalCommandQueue({ maxCommandsInProcess: 5, maxCommandsInQueue: 5 })

.then(client => {
let cmds = Array.from({ length: 10 }, (_, i) =>
const cmds = Array.from({ length: 10 }, (_, i) =>
client.put(new Aerospike.Key('test', 'test', i), { i: i }))

@@ -45,3 +45,3 @@ Promise.all(cmds)

it('rejects commands it cannot queue', function () {
let test = function (Aerospike, config, done) {
const test = function (Aerospike, config, done) {
config = Object.assign(config, { log: { level: Aerospike.log.OFF } }) // disable logging for this test to suppress C client error messages

@@ -51,3 +51,3 @@ Aerospike.setupGlobalCommandQueue({ maxCommandsInProcess: 5, maxCommandsInQueue: 1 })

.then(client => {
let cmds = Array.from({ length: 10 }, (_, i) =>
const cmds = Array.from({ length: 10 }, (_, i) =>
client.put(new Aerospike.Key('test', 'test', i), { i: i }))

@@ -65,3 +65,3 @@ Promise.all(cmds)

it('throws an error when trying to configure command queue after client connect', function () {
let test = function (Aerospike, config, done) {
const test = function (Aerospike, config, done) {
config = Object.assign(config, { log: { level: Aerospike.log.OFF } })

@@ -68,0 +68,0 @@ Aerospike.connect(config)

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -32,3 +32,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

it('creates subclasses with informative constructor names', function () {
let cmd = new TestCommand({})
const cmd = new TestCommand({})
expect(cmd.constructor.name).to.equal('TestCommand')

@@ -38,4 +38,4 @@ })

it('keeps a reference to the client instance', function () {
let client = {}
let cmd = new TestCommand(client)
const client = {}
const cmd = new TestCommand(client)
expect(cmd.client).to.equal(client)

@@ -42,0 +42,0 @@ })

@@ -41,5 +41,5 @@ // *****************************************************************************

it('copies config values from the passed Object', function () {
let settings = {
const settings = {
clusterName: 'testCluster',
hosts: [ { addr: 'localhost', port: 3000 } ],
hosts: [{ addr: 'localhost', port: 3000 }],
log: { level: 1, file: 2 },

@@ -71,3 +71,3 @@ policies: {

let config = new Config(settings)
const config = new Config(settings)
expect(config).to.have.property('clusterName')

@@ -90,3 +90,3 @@ expect(config).to.have.property('hosts')

let policies = config.policies
const policies = config.policies
expect(policies.apply).to.be.instanceof(Aerospike.ApplyPolicy)

@@ -104,3 +104,3 @@ expect(policies.batch).to.be.instanceof(Aerospike.BatchPolicy)

it('initializes default policies', function () {
let settings = {
const settings = {
policies: {

@@ -118,3 +118,3 @@ apply: { totalTimeout: 1000 },

}
let config = new Config(settings)
const config = new Config(settings)

@@ -155,3 +155,3 @@ expect(config.policies.apply).to.be.instanceof(Aerospike.ApplyPolicy)

it('throws a TypeError if invalid policy values are passed', function () {
let settings = {
const settings = {
policies: {

@@ -158,0 +158,0 @@ totalTimeout: 1000

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -36,3 +36,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

it('throws an error if not passed a number', function () {
let fn = () => new Double('four point nine')
const fn = () => new Double('four point nine')
expect(fn).to.throw(TypeError)

@@ -42,3 +42,3 @@ })

it('throws an error if called without `new`', function () {
let fn = () => Double(3.1415)
const fn = () => Double(3.1415)
expect(fn).to.throw('Invalid use of Double constructor')

@@ -45,0 +45,0 @@ })

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -37,3 +37,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

it('initializes the error with default values', function () {
let subject = new AerospikeError()
const subject = new AerospikeError()
expect(subject).to.have.property('message', '')

@@ -49,3 +49,3 @@ expect(subject).to.have.property('code', status.ERR_CLIENT)

it('sets an error message', function () {
let subject = new AerospikeError('Dooh!')
const subject = new AerospikeError('Dooh!')
expect(subject).to.have.property('message', 'Dooh!')

@@ -55,4 +55,4 @@ })

it('keeps a reference to the command', function () {
let cmd = {}
let subject = new AerospikeError('Dooh!', cmd)
const cmd = {}
const subject = new AerospikeError('Dooh!', cmd)
expect(subject).to.have.property('command', cmd)

@@ -62,3 +62,3 @@ })

it('captures a stacktrace', function () {
let subject = new AerospikeError('Dooh!')
const subject = new AerospikeError('Dooh!')
expect(subject).to.have.property('stack')

@@ -70,5 +70,5 @@ .that.is.a('string')

it('copies the stacktrace of the command', function () {
let cmd = { name: 'AerospikeError', message: 'Dooh!' }
const cmd = { name: 'AerospikeError', message: 'Dooh!' }
Error.captureStackTrace(cmd)
let subject = new AerospikeError('Dooh!', cmd)
const subject = new AerospikeError('Dooh!', cmd)
expect(subject).to.have.property('stack')

@@ -82,3 +82,3 @@ .that.is.a('string')

it('copies the info from a AerospikeClient error instance', function () {
let error = {
const error = {
code: -11,

@@ -91,3 +91,3 @@ message: 'Dooh!',

}
let subject = AerospikeError.fromASError(error)
const subject = AerospikeError.fromASError(error)
expect(subject).to.have.property('code', -11)

@@ -102,7 +102,7 @@ expect(subject).to.have.property('message', 'Dooh!')

it('replaces error codes with descriptive messages', function () {
let error = {
const error = {
code: status.ERR_RECORD_NOT_FOUND,
message: '127.0.0.1:3000 AEROSPIKE_ERR_RECORD_NOT_FOUND'
}
let subject = AerospikeError.fromASError(error)
const subject = AerospikeError.fromASError(error)
expect(subject.message).to.equal('127.0.0.1:3000 Record does not exist in database. May be returned by read, or write with policy Aerospike.policy.exists.UPDATE')

@@ -112,3 +112,3 @@ })

it('returns an AerospikeError instance unmodified', function () {
let error = new AerospikeError('Dooh!')
const error = new AerospikeError('Dooh!')
expect(AerospikeError.fromASError(error)).to.equal(error)

@@ -118,3 +118,3 @@ })

it('returns null if the status code is OK', function () {
let error = { code: status.OK }
const error = { code: status.OK }
expect(AerospikeError.fromASError(error)).to.be.null()

@@ -130,4 +130,4 @@ })

it('returns true if the error code indicates a server error', function () {
let error = { code: status.ERR_RECORD_NOT_FOUND }
let subject = AerospikeError.fromASError(error)
const error = { code: status.ERR_RECORD_NOT_FOUND }
const subject = AerospikeError.fromASError(error)
expect(subject.isServerError()).to.be.true()

@@ -137,4 +137,4 @@ })

it('returns false if the error code indicates a client error', function () {
let error = { code: status.ERR_PARAM }
let subject = AerospikeError.fromASError(error)
const error = { code: status.ERR_PARAM }
const subject = AerospikeError.fromASError(error)
expect(subject.isServerError()).to.be.false()

@@ -146,3 +146,3 @@ })

it('sets an informative error message', function () {
let subject = new AerospikeError('Dooh!')
const subject = new AerospikeError('Dooh!')
expect(subject.toString()).to.eql('AerospikeError: Dooh!')

@@ -149,0 +149,0 @@ })

@@ -25,7 +25,7 @@ // *****************************************************************************

describe('client.exists()', function () {
let client = helper.client
const client = helper.client
context('Promises', function () {
it('returns true if the record exists', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exists/' })()
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exists/' })()

@@ -39,3 +39,3 @@ return client.put(key, { str: 'abcde' })

it('returns false if the record does not exist', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exists/' })()
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exists/' })()

@@ -49,3 +49,3 @@ return client.exists(key)

it('returns true if the record exists', function (done) {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exists/' })()
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exists/' })()

@@ -66,3 +66,3 @@ client.put(key, { str: 'abcde' }, error => {

it('returns false if the record does not exist', function (done) {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exists/' })()
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exists/' })()

@@ -69,0 +69,0 @@ client.exists(key, (error, result) => {

// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -39,5 +39,5 @@ // Licensed under the Apache License, Version 2.0 (the "License")

record = new Record(generator.key(), generator.bins(), generator.metadata())
let putCb = creator.bind(this, record)
let policy = generator.policy()
let meta = { ttl: record.ttl, gen: record.gen }
const putCb = creator.bind(this, record)
const policy = generator.policy()
const meta = { ttl: record.ttl, gen: record.gen }
client.put(record.key, record.bins, meta, policy, putCb)

@@ -76,3 +76,3 @@ inFlight++

return new Promise((resolve, reject) => {
let records = []
const records = []
createRecords(helper.client, generator, n, 200, record => {

@@ -79,0 +79,0 @@ if (record) {

@@ -29,3 +29,3 @@ // *****************************************************************************

context('GeoJSON class #noserver', function () {
let subject = new GeoJSON({ type: 'Point', coordinates: [103.913, 1.308] })
const subject = new GeoJSON({ type: 'Point', coordinates: [103.913, 1.308] })

@@ -46,3 +46,3 @@ describe('constructor', function () {

it('throws a type error if passed an invalid GeoJSON value', function () {
let fn = () => new GeoJSON(45)
const fn = () => new GeoJSON(45)
expect(fn).to.throw(TypeError)

@@ -86,3 +86,3 @@ })

it('creates a GeoJSON circle representation', function () {
let circle = new GeoJSON({ type: 'AeroCircle', coordinates: [[-122.250629, 37.871022], 300] })
const circle = new GeoJSON({ type: 'AeroCircle', coordinates: [[-122.250629, 37.871022], 300] })
expect(GeoJSON.Circle(-122.250629, 37.871022, 300)).to.eql(circle)

@@ -89,0 +89,0 @@ })

@@ -63,4 +63,4 @@ // *****************************************************************************

it('should return lists and maps as raw bytes', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/get/' })()
let bins = {
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/get/' })()
const bins = {
i: 123,

@@ -71,3 +71,3 @@ s: 'abc',

}
let policy = new Aerospike.ReadPolicy({
const policy = new Aerospike.ReadPolicy({
deserialize: false

@@ -79,3 +79,3 @@ })

.then(record => {
let bins = record.bins
const bins = record.bins
expect(bins.i).to.eql(123)

@@ -118,7 +118,7 @@ expect(bins.s).to.eql('abc')

it('fetches a record given the digest', function () {
let key = new Aerospike.Key('test', 'test', 'digestOnly')
const key = new Aerospike.Key('test', 'test', 'digestOnly')
client.put(key, { foo: 'bar' })
.then(() => {
let digest = key.digest
let key2 = new Aerospike.Key('test', null, null, digest)
const digest = key.digest
const key2 = new Aerospike.Key('test', null, null, digest)
return client.get(key2)

@@ -125,0 +125,0 @@ .then(record => expect(record.bins.foo).to.equal('bar'))

// *****************************************************************************
// Copyright 2013-2017 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -27,4 +27,4 @@ // Licensed under the Apache License, Version 2.0 (the "License")

describe('IndexJob', function () {
let client = helper.client
let testIndex = { name: null, bin: null, counter: 0 }
const client = helper.client
const testIndex = { name: null, bin: null, counter: 0 }
beforeEach(function () {

@@ -58,3 +58,3 @@ testIndex.counter++

it('should return a boolean indicating whether the job is done or not', function () {
let options = {
const options = {
ns: helper.namespace,

@@ -61,0 +61,0 @@ set: helper.set,

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -28,6 +28,6 @@ // Licensed under the Apache License, Version 2.0 (the "License")

context('secondary indexes', function () {
let client = helper.client
const client = helper.client
// generate unique index name for each test
let testIndex = { name: null, bin: null, counter: 0 }
const testIndex = { name: null, bin: null, counter: 0 }
beforeEach(() => {

@@ -40,4 +40,4 @@ testIndex.counter++

function verifyIndexExists (namespace, indexName) {
let sindex = 'sindex/' + namespace + '/' + indexName
let checkStatus = function () {
const sindex = 'sindex/' + namespace + '/' + indexName
const checkStatus = function () {
return client.infoAll(sindex)

@@ -58,3 +58,3 @@ .then(() => true)

it('returns an IndexJob instance', function () {
let options = {
const options = {
ns: helper.namespace,

@@ -73,3 +73,3 @@ set: helper.set,

it('should create a complex index on list', function () {
let options = {
const options = {
ns: helper.namespace,

@@ -88,3 +88,3 @@ set: helper.set,

it('should create an integer index with info policy', function () {
let options = {
const options = {
ns: helper.namespace,

@@ -96,3 +96,3 @@ set: helper.set,

}
let policy = new Aerospike.InfoPolicy({
const policy = new Aerospike.InfoPolicy({
totalTimeout: 100

@@ -106,3 +106,3 @@ })

it('re-creating an index with identical options returns an error', function () {
let options = {
const options = {
ns: helper.namespace,

@@ -131,3 +131,3 @@ set: helper.set,

it('should create an integer index', function () {
let options = {
const options = {
ns: helper.namespace,

@@ -146,3 +146,3 @@ set: helper.set,

it('should create an string index', function () {
let args = {
const args = {
ns: helper.namespace,

@@ -161,3 +161,3 @@ set: helper.set,

it('should create a geospatial index', function () {
let args = {
const args = {
ns: helper.namespace,

@@ -164,0 +164,0 @@ set: helper.set,

@@ -29,3 +29,3 @@ // *****************************************************************************

context('Info commands', function () {
let client = helper.client
const client = helper.client

@@ -160,3 +160,3 @@ describe('Client#info()', function () {

var infoHash = info.parse(infoStr)
expect(infoHash['statistics']).to.eql({ mem: 10, req: 20 })
expect(infoHash.statistics).to.eql({ mem: 10, req: 20 })
})

@@ -167,3 +167,3 @@

var infoHash = info.parse(infoStr)
expect(infoHash['features']).to.eql(['geo', 'double'])
expect(infoHash.features).to.eql(['geo', 'double'])
})

@@ -174,3 +174,3 @@

var infoHash = info.parse(infoStr)
expect(infoHash['version']).to.be.a('number')
expect(infoHash.version).to.be.a('number')
})

@@ -213,5 +213,5 @@

it('should parse the bins info key', function () {
let infoStr = 'bins\ttest:bin_names=2,bin_names_quota=32768,bin1,bin2;'
let infoHash = info.parse(infoStr)
let expected = {
const infoStr = 'bins\ttest:bin_names=2,bin_names_quota=32768,bin1,bin2;'
const infoHash = info.parse(infoStr)
const expected = {
test: {

@@ -222,9 +222,9 @@ names: ['bin1', 'bin2'],

}
expect(infoHash['bins']).to.deep.equal(expected)
expect(infoHash.bins).to.deep.equal(expected)
})
it('should pick the right separators to parse based on the key pattern', function () {
let infoStr = 'sets/test/foo/bar\tobjects=0:tombstones=0:truncate_lut=275452156000:disable-eviction=false;'
let infoHash = info.parse(infoStr)
let expected = {
const infoStr = 'sets/test/foo/bar\tobjects=0:tombstones=0:truncate_lut=275452156000:disable-eviction=false;'
const infoHash = info.parse(infoStr)
const expected = {
objects: 0,

@@ -231,0 +231,0 @@ tombstones: 0,

@@ -136,4 +136,4 @@ // *****************************************************************************

it('matches two keys with identical ns, set and user key', function () {
let key1 = new Key('ns1', 'set1', 'key1')
let key2 = new Key('ns1', 'set1', 'key1')
const key1 = new Key('ns1', 'set1', 'key1')
const key2 = new Key('ns1', 'set1', 'key1')
expect(key1.equals(key2)).to.be.true()

@@ -144,4 +144,4 @@ expect(key2.equals(key1)).to.be.true()

it('matches two keys with identical ns, set, user key and digest', function () {
let key1 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
let key2 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
const key1 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
const key2 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
expect(key1.equals(key2)).to.be.true()

@@ -152,4 +152,4 @@ expect(key2.equals(key1)).to.be.true()

it('matches two keys with identical ns, set and digest', function () {
let key1 = new Key('ns1', 'set1', null, Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
let key2 = new Key('ns1', 'set1', null, Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
const key1 = new Key('ns1', 'set1', null, Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
const key2 = new Key('ns1', 'set1', null, Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
expect(key1.equals(key2)).to.be.true()

@@ -160,4 +160,4 @@ expect(key2.equals(key1)).to.be.true()

it('a key with digest to another key with identical ns, set and user key but without digest', function () {
let key1 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
let key2 = new Key('ns1', 'set1', 'key1')
const key1 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
const key2 = new Key('ns1', 'set1', 'key1')
expect(key1.equals(key2)).to.be.true()

@@ -168,4 +168,4 @@ expect(key2.equals(key1)).to.be.true()

it('matches two keys with identical ns, empty set and user key', function () {
let key1 = new Key('ns1', null, 'key1')
let key2 = new Key('ns1', null, 'key1')
const key1 = new Key('ns1', null, 'key1')
const key2 = new Key('ns1', null, 'key1')
expect(key1.equals(key2)).to.be.true()

@@ -176,4 +176,4 @@ expect(key2.equals(key1)).to.be.true()

it('does not match two keys with different ns', function () {
let key1 = new Key('ns1', 'set1', 'key1')
let key2 = new Key('ns2', 'set1', 'key1')
const key1 = new Key('ns1', 'set1', 'key1')
const key2 = new Key('ns2', 'set1', 'key1')
expect(key1.equals(key2)).to.be.false()

@@ -184,4 +184,4 @@ expect(key2.equals(key1)).to.be.false()

it('does not match two keys with different set', function () {
let key1 = new Key('ns1', 'set1', 'key1')
let key2 = new Key('ns1', 'set2', 'key1')
const key1 = new Key('ns1', 'set1', 'key1')
const key2 = new Key('ns1', 'set2', 'key1')
expect(key1.equals(key2)).to.be.false()

@@ -192,4 +192,4 @@ expect(key2.equals(key1)).to.be.false()

it('does not match a key with set and a key without set', function () {
let key1 = new Key('ns1', 'set1', 'key1')
let key2 = new Key('ns1', null, 'key1')
const key1 = new Key('ns1', 'set1', 'key1')
const key2 = new Key('ns1', null, 'key1')
expect(key1.equals(key2)).to.be.false()

@@ -200,4 +200,4 @@ expect(key2.equals(key1)).to.be.false()

it('does not match two keys with different user keys', function () {
let key1 = new Key('ns1', 'set1', 'key1')
let key2 = new Key('ns1', 'set1', 'key2')
const key1 = new Key('ns1', 'set1', 'key1')
const key2 = new Key('ns1', 'set1', 'key2')
expect(key1.equals(key2)).to.be.false()

@@ -208,4 +208,4 @@ expect(key2.equals(key1)).to.be.false()

it('does not match a key with user key and a key without user key', function () {
let key1 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
let key2 = new Key('ns1', 'set1', null, Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
const key1 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
const key2 = new Key('ns1', 'set1', null, Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
expect(key1.equals(key2)).to.be.false()

@@ -216,4 +216,4 @@ expect(key2.equals(key1)).to.be.false()

it('does not match two keys with different digests', function () {
let key1 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
let key2 = new Key('ns1', 'set1', 'key1', Buffer.from('0j9i8h7g6f5e4d3c2b1a'))
const key1 = new Key('ns1', 'set1', 'key1', Buffer.from('a1b2c3d4e5f6g7h8i9j0'))
const key2 = new Key('ns1', 'set1', 'key1', Buffer.from('0j9i8h7g6f5e4d3c2b1a'))
expect(key1.equals(key2)).to.be.false()

@@ -220,0 +220,0 @@ expect(key2.equals(key1)).to.be.false()

@@ -28,2 +28,3 @@ // *****************************************************************************

const ops = Aerospike.operations
const Context = Aerospike.cdt.Context
const status = Aerospike.status

@@ -33,108 +34,34 @@

const {
assertError,
assertRecordEql,
assertResultEql,
assertResultSatisfy,
cleanup,
createRecord,
expectError,
initState,
operate
} = require('./util/statefulAsyncTest')
const orderList = (bin, ctx) => {
const setListOrder = lists.setOrder(bin, lists.order.ORDERED)
if (ctx) setListOrder.withContext(ctx)
return operate(setListOrder)
}
describe('client.operate() - CDT List operations', function () {
helper.skipUnlessSupportsFeature('cdt-list', this)
let client = helper.client
let ListOutOfBoundsError
before(() => {
ListOutOfBoundsError = helper.cluster.isVersionInRange('>=4.6.0')
? status.ERR_OP_NOT_APPLICABLE
: status.ERR_REQUEST_INVALID
})
class State {
enrich (name, promise) {
if (this._expectError) {
return promise.catch(error => {
this['error'] = error
return this
})
} else {
return promise.then(value => {
this[name] = value
return this
})
}
}
passthrough (promise) {
return promise.then(() => this)
}
resolve (value) {
return Promise.resolve(value).then(() => this)
}
expectError () {
this._expectError = true
return this
}
}
function initState () {
return Promise.resolve(new State())
}
function expectError () {
return function (state) {
return state.expectError()
}
}
function createRecord (bins) {
return function (state) {
let key = helper.keygen.string(helper.namespace, helper.set, { prefix: 'cdt_list/' })()
let meta = { ttl: 600 }
let policy = new Aerospike.WritePolicy({
exists: Aerospike.policy.exists.CREATE_OR_REPLACE
})
return state.enrich('key', client.put(key, bins, meta, policy))
}
}
function operate (ops) {
if (!Array.isArray(ops)) {
ops = [ops]
}
return function (state) {
return state.enrich('result', client.operate(state.key, ops))
}
}
function orderList (bin) {
return operate(lists.setOrder(bin, lists.order.ORDERED))
}
function assertResultEql (expected) {
return function (state) {
return state.resolve(expect(state.result.bins).to.eql(expected, 'operate result'))
}
}
function assertResultSatisfy (matcher) {
return function (state) {
return state.resolve(expect(state.result.bins).to.satisfy(matcher, 'operate result'))
}
}
function assertRecordEql (expected) {
return function (state) {
return state.passthrough(client.get(state.key)
.then(record => expect(record.bins).to.eql(expected, 'record bins after operation')))
}
}
function assertError (code) {
return function (state) {
return state.resolve(
expect(state.error, 'error raised by operate command')
.to.be.instanceof(AerospikeError)
.with.property('code', code))
}
}
function cleanup () {
return function (state) {
return state.passthrough(client.remove(state.key))
}
}
describe('lists.setOrder', function () {
it('changes the list order', function () {
return initState()
.then(createRecord({ list: [ 3, 1, 2 ] }))
.then(createRecord({ list: [3, 1, 2] }))
.then(operate([

@@ -147,2 +74,18 @@ lists.setOrder('list', lists.order.ORDERED),

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('changes the order of a nested list', function () {
return initState()
.then(createRecord({ list: [[3, 1, 2], [6, 5, 4]] }))
.then(operate([
lists.setOrder('list', lists.order.ORDERED).withContext(ctx => ctx.addListIndex(0)),
lists.setOrder('list', lists.order.ORDERED).withContext(ctx => ctx.addListIndex(1)),
ops.read('list')
]))
.then(assertResultEql({ list: [[1, 2, 3], [4, 5, 6]] }))
.then(cleanup())
})
})
})

@@ -153,3 +96,3 @@

return initState()
.then(createRecord({ list: [ 3, 1, 2, 1 ] }))
.then(createRecord({ list: [3, 1, 2, 1] }))
.then(operate([

@@ -163,12 +106,29 @@ lists.sort('list', lists.sortFlags.DEFAULT),

it('sorts the list and drops duplicates', function () {
return initState()
.then(createRecord({ list: [ 3, 1, 2, 1 ] }))
.then(operate([
lists.sort('list', lists.sortFlags.DROP_DUPLICATES),
ops.read('list')
]))
.then(assertResultEql({ list: [1, 2, 3] }))
.then(cleanup())
context('with DROP_DUPLICATES flag', function () {
it('sorts the list and drops duplicates', function () {
return initState()
.then(createRecord({ list: [3, 1, 2, 1] }))
.then(operate([
lists.sort('list', lists.sortFlags.DROP_DUPLICATES),
ops.read('list')
]))
.then(assertResultEql({ list: [1, 2, 3] }))
.then(cleanup())
})
})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('sorts a nested list', function () {
return initState()
.then(createRecord({ list: [['a', 'b', 'c'], [3, 1, 2, 1]] }))
.then(operate([
lists.sort('list', lists.sortFlags.DEFAULT).withContext(ctx => ctx.addListIndex(-1)),
ops.read('list')
]))
.then(assertResultEql({ list: [['a', 'b', 'c'], [1, 1, 2, 3]] }))
.then(cleanup())
})
})
})

@@ -187,3 +147,3 @@

context('with add-unique flag', function () {
let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE

@@ -204,3 +164,3 @@ }

let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE | lists.writeFlags.NO_FAIL

@@ -219,2 +179,15 @@ }

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('appends a value to a nested list', function () {
return initState()
.then(createRecord({ list: [1, 2, ['a', 'b', 'c'], 4, 5] }))
.then(operate(lists.append('list', 'd').withContext(ctx => ctx.addListIndex(2))))
.then(assertResultEql({ list: 4 }))
.then(assertRecordEql({ list: [1, 2, ['a', 'b', 'c', 'd'], 4, 5] }))
.then(cleanup)
})
})
})

@@ -242,3 +215,3 @@

context('with add-unique flag', function () {
let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE

@@ -259,3 +232,3 @@ }

let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE | lists.writeFlags.NO_FAIL

@@ -274,3 +247,3 @@ }

context('with partial flag', function () {
let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE | lists.writeFlags.NO_FAIL | lists.writeFlags.PARTIAL

@@ -290,2 +263,15 @@ }

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('appends the items to a nested list', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.appendItems('map', [99, 100]).withContext(ctx => ctx.addMapKey('list'))))
.then(assertResultEql({ map: 7 }))
.then(assertRecordEql({ map: { list: [1, 2, 3, 4, 5, 99, 100] } }))
.then(cleanup)
})
})
})

@@ -304,3 +290,3 @@

context('with add-unique flag', function () {
let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE

@@ -321,3 +307,3 @@ }

let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE | lists.writeFlags.NO_FAIL

@@ -340,3 +326,3 @@ }

let policy = new Aerospike.ListPolicy({
const policy = new Aerospike.ListPolicy({
writeFlags: lists.writeFlags.INSERT_BOUNDED

@@ -350,3 +336,3 @@ })

.then(operate(lists.insert('list', 10, 99, policy)))
.then(assertError(status.ERR_REQUEST_INVALID))
.then(assertError(ListOutOfBoundsError))
.then(cleanup)

@@ -356,3 +342,3 @@ })

context('with no-fail flag', function () {
let policy = new Aerospike.ListPolicy({
const policy = new Aerospike.ListPolicy({
writeFlags: lists.writeFlags.INSERT_BOUNDED | lists.writeFlags.NO_FAIL

@@ -371,2 +357,15 @@ })

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('inserts the item at the specified index of a nested list', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.insert('map', 2, 99).withContext(ctx => ctx.addMapKey('list'))))
.then(assertResultEql({ map: 6 }))
.then(assertRecordEql({ map: { list: [1, 2, 99, 3, 4, 5] } }))
.then(cleanup)
})
})
})

@@ -394,3 +393,3 @@

context('with add-unique flag', function () {
let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE

@@ -411,3 +410,3 @@ }

let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE | lists.writeFlags.NO_FAIL

@@ -426,3 +425,3 @@ }

context('with partial flag', function () {
let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE | lists.writeFlags.NO_FAIL | lists.writeFlags.PARTIAL

@@ -446,3 +445,3 @@ }

let policy = new Aerospike.ListPolicy({
const policy = new Aerospike.ListPolicy({
writeFlags: lists.writeFlags.INSERT_BOUNDED

@@ -456,3 +455,3 @@ })

.then(operate(lists.insertItems('list', 10, [99, 100], policy)))
.then(assertError(status.ERR_REQUEST_INVALID))
.then(assertError(ListOutOfBoundsError))
.then(cleanup)

@@ -462,3 +461,3 @@ })

context('with no-fail flag', function () {
let policy = new Aerospike.ListPolicy({
const policy = new Aerospike.ListPolicy({
writeFlags: lists.writeFlags.INSERT_BOUNDED | lists.writeFlags.NO_FAIL

@@ -477,2 +476,15 @@ })

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('inserts the items at the specified index of a nested list', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.insertItems('map', 2, [99, 100]).withContext(ctx => ctx.addMapKey('list'))))
.then(assertResultEql({ map: 7 }))
.then(assertRecordEql({ map: { list: [1, 2, 99, 100, 3, 4, 5] } }))
.then(cleanup)
})
})
})

@@ -489,2 +501,15 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes the item at the specified index and returns it', function () {
return initState()
.then(createRecord({ list: [[1, 2, 3, 4, 5], [6, 7, 8]] }))
.then(operate(lists.pop('list', 2).withContext(ctx => ctx.addListIndex(0))))
.then(assertResultEql({ list: 3 }))
.then(assertRecordEql({ list: [[1, 2, 4, 5], [6, 7, 8]] }))
.then(cleanup)
})
})
})

@@ -510,2 +535,15 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes the items in the specified range and returns them', function () {
return initState()
.then(createRecord({ list: [[1, 2, 3, 4, 5], [6, 7, 8]] }))
.then(operate(lists.popRange('list', 2).withContext(ctx => ctx.addListIndex(1))))
.then(assertResultEql({ list: [8] }))
.then(assertRecordEql({ list: [[1, 2, 3, 4, 5], [6, 7]] }))
.then(cleanup)
})
})
})

@@ -522,2 +560,15 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes the item at the specified index', function () {
return initState()
.then(createRecord({ list: [[1, 2, 3, 4, 5], [6, 7, 8]] }))
.then(operate(lists.remove('list', 2).withContext(ctx => ctx.addListIndex(1))))
.then(assertResultEql({ list: 1 }))
.then(assertRecordEql({ list: [[1, 2, 3, 4, 5], [6, 7]] }))
.then(cleanup)
})
})
})

@@ -543,2 +594,15 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes the item at the specified range', function () {
return initState()
.then(createRecord({ list: [[1, 2, 3, 4, 5], [6, 7, 8]] }))
.then(operate(lists.removeRange('list', 1, 3).withContext(ctx => ctx.addListIndex(0))))
.then(assertResultEql({ list: 3 }))
.then(assertRecordEql({ list: [[1, 5], [6, 7, 8]] }))
.then(cleanup)
})
})
})

@@ -557,2 +621,14 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes the item at the specified index', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.removeByIndex('map', 2).withContext(ctx => ctx.addMapKey('list'))))
.then(assertRecordEql({ map: { list: [1, 2, 4, 5] } }))
.then(cleanup)
})
})
})

@@ -580,2 +656,14 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes the item int the specified range', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.removeByIndexRange('map', 1, 3).withContext(ctx => ctx.addMapKey('list'))))
.then(assertRecordEql({ map: { list: [1, 5] } }))
.then(cleanup)
})
})
})

@@ -594,2 +682,14 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes all items with the specified value', function () {
return initState()
.then(createRecord({ list: [[3, 2, 1], [1, 2, 3, 1, 2, 3]] }))
.then(operate(lists.removeByValue('list', 3).withContext(ctx => ctx.addListValue([3, 2, 1]))))
.then(assertRecordEql({ list: [[2, 1], [1, 2, 3, 1, 2, 3]] }))
.then(cleanup)
})
})
})

@@ -617,2 +717,19 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes all items except with the specified values', function () {
return initState()
.then(createRecord({ list: [[3, 2, 1], [1, 2, 3, 1, 2, 3]] }))
.then(operate(
lists
.removeByValueList('list', [1, 4])
.withContext(ctx => ctx.addListIndex(-1))
.invertSelection()
))
.then(assertRecordEql({ list: [[3, 2, 1], [1, 1]] }))
.then(cleanup)
})
})
})

@@ -632,2 +749,14 @@ })

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes all items in the specified range of values', function () {
return initState()
.then(createRecord({ list: [[1, 2, 3, 4, 5], [6, 7, 8]] }))
.then(operate(lists.removeByValueRange('list', 2, 5).withContext(ctx => ctx.addListIndex(0))))
.then(assertRecordEql({ list: [[1, 5], [6, 7, 8]] }))
.then(cleanup)
})
})
})

@@ -661,2 +790,16 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes all items nearest to value and greater, by relative rank', function () {
const listContext = new Context().addMapKey('list')
return initState()
.then(createRecord({ map: { list: [0, 4, 5, 9, 11, 15] } }))
.then(orderList('map', listContext))
.then(operate(lists.removeByValueRelRankRange('map', 5, 0, 2).withContext(listContext)))
.then(assertRecordEql({ map: { list: [0, 4, 11, 15] } }))
.then(cleanup)
})
})
})

@@ -675,2 +818,14 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes the item with the specified list rank', function () {
return initState()
.then(createRecord({ list: [[2, 3, 1, 4], [3, 1, 2, 4]] }))
.then(operate(lists.removeByRank('list', 1).withContext(ctx => ctx.addListIndex(1))))
.then(assertRecordEql({ list: [[2, 3, 1, 4], [3, 1, 4]] }))
.then(cleanup)
})
})
})

@@ -689,2 +844,14 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes the item with the specified list rank', function () {
return initState()
.then(createRecord({ list: [[3, 1, 2, 5, 4], [1, 2, 3]] }))
.then(operate(lists.removeByRankRange('list', 1, 3).withContext(ctx => ctx.addListIndex(0))))
.then(assertRecordEql({ list: [[1, 5], [1, 2, 3]] }))
.then(cleanup)
})
})
})

@@ -700,2 +867,14 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes all elements from the list', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.clear('map').withContext(ctx => ctx.addMapKey('list'))))
.then(assertRecordEql({ map: { list: [] } }))
.then(cleanup)
})
})
})

@@ -711,2 +890,46 @@

})
context('with add-unique flag', function () {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE
}
it('fails with an error if the value already exists in the list', function () {
return initState()
.then(createRecord({ list: [1, 2, 3, 4, 5] }))
.then(expectError())
.then(operate(lists.set('list', 2, 5, policy)))
.then(assertError(status.ERR_FAIL_ELEMENT_EXISTS))
.then(assertRecordEql({ list: [1, 2, 3, 4, 5] }))
.then(cleanup)
})
context('with no-fail flag', function () {
helper.skipUnlessVersion('>= 4.3.0', this)
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE | lists.writeFlags.NO_FAIL
}
it('does not set the value but returns ok', function () {
return initState()
.then(createRecord({ list: [1, 2, 3, 4, 5] }))
.then(operate(lists.set('list', 2, 5, policy)))
.then(assertRecordEql({ list: [1, 2, 3, 4, 5] }))
.then(cleanup)
})
})
})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('sets the item at the specified index', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.set('map', 2, 99).withContext(ctx => ctx.addMapKey('list'))))
.then(assertRecordEql({ map: { list: [1, 2, 99, 4, 5] } }))
.then(cleanup)
})
})
})

@@ -723,2 +946,15 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes all elements not within the specified range', function () {
return initState()
.then(createRecord({ list: [['a', 'b', 'c'], [1, 2, 3, 4, 5]] }))
.then(operate(lists.trim('list', 1, 3).withContext(ctx => ctx.addListValue([1, 2, 3, 4, 5]))))
.then(assertResultEql({ list: 2 }))
.then(assertRecordEql({ list: [['a', 'b', 'c'], [2, 3, 4]] }))
.then(cleanup)
})
})
})

@@ -740,5 +976,17 @@

.then(operate(lists.get('list', 99)))
.then(assertError(status.ERR_REQUEST_INVALID))
.then(assertError(ListOutOfBoundsError))
.then(cleanup)
})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('returns the item at the specified index', function () {
return initState()
.then(createRecord({ list: [['a', 'b', 'c'], [1, 2, 3, 4, 5]] }))
.then(operate(lists.get('list', 2).withContext(ctx => ctx.addListIndex(1))))
.then(assertResultEql({ list: 3 }))
.then(cleanup)
})
})
})

@@ -762,2 +1010,14 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('returns the items in the specified range', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.getRange('map', 1, 3).withContext(ctx => ctx.addMapKey('list'))))
.then(assertResultEql({ map: [2, 3, 4] }))
.then(cleanup)
})
})
})

@@ -774,2 +1034,19 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches the item at the specified index and returns its value', function () {
return initState()
.then(createRecord({ list: [['a', 'b', 'c'], [1, 2, 3, 4, 5]] }))
.then(operate(
lists
.getByIndex('list', 2)
.withContext(ctx => ctx.addListIndex(1))
.andReturn(lists.returnType.VALUE)
))
.then(assertResultEql({ list: 3 }))
.then(cleanup)
})
})
})

@@ -795,2 +1072,19 @@ })

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches the items in the specified range and returns the values', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(
lists
.getByIndexRange('map', 2, 2)
.withContext(ctx => ctx.addMapKey('list'))
.andReturn(lists.returnType.VALUE)
))
.then(assertResultEql({ map: [3, 4] }))
.then(cleanup)
})
})
})

@@ -808,2 +1102,19 @@ })

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches all items with the specified value and returns the indexes', function () {
return initState()
.then(createRecord({ list: [['a', 'b', 'c'], [1, 2, 3, 1, 2, 3]] }))
.then(operate(
lists
.getByValue('list', 3)
.withContext(ctx => ctx.addListIndex(1))
.andReturn(lists.returnType.INDEX)
))
.then(assertResultEql({ list: [2, 5] }))
.then(cleanup)
})
})
})

@@ -821,2 +1132,19 @@ })

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches all items with the specified values and returns the indexes', function () {
return initState()
.then(createRecord({ list: [['a', 'b', 'c'], [1, 2, 3, 1, 2, 3]] }))
.then(operate(
lists
.getByValueList('list', [1, 3])
.withContext(ctx => ctx.addListIndex(1))
.andReturn(lists.returnType.INDEX)
))
.then(assertResultEql({ list: [0, 2, 3, 5] }))
.then(cleanup)
})
})
})

@@ -844,2 +1172,19 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches all items in the specified range of values and returns the indexes', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(
lists
.getByValueRange('map', 2, 5)
.withContext(ctx => ctx.addMapKey('list'))
.andReturn(lists.returnType.INDEX)
))
.then(assertResultEql({ map: [1, 2, 3] }))
.then(cleanup)
})
})
})

@@ -871,2 +1216,21 @@ })

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches all items nearest to value and greater, by relative rank', function () {
const listContext = new Context().addMapKey('list')
return initState()
.then(createRecord({ map: { list: [0, 4, 5, 9, 11, 15] } }))
.then(orderList('map', listContext))
.then(operate(
lists
.getByValueRelRankRange('map', 5, 0, 2)
.withContext(listContext)
.andReturn(lists.returnType.VALUE)
))
.then(assertResultEql({ map: [5, 9] }))
.then(cleanup)
})
})
})

@@ -883,2 +1247,19 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches the item with the specified list rank and returns the value', function () {
return initState()
.then(createRecord({ list: [[3, 1, 2, 4], ['a', 'b', 'c']] }))
.then(operate(
lists
.getByRank('list', 1)
.withContext(ctx => ctx.addListIndex(0))
.andReturn(lists.returnType.VALUE)
))
.then(assertResultEql({ list: 2 }))
.then(cleanup)
})
})
})

@@ -896,2 +1277,19 @@ })

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches the item with the specified list rank and returns the value', function () {
return initState()
.then(createRecord({ list: [[3, 1, 2, 5, 4], ['a', 'b', 'c']] }))
.then(operate(
lists
.getByRankRange('list', 1, 3)
.withContext(ctx => ctx.addListIndex(0))
.andReturn(lists.returnType.VALUE)
))
.then(assertResultSatisfy(result => eql(result.list.sort(), [2, 3, 4])))
.then(cleanup)
})
})
})

@@ -934,3 +1332,3 @@ })

context('with add-unique flag', function () {
let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE

@@ -951,3 +1349,3 @@ }

let policy = {
const policy = {
writeFlags: lists.writeFlags.ADD_UNIQUE | lists.writeFlags.NO_FAIL

@@ -968,2 +1366,15 @@ }

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('increments the element at the specified index and returns the final value', function () {
return initState()
.then(createRecord({ map: { list: [1, 2, 3, 4, 5] } }))
.then(operate(lists.increment('map', 1, 3).withContext(ctx => ctx.addMapKey('list'))))
.then(assertResultEql({ map: 5 }))
.then(assertRecordEql({ map: { list: [1, 5, 3, 4, 5] } }))
.then(cleanup)
})
})
})

@@ -979,2 +1390,14 @@

})
context('with nested list context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('returns the element count', function () {
return initState()
.then(createRecord({ list: [[], [1, 2, 3, 4, 5]] }))
.then(operate(lists.size('list').withContext(ctx => ctx.addListIndex(-1))))
.then(assertResultEql({ list: 5 }))
.then(cleanup)
})
})
})

@@ -981,0 +1404,0 @@

@@ -20,3 +20,2 @@ // *****************************************************************************

/* eslint-env mocha */
/* global expect */

@@ -26,4 +25,4 @@ const Aerospike = require('../lib/aerospike')

const AerospikeError = Aerospike.AerospikeError
const maps = Aerospike.maps
const Context = Aerospike.cdt.Context
const status = Aerospike.status

@@ -33,114 +32,26 @@

const {
assertError,
assertRecordEql,
assertResultEql,
assertResultSatisfy,
cleanup,
createRecord,
expectError,
initState,
operate
} = require('./util/statefulAsyncTest')
const orderMap = (bin, order, ctx) => {
const policy = new maps.MapPolicy({ order })
const setMapPolicy = maps.setPolicy(bin, policy)
if (ctx) setMapPolicy.withContext(ctx)
return operate(setMapPolicy)
}
const orderByKey = (bin, ctx) => orderMap(bin, maps.order.KEY_ORDERED, ctx)
const orderByKeyValue = (bin, ctx) => orderMap(bin, maps.order.KEY_VALUE_ORDERED, ctx)
describe('client.operate() - CDT Map operations', function () {
helper.skipUnlessSupportsFeature('cdt-map', this)
let client = helper.client
class State {
enrich (name, promise) {
if (this._expectError) {
return promise.catch(error => {
this['error'] = error
return this
})
} else {
return promise.then(value => {
this[name] = value
return this
})
}
}
passthrough (promise) {
return promise.then(() => this)
}
resolve (value) {
return Promise.resolve(value).then(() => this)
}
expectError () {
this._expectError = true
return this
}
}
function initState () {
return Promise.resolve(new State())
}
function expectError () {
return function (state) {
return state.expectError()
}
}
function createRecord (bins) {
return function (state) {
let key = helper.keygen.string(helper.namespace, helper.set, { prefix: 'cdt_map/' })()
let meta = { ttl: 600 }
let policy = new Aerospike.WritePolicy({
exists: Aerospike.policy.exists.CREATE_OR_REPLACE
})
return state.enrich('key', client.put(key, bins, meta, policy))
}
}
function operate (ops) {
if (!Array.isArray(ops)) {
ops = [ops]
}
return function (state) {
return state.enrich('result', client.operate(state.key, ops))
}
}
function orderByKey (bin) {
let policy = new maps.MapPolicy({
order: maps.order.KEY_ORDERED
})
return operate(maps.setPolicy(bin, policy))
}
function orderByKeyValue (bin) {
let policy = new maps.MapPolicy({
order: maps.order.KEY_VALUE_ORDERED
})
return operate(maps.setPolicy(bin, policy))
}
function assertResultEql (expected) {
return function (state) {
return state.resolve(expect(state.result.bins).to.eql(expected, 'operate result'))
}
}
function assertResultSatisfy (matcher) {
return function (state) {
return state.resolve(expect(state.result.bins).to.satisfy(matcher, 'operate result'))
}
}
function assertRecordEql (expected) {
return function (state) {
return state.passthrough(client.get(state.key)
.then(record => expect(record.bins).to.eql(expected, 'record bins after operation')))
}
}
function assertError (code) {
return function (state) {
return state.resolve(
expect(state.error, 'error raised by operate command')
.to.be.instanceof(AerospikeError)
.with.property('code', code))
}
}
function cleanup () {
return function (state) {
return state.passthrough(client.remove(state.key))
}
}
describe('maps.setPolicy', function () {

@@ -195,3 +106,3 @@ it('changes the map order', function () {

context('update-only write mode', function () {
let updateOnlyPolicy = new maps.MapPolicy({
const updateOnlyPolicy = new maps.MapPolicy({
writeMode: maps.writeMode.UPDATE_ONLY

@@ -222,3 +133,3 @@ })

let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.UPDATE_ONLY

@@ -246,3 +157,3 @@ })

context('with no-fail flag', function () {
let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.UPDATE_ONLY | maps.writeFlags.NO_FAIL

@@ -263,3 +174,3 @@ })

context('create-only write mode', function () {
let createOnlyPolicy = new maps.MapPolicy({
const createOnlyPolicy = new maps.MapPolicy({
writeMode: maps.writeMode.CREATE_ONLY

@@ -290,3 +201,3 @@ })

let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.CREATE_ONLY

@@ -314,3 +225,3 @@ })

context('with no-fail flag', function () {
let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.CREATE_ONLY | maps.writeFlags.NO_FAIL

@@ -329,2 +240,15 @@ })

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('adds the item to the nested map', function () {
return initState()
.then(createRecord({ list: [{ a: 1, b: 2, c: 3 }] }))
.then(operate(maps.put('list', 'd', 99).withContext(ctx => ctx.addListIndex(0))))
.then(assertResultEql({ list: 4 }))
.then(assertRecordEql({ list: [{ a: 1, b: 2, c: 3, d: 99 }] }))
.then(cleanup())
})
})
})

@@ -345,3 +269,3 @@

let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.UPDATE_ONLY

@@ -360,3 +284,3 @@ })

context('with no-fail flag', function () {
let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.UPDATE_ONLY | maps.writeFlags.NO_FAIL

@@ -375,3 +299,3 @@ })

context('with partial flag', function () {
let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.UPDATE_ONLY | maps.writeFlags.NO_FAIL | maps.writeFlags.PARTIAL

@@ -395,3 +319,3 @@ })

let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.CREATE_ONLY

@@ -410,3 +334,3 @@ })

context('with no-fail flag', function () {
let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.CREATE_ONLY | maps.writeFlags.NO_FAIL

@@ -425,3 +349,3 @@ })

context('with partial flag', function () {
let policy = new maps.MapPolicy({
const policy = new maps.MapPolicy({
writeFlags: maps.writeFlags.CREATE_ONLY | maps.writeFlags.NO_FAIL | maps.writeFlags.PARTIAL

@@ -441,2 +365,15 @@ })

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('adds each item to the nested map', function () {
return initState()
.then(createRecord({ map: { nested: { a: 1, b: 2, c: 3 } } }))
.then(operate(maps.putItems('map', { c: 99, d: 100 }).withContext(ctx => ctx.addMapKey('nested'))))
.then(assertResultEql({ map: 4 }))
.then(assertRecordEql({ map: { nested: { a: 1, b: 2, c: 99, d: 100 } } }))
.then(cleanup())
})
})
})

@@ -462,2 +399,15 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('increments the value of the entry and returns the final value', function () {
return initState()
.then(createRecord({ list: [[1, 2, 3], { a: 1, b: 2, c: 3 }] }))
.then(operate(maps.increment('list', 'b', 10).withContext(ctx => ctx.addListIndex(1))))
.then(assertResultEql({ list: 12 }))
.then(assertRecordEql({ list: [[1, 2, 3], { a: 1, b: 12, c: 3 }] }))
.then(cleanup())
})
})
})

@@ -483,2 +433,15 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('decrements the value of the entry and returns the final value', function () {
return initState()
.then(createRecord({ list: [{ a: 1, b: 12, c: 3 }, ['a', 'b', 'c']] }))
.then(operate(maps.decrement('list', 'b', 10).withContext(ctx => ctx.addListIndex(0))))
.then(assertResultEql({ list: 2 }))
.then(assertRecordEql({ list: [{ a: 1, b: 2, c: 3 }, ['a', 'b', 'c']] }))
.then(cleanup())
})
})
})

@@ -495,2 +458,18 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes all entries from the map', function () {
return initState()
.then(createRecord({ map: { nested: { deepNested: { a: 1, b: 12, c: 3 } } } }))
.then(operate(
maps
.clear('map')
.withContext(ctx => ctx.addMapKey('nested').addMapKey('deepNested'))
))
.then(assertRecordEql({ map: { nested: { deepNested: { } } } }))
.then(cleanup())
})
})
})

@@ -516,2 +495,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes a map entry identified by key', function () {
return initState()
.then(createRecord({ list: [{ a: 1, b: 2, c: 3 }, { a: 2, b: 3, c: 4 }] }))
.then(operate(maps.removeByKey('list', 'b').withContext(ctx => ctx.addListIndex(-1))))
.then(assertRecordEql({ list: [{ a: 1, b: 2, c: 3 }, { a: 2, c: 4 }] }))
.then(cleanup())
})
})
})

@@ -537,2 +528,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes map entries identified by one or more keys', function () {
return initState()
.then(createRecord({ maps: { a: { a: 1, b: 2, c: 3 }, b: { a: 2, b: 3, c: 4 } } }))
.then(operate(maps.removeByKeyList('maps', ['a', 'c']).withContext(ctx => ctx.addMapKey('a'))))
.then(assertRecordEql({ maps: { a: { b: 2 }, b: { a: 2, b: 3, c: 4 } } }))
.then(cleanup())
})
})
})

@@ -570,2 +573,16 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes map entries identified by key range', function () {
const mapContext = new Context().addListIndex(0)
return initState()
.then(createRecord({ list: [{ a: 1, b: 2, c: 3, d: 4 }] }))
.then(orderByKey('list', mapContext))
.then(operate(maps.removeByKeyRange('list', 'b', 'd').withContext(mapContext)))
.then(assertRecordEql({ list: [{ a: 1, d: 4 }] }))
.then(cleanup())
})
})
})

@@ -599,2 +616,16 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes map entries nearest to key and greater, by index', function () {
const mapContext = new Context().addListIndex(0)
return initState()
.then(createRecord({ list: [{ a: 17, e: 2, f: 15, j: 10 }, { a: 32, f: 14 }] }))
.then(orderByKey('list', mapContext))
.then(operate(maps.removeByKeyRelIndexRange('list', 'f', 0, 1).withContext(mapContext)))
.then(assertRecordEql({ list: [{ a: 17, e: 2, j: 10 }, { a: 32, f: 14 }] }))
.then(cleanup())
})
})
})

@@ -611,2 +642,20 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes a map entry identified by value', function () {
return initState()
.then(createRecord({ list: [{ a: 1, b: 2 }, { a: 1, b: 2 }, { a: 2, b: 3 }] }))
.then(operate(
maps
.removeByValue('list', 2)
.withContext(ctx => ctx.addListValue({ a: 1, b: 2 })) // matches only the first list value
.andReturn(maps.returnType.RANK)
))
.then(assertResultEql({ list: [1] }))
.then(assertRecordEql({ list: [{ a: 1 }, { a: 1, b: 2 }, { a: 2, b: 3 }] }))
.then(cleanup())
})
})
})

@@ -632,2 +681,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes map entries identified by one or more values', function () {
return initState()
.then(createRecord({ map: { a: { a: 1, b: 2, c: 3 }, b: { b: 2, c: 3, d: 4 } } }))
.then(operate(maps.removeByValueList('map', [1, 3]).withContext(ctx => ctx.addMapKey('a'))))
.then(assertRecordEql({ map: { a: { b: 2 }, b: { b: 2, c: 3, d: 4 } } }))
.then(cleanup())
})
})
})

@@ -662,2 +723,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes map entries identified by value range', function () {
return initState()
.then(createRecord({ list: [['a', 'b', 'c'], { a: 1, b: 2, c: 2, d: 3 }] }))
.then(operate(maps.removeByValueRange('list', 2, 3).withContext(ctx => ctx.addListIndex(-1))))
.then(assertRecordEql({ list: [['a', 'b', 'c'], { a: 1, d: 3 }] }))
.then(cleanup())
})
})
})

@@ -691,2 +764,18 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes map entries nearest to value and greater by relative rank', function () {
const mapContext = new Context()
.addListIndex(2)
.addListIndex(1)
return initState()
.then(createRecord({ list: ['a', 'b', ['c', { e: 2, j: 10, f: 15, a: 17 }], 'd', 'e'] }))
.then(orderByKeyValue('list', mapContext))
.then(operate(maps.removeByValueRelRankRange('list', 11, 1, 1).withContext(mapContext)))
.then(assertRecordEql({ list: ['a', 'b', ['c', { e: 2, j: 10, f: 15 }], 'd', 'e'] }))
.then(cleanup())
})
})
})

@@ -703,2 +792,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes a map entry identified by index', function () {
return initState()
.then(createRecord({ map: { nested: { a: 1, b: 2, c: 3 } } }))
.then(operate(maps.removeByIndex('map', 1).withContext(ctx => ctx.addMapValue({ a: 1, b: 2, c: 3 }))))
.then(assertRecordEql({ map: { nested: { a: 1, c: 3 } } }))
.then(cleanup())
})
})
})

@@ -733,2 +834,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes map entries identified by index range', function () {
return initState()
.then(createRecord({ map: { nested: { a: 1, b: 2, c: 2, d: 3 } } }))
.then(operate(maps.removeByIndexRange('map', 1, 2).withContext(ctx => ctx.addMapKey('nested'))))
.then(assertRecordEql({ map: { nested: { a: 1, d: 3 } } }))
.then(cleanup())
})
})
})

@@ -745,2 +858,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes a map entry identified by rank', function () {
return initState()
.then(createRecord({ list: [{ a: 3, b: 2, c: 1 }] }))
.then(operate(maps.removeByRank('list', 0).withContext(ctx => ctx.addListIndex(0))))
.then(assertRecordEql({ list: [{ a: 3, b: 2 }] }))
.then(cleanup())
})
})
})

@@ -766,2 +891,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('removes map entries identified by rank range', function () {
return initState()
.then(createRecord({ list: [{ a: 3, b: 2, c: 1 }] }))
.then(operate(maps.removeByRankRange('list', 0, 2).withContext(ctx => ctx.addListIndex(-1))))
.then(assertRecordEql({ list: [{ a: 3 }] }))
.then(cleanup())
})
})
})

@@ -793,2 +930,14 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('returns the size of the map', function () {
return initState()
.then(createRecord({ map: { nested: { a: 1, b: 2, c: 3 } } }))
.then(operate(maps.size('map').withContext(ctx => ctx.addMapKey('nested'))))
.then(assertResultEql({ map: 3 }))
.then(cleanup())
})
})
})

@@ -812,2 +961,19 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches a map entry identified by key', function () {
return initState()
.then(createRecord({ list: [{ a: 1, b: 2, c: 3 }, { b: 3 }] }))
.then(operate(
maps
.getByKey('list', 'b')
.withContext(ctx => ctx.addListIndex(0))
.andReturn(maps.returnType.KEY_VALUE)
))
.then(assertResultEql({ list: ['b', 2] }))
.then(cleanup())
})
})
})

@@ -841,2 +1007,21 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches map entries identified by key range', function () {
const mapContext = new Context().addListIndex(-1)
return initState()
.then(createRecord({ list: [{ b: 3, c: 4 }, { a: 1, b: 2, c: 3, d: 4 }] }))
.then(orderByKey('list', mapContext))
.then(operate(
maps
.getByKeyRange('list', 'b', 'd')
.withContext(mapContext)
.andReturn(maps.returnType.KEY)
))
.then(assertResultEql({ list: ['b', 'c'] }))
.then(cleanup())
})
})
})

@@ -868,2 +1053,21 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('retrieves map entries nearest to key and greater, by index', function () {
const mapContext = new Context().addListIndex(-1)
return initState()
.then(createRecord({ list: [{ a: 17, e: 2, f: 15, j: 10 }] }))
.then(orderByKey('list', mapContext))
.then(operate(
maps
.getByKeyRelIndexRange('list', 'f', 0)
.withContext(mapContext)
.andReturn(maps.returnType.KEY)
))
.then(assertResultEql({ list: ['f', 'j'] }))
.then(cleanup())
})
})
})

@@ -879,2 +1083,19 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches a map entry identified by value', function () {
return initState()
.then(createRecord({ map: { nested: { a: 1, b: 2, c: 2 } } }))
.then(operate(
maps
.getByValue('map', 2)
.withContext(ctx => ctx.addMapKey('nested'))
.andReturn(maps.returnType.KEY)
))
.then(assertResultSatisfy(result => eql(result.map.sort(), ['b', 'c'])))
.then(cleanup())
})
})
})

@@ -906,2 +1127,19 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches map entries identified by value range', function () {
return initState()
.then(createRecord({ list: [{ a: 2, b: 3, c: 4 }, { a: 1, b: 2, c: 2, d: 3 }] }))
.then(operate(
maps
.getByValueRange('list', 2, 3)
.withContext(ctx => ctx.addListIndex(1))
.andReturn(maps.returnType.VALUE)
))
.then(assertResultEql({ list: [2, 2] }))
.then(cleanup())
})
})
})

@@ -933,2 +1171,21 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('retrieves map entries nearest to value and greater by relative rank', function () {
const mapContext = new Context().addMapKey('nested')
return initState()
.then(createRecord({ map: { nested: { e: 2, j: 10, f: 15, a: 17 } } }))
.then(orderByKeyValue('map', mapContext))
.then(operate(
maps
.getByValueRelRankRange('map', 11, 1, 1)
.withContext(mapContext)
.andReturn(maps.returnType.KEY)
))
.then(assertResultEql({ map: ['a'] }))
.then(cleanup())
})
})
})

@@ -952,2 +1209,19 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches a map entry identified by index', function () {
return initState()
.then(createRecord({ list: [1, 2, 3, 4, { a: 1, b: 2, c: 3 }] }))
.then(operate(
maps
.getByIndex('list', 1)
.withContext(ctx => ctx.addListIndex(4))
.andReturn(maps.returnType.KEY_VALUE)
))
.then(assertResultEql({ list: ['b', 2] }))
.then(cleanup())
})
})
})

@@ -979,2 +1253,19 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches map entries identified by index range', function () {
return initState()
.then(createRecord({ list: [{ a: 1, b: 2, c: 2, d: 3 }] }))
.then(operate(
maps
.getByIndexRange('list', 1, 2)
.withContext(ctx => ctx.addListIndex(0))
.andReturn(maps.returnType.KEY_VALUE)
))
.then(assertResultEql({ list: ['b', 2, 'c', 2] }))
.then(cleanup())
})
})
})

@@ -998,2 +1289,19 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches a map entry identified by rank', function () {
return initState()
.then(createRecord({ map: { nested: { a: 3, b: 2, c: 1 } } }))
.then(operate(
maps
.getByRank('map', 0)
.withContext(ctx => ctx.addMapKey('nested'))
.andReturn(maps.returnType.VALUE)
))
.then(assertResultEql({ map: 1 }))
.then(cleanup())
})
})
})

@@ -1025,2 +1333,19 @@

})
context('with nested map context', function () {
helper.skipUnlessVersion('>= 4.6.0', this)
it('fetches map entries identified by rank range', function () {
return initState()
.then(createRecord({ list: [{ a: 3, b: 2, c: 1 }] }))
.then(operate(
maps
.getByRankRange('list', 0, 2)
.withContext(ctx => ctx.addListIndex(0))
.andReturn(maps.returnType.VALUE)
))
.then(assertResultEql({ list: [1, 2] }))
.then(cleanup())
})
})
})

@@ -1097,3 +1422,3 @@

.then(operate(maps.getByIndexRange('map', 0, 2, maps.returnType.KEY)))
.then(assertResultEql({ map: [ 'a', 'b' ] }))
.then(assertResultEql({ map: ['a', 'b'] }))
.then(cleanup())

@@ -1116,3 +1441,3 @@ })

.then(operate(maps.getByIndexRange('map', 0, 2, maps.returnType.VALUE)))
.then(assertResultEql({ map: [ 1, 2 ] }))
.then(assertResultEql({ map: [1, 2] }))
.then(cleanup())

@@ -1126,3 +1451,3 @@ })

.then(operate(maps.getByIndex('map', 0, maps.returnType.KEY_VALUE)))
.then(assertResultEql({ map: [ 'a', 1 ] }))
.then(assertResultEql({ map: ['a', 1] }))
.then(cleanup())

@@ -1136,3 +1461,3 @@ })

.then(operate(maps.getByIndexRange('map', 0, 2, maps.returnType.KEY_VALUE)))
.then(assertResultEql({ map: [ 'a', 1, 'b', 2 ] }))
.then(assertResultEql({ map: ['a', 1, 'b', 2] }))
.then(cleanup())

@@ -1139,0 +1464,0 @@ })

@@ -34,3 +34,3 @@ // *****************************************************************************

context('Operations', function () {
let client = helper.client
const client = helper.client
let key = null

@@ -40,3 +40,3 @@

key = keygen.string(helper.namespace, helper.set, { prefix: 'test/operate' })()
let bins = {
const bins = {
string: 'abc',

@@ -51,6 +51,6 @@ int: 123,

}
let policy = new Aerospike.WritePolicy({
const policy = new Aerospike.WritePolicy({
exists: Aerospike.policy.exists.CREATE_OR_REPLACE
})
let meta = { ttl: 60 }
const meta = { ttl: 60 }
return client.put(key, bins, meta, policy)

@@ -64,3 +64,3 @@ })

it('writes a new value to a bin', function () {
let ops = [
const ops = [
op.write('string', 'def'),

@@ -79,12 +79,12 @@ op.write('int', 432),

.then(record => {
expect(record.bins['string']).to.equal('def')
expect(record.bins['int']).to.equal(432)
expect(record.bins['double1']).to.equal(2.34)
expect(record.bins['double2']).to.equal(2.0)
expect(new GeoJSON(record.bins['geo']).toJSON()).to.eql(
expect(record.bins.string).to.equal('def')
expect(record.bins.int).to.equal(432)
expect(record.bins.double1).to.equal(2.34)
expect(record.bins.double2).to.equal(2.0)
expect(new GeoJSON(record.bins.geo).toJSON()).to.eql(
{ type: 'Point', coordinates: [123.456, 1.308] }
)
expect(record.bins['blob'].equals(Buffer.from('bar'))).to.be.ok()
expect(record.bins['list']).to.eql([2, 3, 4])
expect(record.bins['map']).to.eql({ d: 4, e: 5, f: 6 })
expect(record.bins.blob.equals(Buffer.from('bar'))).to.be.ok()
expect(record.bins.list).to.eql([2, 3, 4])
expect(record.bins.map).to.eql({ d: 4, e: 5, f: 6 })
})

@@ -94,3 +94,3 @@ })

it('deletes a bin by writing null to it', function () {
let ops = [
const ops = [
op.write('string', null)

@@ -109,3 +109,3 @@ ]

it('adds an integer value to a bin', function () {
let ops = [
const ops = [
op.add('int', 432)

@@ -117,3 +117,3 @@ ]

.then(record => {
expect(record.bins['int']).to.equal(555)
expect(record.bins.int).to.equal(555)
})

@@ -123,3 +123,3 @@ })

it('adds a double value to a bin', function () {
let ops = [
const ops = [
op.add('double1', 3.45),

@@ -132,4 +132,4 @@ op.add('double2', new Double(3.14159))

.then(record => {
expect(record.bins['double1']).to.equal(4.68)
expect(record.bins['double2']).to.equal(4.14159)
expect(record.bins.double1).to.equal(4.68)
expect(record.bins.double2).to.equal(4.14159)
})

@@ -139,3 +139,3 @@ })

it('can be called using the "incr" alias', function () {
let ops = [
const ops = [
op.incr('int', 432)

@@ -147,3 +147,3 @@ ]

.then(record => {
expect(record.bins['int']).to.equal(555)
expect(record.bins.int).to.equal(555)
})

@@ -153,3 +153,3 @@ })

it('returns a parameter error when trying to add a string value', function () {
let ops = [
const ops = [
op.add('int', 'abc')

@@ -165,3 +165,3 @@ ]

it('appends a string value to a string bin', function () {
let ops = [
const ops = [
op.append('string', 'def')

@@ -173,3 +173,3 @@ ]

.then(record => {
expect(record.bins['string']).to.equal('abcdef')
expect(record.bins.string).to.equal('abcdef')
})

@@ -179,3 +179,3 @@ })

it('returns a parameter error when trying to append a numeric value', function () {
let ops = [
const ops = [
op.append('string', 123)

@@ -191,3 +191,3 @@ ]

it('prepends a string value to a string bin', function () {
let ops = [
const ops = [
op.prepend('string', 'def')

@@ -199,3 +199,3 @@ ]

.then(record => {
expect(record.bins['string']).to.equal('defabc')
expect(record.bins.string).to.equal('defabc')
})

@@ -205,3 +205,3 @@ })

it('returns a parameter error when trying to prepend a numeric value', function () {
let ops = [
const ops = [
op.prepend('string', 123)

@@ -232,5 +232,5 @@ ]

let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/operate/ttl' })()
let bins = { i: 123, s: 'abc' }
let meta = { ttl: 1000 }
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/operate/ttl' })()
const bins = { i: 123, s: 'abc' }
const meta = { ttl: 1000 }

@@ -277,3 +277,3 @@ client.put(key, bins, meta, function (err) {

const notExistentKey = keygen.string(helper.namespace, helper.set, { prefix: 'test/operate/doesNotExist' })()
const ops = [ op.write('i', 49) ]
const ops = [op.write('i', 49)]

@@ -296,3 +296,3 @@ return client.operate(notExistentKey, ops, {}, policy)

it('executes the operation if the generation matches', function () {
const ops = [ op.add('int', 7) ]
const ops = [op.add('int', 7)]
const meta = { gen: 1 }

@@ -306,3 +306,3 @@

it('rejects the operation if the generation does not match', function () {
const ops = [ op.add('int', 7) ]
const ops = [op.add('int', 7)]
const meta = { gen: 99 }

@@ -329,3 +329,3 @@

it('returns list and map bins as byte buffers', function () {
const ops = [ op.read('int'), op.read('list'), op.read('map') ]
const ops = [op.read('int'), op.read('list'), op.read('map')]

@@ -343,3 +343,3 @@ return client.operate(key, ops, null, policy)

it('calls the callback function with the results of the operation', function (done) {
let ops = [
const ops = [
op.read('int')

@@ -350,3 +350,3 @@ ]

if (error) throw error
expect(result.bins['int']).to.equal(123)
expect(result.bins.int).to.equal(123)
done()

@@ -362,3 +362,3 @@ })

.then(record => {
expect(record.bins['int']).to.equal(357)
expect(record.bins.int).to.equal(357)
})

@@ -373,3 +373,3 @@ })

.then(record => {
expect(record.bins['int']).to.equal(357)
expect(record.bins.int).to.equal(357)
})

@@ -384,3 +384,3 @@ })

.then(record => {
expect(record.bins['string']).to.equal('abcdef')
expect(record.bins.string).to.equal('abcdef')
})

@@ -395,3 +395,3 @@ })

.then(record => {
expect(record.bins['string']).to.equal('defabc')
expect(record.bins.string).to.equal('defabc')
})

@@ -398,0 +398,0 @@ })

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -30,3 +30,3 @@ // Licensed under the Apache License, Version 2.0 (the "License")

it('sets totalTimeout to zero', function () {
let subject = new BasePolicy({
const subject = new BasePolicy({
totalTimeout: 0

@@ -43,3 +43,3 @@ })

it('sets the policy values from a value object', function () {
let subject = new Aerospike.ApplyPolicy({
const subject = new Aerospike.ApplyPolicy({
socketTimeout: 1000,

@@ -70,3 +70,3 @@ totalTimeout: 2000,

it('sets the policy values from a value object', function () {
let subject = new Aerospike.WritePolicy({
const subject = new Aerospike.WritePolicy({
socketTimeout: 1000,

@@ -99,3 +99,3 @@ totalTimeout: 2000,

it('sets the policy values from a value object', function () {
let subject = new Aerospike.ReadPolicy({
const subject = new Aerospike.ReadPolicy({
socketTimeout: 1000,

@@ -124,3 +124,3 @@ totalTimeout: 2000,

it('sets the policy values from a value object', function () {
let subject = new Aerospike.BatchPolicy({
const subject = new Aerospike.BatchPolicy({
socketTimeout: 1000,

@@ -149,3 +149,3 @@ totalTimeout: 2000,

it('sets the policy values from a value object', function () {
let subject = new Aerospike.InfoPolicy({
const subject = new Aerospike.InfoPolicy({
totalTimeout: 1000,

@@ -166,3 +166,3 @@ sendAsIs: true,

it('sets the policy values from a value object', function () {
let subject = new Aerospike.RemovePolicy({
const subject = new Aerospike.RemovePolicy({
socketTimeout: 1000,

@@ -193,3 +193,3 @@ totalTimeout: 2000,

it('sets the policy values from a value object', function () {
let subject = new Aerospike.OperatePolicy({
const subject = new Aerospike.OperatePolicy({
socketTimeout: 1000,

@@ -223,3 +223,3 @@ totalTimeout: 2000,

it('sets the policy values from a value object', function () {
let subject = new Aerospike.ScanPolicy({
const subject = new Aerospike.ScanPolicy({
socketTimeout: 1000,

@@ -244,3 +244,3 @@ totalTimeout: 2000,

it('sets the policy values from a value object', function () {
let subject = new Aerospike.QueryPolicy({
const subject = new Aerospike.QueryPolicy({
socketTimeout: 1000,

@@ -247,0 +247,0 @@ totalTimeout: 2000,

@@ -49,4 +49,4 @@ // *****************************************************************************

{ name: 'string map non-match', ms: { a: 'tomato', b: 'cuccumber' } },
{ name: 'string mapkeys match', mks: { 'banana': 1, 'blueberry': 2 } },
{ name: 'string mapkeys non-match', mks: { 'tomato': 3, 'cuccumber': 4 } },
{ name: 'string mapkeys match', mks: { banana: 1, blueberry: 2 } },
{ name: 'string mapkeys non-match', mks: { tomato: 3, cuccumber: 4 } },
{ name: 'point match', g: GeoJSON.Point(103.913, 1.308) },

@@ -61,6 +61,6 @@ { name: 'point non-match', g: GeoJSON.Point(-122.101, 37.421) },

before(() => {
let entries = samples.entries()
let rgen = () => entries.next().value[1]
let kgen = keygen.string(helper.namespace, testSet, { prefix: 'test/predexp/', random: false })
let mgen = metagen.constant({ ttl: 300 })
const entries = samples.entries()
const rgen = () => entries.next().value[1]
const kgen = keygen.string(helper.namespace, testSet, { prefix: 'test/predexp/', random: false })
const mgen = metagen.constant({ ttl: 300 })
return putgen.put(samples.length, kgen, rgen, mgen)

@@ -449,4 +449,4 @@ })

it('matches the record last update time', function () {
let t1 = timeNanos(300)
let t2 = timeNanos(-300)
const t1 = timeNanos(300)
const t2 = timeNanos(-300)

@@ -472,4 +472,4 @@ const query = client.query(helper.namespace, testSet)

it('matches the record void time time', function () {
let t1 = timeNanos()
let t2 = timeNanos(600)
const t1 = timeNanos()
const t2 = timeNanos(600)

@@ -495,4 +495,4 @@ const query = client.query(helper.namespace, testSet)

it('matches the record void time time', function () {
let mod = 5
let rem = 3
const mod = 5
const rem = 3

@@ -507,3 +507,3 @@ const query = client.query(helper.namespace, testSet)

return query.results().then(results => {
let digests = results.map(rec => rec.key.digest)
const digests = results.map(rec => rec.key.digest)
expect(digests.every(

@@ -510,0 +510,0 @@ // modulo is calculated from the last 4 bytes of the digest

@@ -113,4 +113,4 @@ // *****************************************************************************

context('bins with various data types', function () {
let meta = { ttl: 600 }
let policy = new Aerospike.WritePolicy({
const meta = { ttl: 600 }
const policy = new Aerospike.WritePolicy({
exists: Aerospike.policy.exists.CREATE_OR_REPLACE

@@ -168,7 +168,9 @@ })

it('writes bin with array value as list and reads it back', function (done) {
var record = { list: [ 1, 'foo', 1.23, new Double(3.14), Buffer.from('bar'),
GeoJSON.Point(103.8, 1.283), [1, 2, 3], { a: 1, b: 2 } ]
var record = {
list: [1, 'foo', 1.23, new Double(3.14), Buffer.from('bar'),
GeoJSON.Point(103.8, 1.283), [1, 2, 3], { a: 1, b: 2 }]
}
var expected = { list: [ 1, 'foo', 1.23, 3.14, Buffer.from('bar'),
'{"type":"Point","coordinates":[103.8,1.283]}', [1, 2, 3], { a: 1, b: 2 } ]
var expected = {
list: [1, 'foo', 1.23, 3.14, Buffer.from('bar'),
'{"type":"Point","coordinates":[103.8,1.283]}', [1, 2, 3], { a: 1, b: 2 }]
}

@@ -179,21 +181,25 @@ putGetVerify(record, expected, done)

it('writes bin with object value as map and reads it back', function (done) {
var record = { map: {
a: 1,
b: 'foo',
c: 1.23,
d: new Double(3.14),
e: Buffer.from('bar'),
f: GeoJSON.Point(103.8, 1.283),
g: [1, 2, 3],
h: { a: 1, b: 2 } }
var record = {
map: {
a: 1,
b: 'foo',
c: 1.23,
d: new Double(3.14),
e: Buffer.from('bar'),
f: GeoJSON.Point(103.8, 1.283),
g: [1, 2, 3],
h: { a: 1, b: 2 }
}
}
var expected = { map: {
a: 1,
b: 'foo',
c: 1.23,
d: 3.14,
e: Buffer.from('bar'),
f: '{"type":"Point","coordinates":[103.8,1.283]}',
g: [1, 2, 3],
h: { a: 1, b: 2 } }
var expected = {
map: {
a: 1,
b: 'foo',
c: 1.23,
d: 3.14,
e: Buffer.from('bar'),
f: '{"type":"Point","coordinates":[103.8,1.283]}',
g: [1, 2, 3],
h: { a: 1, b: 2 }
}
}

@@ -204,15 +210,18 @@ putGetVerify(record, expected, done)

it.skip('writes bin with Map value as map and reads it back', function (done) {
var record = { map: new Map([['a', 1], ['b', 'foo'], ['c', 1.23],
['d', new Double(3.14)], ['e', Buffer.from('bar')], ['f', GeoJSON.Point(103.8, 1.283)],
['g', [1, 2, 3]], ['h', { a: 1, b: 2 }]])
var record = {
map: new Map([['a', 1], ['b', 'foo'], ['c', 1.23],
['d', new Double(3.14)], ['e', Buffer.from('bar')], ['f', GeoJSON.Point(103.8, 1.283)],
['g', [1, 2, 3]], ['h', { a: 1, b: 2 }]])
}
var expected = { map: {
a: 1,
b: 'foo',
c: 1.23,
d: 3.14,
e: Buffer.from('bar'),
f: '{"type":"Point","coordinates":[103.8,1.283]}',
g: [1, 2, 3],
h: { a: 1, b: 2 } }
var expected = {
map: {
a: 1,
b: 'foo',
c: 1.23,
d: 3.14,
e: Buffer.from('bar'),
f: '{"type":"Point","coordinates":[103.8,1.283]}',
g: [1, 2, 3],
h: { a: 1, b: 2 }
}
}

@@ -257,4 +266,4 @@ putGetVerify(record, expected, done)

it('should write a bin with a name of max. length 15', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/put/' })()
let bins = { 'bin-name-len-15': 'bin name with 15 chars' }
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/put/' })()
const bins = { 'bin-name-len-15': 'bin name with 15 chars' }

@@ -271,4 +280,4 @@ return client.put(key, bins)

it('should return a parameter error when bin length exceeds 15 chars', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/put/' })()
let bins = { 'bin-name-size-16': 'bin name with 16 chars' }
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/put/' })()
const bins = { 'bin-name-size-16': 'bin name with 16 chars' }

@@ -499,4 +508,4 @@ return client.put(key, bins)

it('does not create a key that does not exist yet', function () {
let key = keygen.integer(helper.namespace, helper.set)()
let policy = new Aerospike.policy.WritePolicy({
const key = keygen.integer(helper.namespace, helper.set)()
const policy = new Aerospike.policy.WritePolicy({
exists: Aerospike.policy.exists.UPDATE

@@ -514,4 +523,4 @@ })

it('does not update a record if it already exists', function () {
let key = keygen.integer(helper.namespace, helper.set)()
let policy = new Aerospike.policy.WritePolicy({
const key = keygen.integer(helper.namespace, helper.set)()
const policy = new Aerospike.policy.WritePolicy({
exists: Aerospike.policy.exists.CREATE

@@ -531,4 +540,4 @@ })

it('updates record if generation matches', function () {
let key = keygen.integer(helper.namespace, helper.set)()
let policy = new Aerospike.WritePolicy({
const key = keygen.integer(helper.namespace, helper.set)()
const policy = new Aerospike.WritePolicy({
gen: Aerospike.policy.gen.EQ

@@ -550,4 +559,4 @@ })

it('does not update record if generation does not match', function () {
let key = keygen.integer(helper.namespace, helper.set)()
let policy = new Aerospike.WritePolicy({
const key = keygen.integer(helper.namespace, helper.set)()
const policy = new Aerospike.WritePolicy({
gen: Aerospike.policy.gen.EQ

@@ -554,0 +563,0 @@ })

@@ -60,4 +60,4 @@ // *****************************************************************************

{ name: 'string map non-match', ms: { a: 'tomato', b: 'cuccumber' } },
{ name: 'string mapkeys match', mks: { 'banana': 1, 'blueberry': 2 } },
{ name: 'string mapkeys non-match', mks: { 'tomato': 3, 'cuccumber': 4 } },
{ name: 'string mapkeys match', mks: { banana: 1, blueberry: 2 } },
{ name: 'string mapkeys non-match', mks: { tomato: 3, cuccumber: 4 } },
{ name: 'point match', g: GeoJSON.Point(103.913, 1.308) },

@@ -114,5 +114,5 @@ { name: 'point non-match', g: GeoJSON.Point(-122.101, 37.421) },

before(() => {
let sampleGen = () => samples.pop()
let kgen = keygen.string(helper.namespace, testSet, { prefix: 'test/query/', random: false })
let mgen = metagen.constant({ ttl: 300 })
const sampleGen = () => samples.pop()
const kgen = keygen.string(helper.namespace, testSet, { prefix: 'test/query/', random: false })
const mgen = metagen.constant({ ttl: 300 })
return Promise.all([

@@ -200,7 +200,7 @@ putgen.put(numberOfSamples, kgen, sampleGen, mgen)

it('returns the key if it was stored on the server', function (done) {
let uniqueKey = 'test/query/record_with_stored_key'
let key = new Aerospike.Key(helper.namespace, testSet, uniqueKey)
let record = { name: uniqueKey }
let meta = { ttl: 300 }
let policy = new Aerospike.WritePolicy({
const uniqueKey = 'test/query/record_with_stored_key'
const key = new Aerospike.Key(helper.namespace, testSet, uniqueKey)
const record = { name: uniqueKey }
const meta = { ttl: 300 }
const policy = new Aerospike.WritePolicy({
key: Aerospike.policy.key.SEND

@@ -248,8 +248,8 @@ })

it('should raise client errors asynchronously', function (done) {
let invalidPolicy = new Aerospike.QueryPolicy({
const invalidPolicy = new Aerospike.QueryPolicy({
totalTimeout: 'not a valid timeout'
})
let query = client.query('test')
let stream = query.foreach(invalidPolicy)
const query = client.query('test')
const stream = query.foreach(invalidPolicy)
// if error is raised synchronously we will never reach here

@@ -263,5 +263,5 @@ stream.on('error', error => {

it('attaches event handlers to the stream', function (done) {
let query = client.query(helper.namespace, testSet)
const query = client.query(helper.namespace, testSet)
let dataHandlerCalled = false
let stream = query.foreach(null,
const stream = query.foreach(null,
(_record) => {

@@ -291,3 +291,3 @@ dataHandlerCalled = true

it('throws a type error if the comparison value is of invalid type', function () {
let fn = () => filter.equal('str', { foo: 'bar' })
const fn = () => filter.equal('str', { foo: 'bar' })
expect(fn).to.throw(TypeError)

@@ -341,3 +341,3 @@ })

it('throws a type error if the comparison value is of invalid type', function () {
let fn = () => filter.contains('list', { foo: 'bar' }, LIST)
const fn = () => filter.contains('list', { foo: 'bar' }, LIST)
expect(fn).to.throw(TypeError)

@@ -437,3 +437,3 @@ })

it('returns a Promise that resolves into the query results', function () {
let query = client.query(helper.namespace, testSet)
const query = client.query(helper.namespace, testSet)
query.where(filter.equal('i', 5))

@@ -493,6 +493,6 @@

it('returns a Promise that resolves to the result of the aggregation', function () {
let args = {
const args = {
filters: [filter.equal('name', 'aggregate')]
}
let query = client.query(helper.namespace, testSet, args)
const query = client.query(helper.namespace, testSet, args)
return query.apply('udf', 'count')

@@ -519,6 +519,6 @@ .then(result => {

it('returns a Promise that resolves to a Job', function () {
let args = {
const args = {
filters: [filter.equal('name', 'aggregate')]
}
let query = client.query(helper.namespace, testSet, args)
const query = client.query(helper.namespace, testSet, args)
return query.background('udf', 'noop')

@@ -533,4 +533,4 @@ .then(job => {

it('should stop the query when the stream is aborted', function (done) {
let query = client.query(helper.namespace, testSet)
let stream = query.foreach()
const query = client.query(helper.namespace, testSet)
const stream = query.foreach()
let recordsReceived = 0

@@ -537,0 +537,0 @@ stream.on('data', () => {

@@ -32,6 +32,6 @@ // *****************************************************************************

describe('client.remove()', function () {
let client = helper.client
const client = helper.client
it('removes an existing record', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/' })()
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/' })()

@@ -45,3 +45,3 @@ return client.put(key, { str: 'abcde' })

it('returns an error when trying to remove a non-existing key', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/' })()
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/' })()

@@ -55,4 +55,4 @@ return client.remove(key)

it('should remove the record if the generation matches', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/' })()
let policy = new Aerospike.RemovePolicy({
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/' })()
const policy = new Aerospike.RemovePolicy({
gen: Aerospike.policy.gen.EQ,

@@ -71,4 +71,4 @@ generation: 1

it('should not remove the record if the generation does not match', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/' })()
let policy = new Aerospike.RemovePolicy({
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/' })()
const policy = new Aerospike.RemovePolicy({
gen: Aerospike.policy.gen.EQ,

@@ -93,5 +93,5 @@ generation: 1

it('should apply the durable delete policy', function () {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/gen/' })()
let record = recgen.record({ i: valgen.integer(), s: valgen.string(), b: valgen.bytes() })()
let policy = new Aerospike.RemovePolicy({
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove/gen/' })()
const record = recgen.record({ i: valgen.integer(), s: valgen.string(), b: valgen.bytes() })()
const policy = new Aerospike.RemovePolicy({
durableDelete: true

@@ -98,0 +98,0 @@ })

@@ -35,12 +35,12 @@ // *****************************************************************************

context('Scans', function () {
let client = helper.client
let testSet = 'test/scan-' + Math.floor(Math.random() * 100000)
let numberOfRecords = 100
const client = helper.client
const testSet = 'test/scan-' + Math.floor(Math.random() * 100000)
const numberOfRecords = 100
before(() => helper.udf.register('udf.lua')
.then(() => {
let kgen = keygen.string(helper.namespace, testSet, { prefix: 'test/scan/', random: false })
let rgen = recgen.record({ i: valgen.integer(), s: valgen.string() })
let mgen = metagen.constant({ ttl: 300 })
let policy = new Aerospike.WritePolicy({
const kgen = keygen.string(helper.namespace, testSet, { prefix: 'test/scan/', random: false })
const rgen = recgen.record({ i: valgen.integer(), s: valgen.string() })
const mgen = metagen.constant({ ttl: 300 })
const policy = new Aerospike.WritePolicy({
totalTimeout: 1000,

@@ -127,5 +127,5 @@ key: Aerospike.policy.key.SEND,

it('attaches event handlers to the stream', function (done) {
let scan = client.scan(helper.namespace, testSet)
const scan = client.scan(helper.namespace, testSet)
let dataHandlerCalled = false
let stream = scan.foreach(null,
const stream = scan.foreach(null,
(_record) => {

@@ -143,4 +143,4 @@ dataHandlerCalled = true

it('sets a scan policy', function (done) {
let scan = client.scan(helper.namespace, testSet)
let policy = new Aerospike.ScanPolicy({
const scan = client.scan(helper.namespace, testSet)
const policy = new Aerospike.ScanPolicy({
totalTimeout: 1000,

@@ -152,3 +152,3 @@ socketTimeout: 1000,

let stream = scan.foreach(policy)
const stream = scan.foreach(policy)
stream.on('data', () => stream.abort())

@@ -167,4 +167,4 @@ stream.on('error', error => {

it('should return only meta data', function (done) {
let scan = client.scan(helper.namespace, testSet, { nobins: true })
let stream = scan.foreach()
const scan = client.scan(helper.namespace, testSet, { nobins: true })
const stream = scan.foreach()
stream.on('data', record => {

@@ -195,3 +195,3 @@ expect(record.bins).to.be.empty()

it('should only scan approx. half of the records', function (done) {
let scan = client.scan(helper.namespace, testSet, {
const scan = client.scan(helper.namespace, testSet, {
percent: 50,

@@ -241,3 +241,3 @@ nobins: true

stream.on('error', error => { throw error })
stream.on('data', record => expect(record.bins['x']).to.equal(token))
stream.on('data', record => expect(record.bins.x).to.equal(token))
stream.on('end', done)

@@ -249,3 +249,3 @@ })

it('returns a Promise that resolves to a Job', function () {
let backgroundScan = client.scan(helper.namespace, testSet)
const backgroundScan = client.scan(helper.namespace, testSet)
return backgroundScan.background('udf', 'noop')

@@ -260,4 +260,4 @@ .then(job => {

it('should stop the scan when the stream is aborted', function (done) {
let scan = client.scan(helper.namespace, testSet)
let stream = scan.foreach()
const scan = client.scan(helper.namespace, testSet)
const stream = scan.foreach()
let recordsReceived = 0

@@ -264,0 +264,0 @@ stream.on('data', () => {

@@ -88,7 +88,7 @@ // *****************************************************************************

it('should read the record w/ a key send policy', function (done) {
let key = keygen.string(helper.namespace, helper.set, { prefix: 'test/select/' })()
let meta = { ttl: 1000 }
let bins = recgen.record({ i: valgen.integer(), s: valgen.string(), b: valgen.bytes() })()
let selected = ['i', 's']
let policy = new Aerospike.ReadPolicy({
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/select/' })()
const meta = { ttl: 1000 }
const bins = recgen.record({ i: valgen.integer(), s: valgen.string(), b: valgen.bytes() })()
const selected = ['i', 's']
const policy = new Aerospike.ReadPolicy({
key: Aerospike.policy.key.SEND

@@ -95,0 +95,0 @@ })

@@ -55,3 +55,3 @@ // *****************************************************************************

UDFHelper.prototype.register = function (filename) {
let script = path.join(__dirname, filename)
const script = path.join(__dirname, filename)
return this.client.udfRegister(script)

@@ -76,3 +76,3 @@ .then(job => job.wait(50))

IndexHelper.prototype.create = function (indexName, setName, binName, dataType, indexType) {
let index = {
const index = {
ns: options.namespace,

@@ -133,6 +133,6 @@ set: setName,

results.forEach(response => {
let info = Info.parse(response.info)
this.edition = info['edition']
this.build = info['build']
let features = info['features']
const info = Info.parse(response.info)
this.edition = info.edition
this.build = info.build
const features = info.features
if (Array.isArray(features)) {

@@ -146,6 +146,6 @@ features.forEach(feature => this.features.add(feature))

ServerInfoHelper.prototype.fetchNamespaceConfig = function (ns) {
let nsKey = 'namespace/' + ns
const nsKey = 'namespace/' + ns
return client.infoAny(nsKey)
.then(results => {
let info = Info.parse(results)
const info = Info.parse(results)
this.nsconfig = info[nsKey]

@@ -173,3 +173,3 @@ })

}
let env = {
const env = {
NODE_PATH: path.join(process.cwd(), 'node_modules')

@@ -176,0 +176,0 @@ }

@@ -92,3 +92,3 @@ // *****************************************************************************

it('deletes all records with an older update timestamp', function (done) {
this.timeout(5000)
this.timeout(10000)
const ns = helper.namespace

@@ -95,0 +95,0 @@ const set = setgen()

@@ -58,3 +58,3 @@ // *****************************************************************************

it('should register a module with an info policy', function (done) {
let policy = new Aerospike.InfoPolicy({
const policy = new Aerospike.InfoPolicy({
timeout: 1000,

@@ -78,3 +78,3 @@ sendAsIs: true,

it('should register a module as Lua language with an info policy', function (done) {
let policy = new Aerospike.InfoPolicy({
const policy = new Aerospike.InfoPolicy({
timeout: 1000,

@@ -81,0 +81,0 @@ sendAsIs: true,

@@ -98,4 +98,4 @@ // *****************************************************************************

let options
if (process.env['OPTIONS']) {
options = process.env['OPTIONS'].trim().split(' ')
if (process.env.OPTIONS) {
options = process.env.OPTIONS.trim().split(' ')
options = parser.parse(options)

@@ -112,3 +112,3 @@ } else {

// enable debug stacktraces
process.env['AEROSPIKE_DEBUG_STACKTRACES'] = process.env['AEROSPIKE_DEBUG_STACKTRACES'] || true
process.env.AEROSPIKE_DEBUG_STACKTRACES = process.env.AEROSPIKE_DEBUG_STACKTRACES || true

@@ -150,4 +150,4 @@ function testDir () {

config.hosts = [host]
} else if (process.env['AEROSPIKE_HOSTS']) {
config.hosts = process.env['AEROSPIKE_HOSTS']
} else if (process.env.AEROSPIKE_HOSTS) {
config.hosts = process.env.AEROSPIKE_HOSTS
}

@@ -154,0 +154,0 @@

// *****************************************************************************
// Copyright 2013-2018 Aerospike, Inc.
// Copyright 2013-2019 Aerospike, Inc.
//

@@ -37,4 +37,4 @@ // Licensed under the Apache License, Version 2.0 (the "License")

function createTempFile (fn, data) {
let source = generateTestSource(fn, data)
let temp = tmp.fileSync({ postfix: '.js' })
const source = generateTestSource(fn, data)
const temp = tmp.fileSync({ postfix: '.js' })
fs.writeSync(temp.fd, source)

@@ -45,3 +45,3 @@ return temp.name

function forkAndRun (fn, env, data) {
let temp = createTempFile(fn, data)
const temp = createTempFile(fn, data)
return childProcess.fork(temp, { env: env })

@@ -52,3 +52,3 @@ }

return new Promise((resolve, reject) => {
let child = forkAndRun(fn, env, data)
const child = forkAndRun(fn, env, data)
child.on('message', message => {

@@ -55,0 +55,0 @@ child.disconnect()

@@ -24,39 +24,2 @@ // *****************************************************************************

describe('utils.hostsToString() #noserver', function () {
it('returns a hosts string unmodified', function () {
let hosts = utils.hostsToString('localhost:3000')
expect(hosts).to.equal('localhost:3000')
})
it('converts a single host name & port to a string', function () {
let hosts = utils.hostsToString([{ addr: 'localhost', port: 3000 }])
expect(hosts).to.equal('localhost:3000')
})
it('converts a single IPv4 & port to a string', function () {
let hosts = utils.hostsToString([{ addr: '127.0.0.1', port: 3000 }])
expect(hosts).to.equal('127.0.0.1:3000')
})
it('encloses IPv6 addresses in brackets', function () {
let hosts = utils.hostsToString([{ addr: '2001::1000', port: 3000 }])
expect(hosts).to.equal('[2001::1000]:3000')
})
it('omits the port number if missing from the address', function () {
let hosts = utils.hostsToString([{ addr: 'localhost' }])
expect(hosts).to.equal('localhost')
})
it('concatenates an array of host addresses into a comma-separated list', function () {
let hosts = utils.hostsToString([{ addr: 'node1', port: 3000 }, { addr: 'node2', port: 3000 }])
expect(hosts).to.equal('node1:3000,node2:3000')
})
it('handles mixed addresses with hostnames, IPv4 & IPv6 addresses', function () {
let hosts = utils.hostsToString([{ addr: 'localhost', port: 3000 }, { addr: '127.0.0.1', port: 3100 }, { addr: '2001::1000', port: 3200 }, { addr: 'foo' }])
expect(hosts).to.equal('localhost:3000,127.0.0.1:3100,[2001::1000]:3200,foo')
})
})
describe('utils.parseHostString() #noserver', function () {

@@ -105,3 +68,3 @@ it('parses a domain name', function () {

var host = utils.parseHostString('[fde4:8dba:82e1::c4]')
expect(host).to.eql({ addr: '[fde4:8dba:82e1::c4]', port: 3000 })
expect(host).to.eql({ addr: 'fde4:8dba:82e1::c4', port: 3000 })
})

@@ -111,3 +74,3 @@

var host = utils.parseHostString('[fde4:8dba:82e1::c4]:3333')
expect(host).to.eql({ addr: '[fde4:8dba:82e1::c4]', port: 3333 })
expect(host).to.eql({ addr: 'fde4:8dba:82e1::c4', port: 3333 })
})

@@ -117,3 +80,3 @@

var host = utils.parseHostString('[fde4:8dba:82e1::c4]:aero.tls:3333')
expect(host).to.eql({ addr: '[fde4:8dba:82e1::c4]', tls: 'aero.tls', port: 3333 })
expect(host).to.eql({ addr: 'fde4:8dba:82e1::c4', tls: 'aero.tls', port: 3333 })
})

@@ -123,3 +86,3 @@

var host = utils.parseHostString('[fde4:8dba:82e1::c4]:aero.tls')
expect(host).to.eql({ addr: '[fde4:8dba:82e1::c4]', tls: 'aero.tls', port: 3000 })
expect(host).to.eql({ addr: 'fde4:8dba:82e1::c4', tls: 'aero.tls', port: 3000 })
})

@@ -133,8 +96,1 @@

})
describe('utils.parseHostsString() #noserver', function () {
it('parses a comma separate list of hosts', function () {
var hosts = utils.parseHostsString('aero.local:aero.tls:3000,192.168.33.10:3000,[fde4:8dba:82e1::c4]')
expect(hosts.length).to.equal(3)
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc