Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
delete data.Attributes._pk_className;
delete data.Attributes._sk_id;
resolve({ ok : 1, n : 1, nModified : 1, value : data.Attributes });
} else {
resolve({ ok : 1, n : 1, nModified : 1, value : null });
}
}
});
} else {
// here we do upserting
if (upsert) {
object = {
...object['$set'],
...object['$inc']
}
object['_id'] = newObjectId();
this.insertOne(object).then(
res => resolve({ ok : 1, n : 1, nModified : 1, value : res.ops[0] })
);
} else {
resolve({ ok : 1, n : 1, nModified : 1, value : null });
}
}
});
}
@test 'handles creating an array, object, date, file'(done) {
const adapter = $;
const objectId = newObjectId();
const className = 'MyClass';
const obj = {
objectId : objectId,
array: [1, 2, 3],
object: {foo: 'bar'},
date: {
__type: 'Date',
iso: '2016-05-26T20:55:01.154Z',
},
file: {
__type: 'File',
name: '7aefd44420d719adf65d16d52e688baf_license.txt',
url: 'http://localhost:1337/files/app/7aefd44420d719adf65d16d52e688baf_license.txt'
}
};
insertOne(object) : Promise {
let id = object['_id'] || newObjectId();
object['_id'] = id;
let params : DynamoDB.DocumentClient.PutItemInput = {
TableName : this.database,
Item: {
_pk_className : this.className,
_sk_id : id,
...object
},
ExpressionAttributeNames : {
'#id' : '_sk_id',
},
ConditionExpression : 'attribute_not_exists(#id)',
}
return new Promise(
@test 'handles updating a single object with array, object, date'(done) {
const adapter = $;
const objectId = newObjectId();
const className = 'MyClass';
const schema = {
fields: {
array: { type: 'Array' },
object: { type: 'Object' },
date: { type: 'Date' },
}
};
adapter.createObject(className, schema, { objectId: objectId })
.then(() => adapter._rawFind(className))
.then(results => {
expect(results.length).to.be.equal(1);
const update = {