Skip to content

Commit

Permalink
Merge pull request #551 from aerospike/stage
Browse files Browse the repository at this point in the history
Nodejs-Release-5.4.0
  • Loading branch information
DomPeliniAerospike authored Mar 31, 2023
2 parents 158e8f1 + c7f2248 commit 69138fd
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 20 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ The Aerospike Node.js client is a Node.js add-on module, written using V8.
The client is compatible with Node.js 19, 18 (LTS), 16 (LTS) and 14 (LTS).
It supports the following operating systems:
- RHEL 8/9
- Debian 10/11
- Ubuntu 18.04/20.04/22.04 (Focal, Jammy, Bionic)
- Debian 10 (x86_64 architecture only)
- Debian 11
- Ubuntu 20.04/22.04 (Focal Fossa, Jammy Jellyfish)
- Many Linux distributions compatible with one of the above OS releases.
- macOS versions 11/12/13 are also supported. (Node.js 14 install unavailable on M1 Mac systems)

Expand Down
1 change: 1 addition & 0 deletions lib/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ exports.writeFlags = as.lists.writeFlags
* @property {number} COUNT - Return count of items selected.
* @property {number} VALUE - Return value for single key read and value list
* for range read.
* @property {number} EXISTS - Return true if count > 0.
*/
exports.returnType = as.lists.returnType

Expand Down
5 changes: 4 additions & 1 deletion lib/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,11 @@ exports.writeFlags = as.maps.writeFlags
* range read.
* @property {number} VALUE - Return value for single key read and value list
* for range read.
* @property {number} KEY_VALUE - Return map items keys and values as an Array,
* @property {number} KEY_VALUE - Return map items keys and values as an Array.
* i.e. [key1, value1, key2, value2, ...].
* @property {number} EXISTS - Return true if count > 0.
* @property {number} UNORDERED_MAP - Return an unordered map.
* @property {number} ORDERED_MAP - Return an ordered map.
*/
exports.returnType = as.maps.returnType

Expand Down
20 changes: 12 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aerospike",
"version": "5.3.0",
"version": "5.4.0",
"description": "Aerospike Client Library",
"keywords": [
"aerospike",
Expand Down
4 changes: 3 additions & 1 deletion src/main/enums/maps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ Local<Object> map_enum_values()
set(return_type, "KEY", AS_MAP_RETURN_KEY);
set(return_type, "VALUE", AS_MAP_RETURN_VALUE);
set(return_type, "KEY_VALUE", AS_MAP_RETURN_KEY_VALUE);
set(return_type, "EXISTS", AS_MAP_RETURN_EXISTS);
set(return_type, "EXISTS", AS_MAP_RETURN_EXISTS);
set(return_type, "UNORDERED_MAP", AS_MAP_RETURN_UNORDERED_MAP);
set(return_type, "ORDERED_MAP", AS_MAP_RETURN_ORDERED_MAP);
set(return_type, "INVERTED", AS_MAP_RETURN_INVERTED);

// as_cdt_op_map
Expand Down
8 changes: 4 additions & 4 deletions src/main/util/conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1056,14 +1056,14 @@ int map_from_jsobject(as_map **map, Local<Object> obj, const LogInfo *log)
const Local<Array> props =
Nan::GetOwnPropertyNames(obj.As<Object>()).ToLocalChecked();
const uint32_t capacity = props->Length();
as_v8_detail(log, "Creating new as_hashmap with capacity %d", capacity);
as_hashmap *hashmap = as_hashmap_new(capacity);
if (hashmap == NULL) {
as_v8_detail(log, "Creating new as_orderedmap with capacity %d", capacity);
as_orderedmap *orderedmap = as_orderedmap_new(capacity);
if (orderedmap == NULL) {
as_v8_error(log, "Map allocation failed");
Nan::ThrowError("Map allocation failed");
return AS_NODE_PARAM_ERR;
}
*map = (as_map *)hashmap;
*map = (as_map *)orderedmap;
for (uint32_t i = 0; i < capacity; i++) {
const Local<Value> name = Nan::Get(props, i).ToLocalChecked();
const Local<Value> value = Nan::Get(obj, name).ToLocalChecked();
Expand Down
41 changes: 41 additions & 0 deletions test/exp.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ describe('Aerospike.exp', function () {

const client = helper.client

const orderMap = (key, bin, order, ctx) => {
const policy = new Aerospike.MapPolicy({ order })
const setMapPolicy = Aerospike.maps.setPolicy(bin, policy)
if (ctx) setMapPolicy.withContext(ctx)
return client.operate(key, [setMapPolicy])
}

const orderByKey = (key, bin, ctx) => orderMap(key, bin, Aerospike.maps.order.KEY_ORDERED, ctx)

async function createRecord (bins, meta = null) {
const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exp' })()
await client.put(key, bins, meta)
Expand Down Expand Up @@ -76,6 +85,38 @@ describe('Aerospike.exp', function () {
})
})

describe('eq on map bin', function () {
it('evaluates to true if a map bin matches a value', async function () {
const key = await createRecord({ map: { c: 1, b: 2, a: 3 } })
await orderByKey(key, 'map')
await testNoMatch(key, exp.eq(exp.map({ d: 4, e: 5 }), exp.binMap('map')))
await testMatch(key, exp.eq(exp.map({ c: 1, b: 2, a: 3 }), exp.binMap('map')))
})

it('evaluates to true if a map bin matches a map bin', async function () {
const key = await createRecord({ map: { c: 1, b: 2, a: 3 }, map2: { c: 1, b: 2, a: 3 }, map3: { c: 1, b: 2 } })
await orderByKey(key, 'map')
await testNoMatch(key, exp.eq(exp.binMap('map'), exp.binMap('map3')))
await testMatch(key, exp.eq(exp.binMap('map'), exp.binMap('map2')))
})
})

describe('eq on list bin', function () {
it('evaluates to true if a list bin matches a value', async function () {
const key = await createRecord({ list: [4, 2, 0] })
await orderByKey(key, 'map')
await testNoMatch(key, exp.eq(exp.list([0, 2, 4]), exp.binList('list')))
await testMatch(key, exp.eq(exp.list([4, 2, 0]), exp.binList('list')))
})

it('evaluates to true if a list bin matches a list bin', async function () {
const key = await createRecord({ list: [4, 2, 0], list2: [4, 2, 0], list3: [4, 2] })
await orderByKey(key, 'map')
await testNoMatch(key, exp.eq(exp.binList('list'), exp.binList('list3')))
await testMatch(key, exp.eq(exp.binList('list'), exp.binList('list2')))
})
})

describe('eq on blob bin', function () {
it('evaluates to true if a blob bin matches a value', async function () {
const key = await createRecord({ blob: Buffer.from([1, 2, 3]) })
Expand Down
2 changes: 1 addition & 1 deletion test/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('client.get()', function () {
expect(bins.i).to.eql(123)
expect(bins.s).to.eql('abc')
expect(bins.l).to.eql(Buffer.from([0x93, 0x01, 0x02, 0x03]))
expect(bins.m).to.eql(Buffer.from([0x83, 0xa2, 0x03, 0x61, 0x01, 0xa2, 0x03, 0x62, 0x02, 0xa2, 0x03, 0x63, 0x03]))
expect(bins.m).to.eql(Buffer.from([0x84, 0xc7, 0x00, 0x01, 0xc0, 0xa2, 0x03, 0x61, 0x01, 0xa2, 0x03, 0x62, 0x02, 0xa2, 0x03, 0x63, 0x03]))
})
})
})
Expand Down
36 changes: 36 additions & 0 deletions test/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1519,5 +1519,41 @@ describe('client.operate() - CDT Map operations', function () {
.then(assertResultEql({ map: true }))
.then(cleanup())
})

it('returns key/value for a single read', function () {
return initState()
.then(createRecord({ map: { a: 1, b: 2, c: 3 } }))
.then(orderByKey('map'))
.then(operate(maps.getByIndex('map', 0, maps.returnType.ORDERED_MAP)))
.then(assertResultEql({ map: { a: 1 } }))
.then(cleanup())
})

it('returns key/value for a range read', function () {
return initState()
.then(createRecord({ map: { a: 1, b: 2, c: 3 } }))
.then(orderByKey('map'))
.then(operate(maps.getByIndexRange('map', 0, 2, maps.returnType.ORDERED_MAP)))
.then(assertResultEql({ map: { a: 1, b: 2 } }))
.then(cleanup())
})

it('returns key/value for a single read', function () {
return initState()
.then(createRecord({ map: { a: 1, b: 2, c: 3 } }))
.then(orderByKey('map'))
.then(operate(maps.getByIndex('map', 0, maps.returnType.UNORDERED_MAP)))
.then(assertResultEql({ map: { a: 1 } }))
.then(cleanup())
})

it('returns key/value for a range read', function () {
return initState()
.then(createRecord({ map: { a: 1, b: 2, c: 3 } }))
.then(orderByKey('map'))
.then(operate(maps.getByIndexRange('map', 0, 2, maps.returnType.UNORDERED_MAP)))
.then(assertResultEql({ map: { a: 1, b: 2 } }))
.then(cleanup())
})
})
})
2 changes: 1 addition & 1 deletion test/operate.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ context('Operations', function () {
.then(record => {
expect(record.bins.int).to.equal(123)
expect(record.bins.list).to.eql(Buffer.from([0x93, 0x01, 0x02, 0x03]))
expect(record.bins.map).to.eql(Buffer.from([0x83, 0xa2, 0x03, 0x61, 0x01, 0xa2, 0x03, 0x62, 0x02, 0xa2, 0x03, 0x63, 0x03]))
expect(record.bins.map).to.eql(Buffer.from([0x84, 0xc7, 0x00, 0x01, 0xc0, 0xa2, 0x03, 0x61, 0x01, 0xa2, 0x03, 0x62, 0x02, 0xa2, 0x03, 0x63, 0x03]))
})
})
})
Expand Down

0 comments on commit 69138fd

Please sign in to comment.