Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.gun.user(key).get(`iris`).get(`identitiesBySearchKey`).map().on((id, k) => {
if (Object.keys(seen).length >= opt.limit) {
// TODO: turn off .map cb
return;
}
if (!searchTermCheck(key)) { return; }
const soul = Gun.node.soul(id);
if (soul && !Object.prototype.hasOwnProperty.call(seen, soul)) {
seen[soul] = true;
opt.callback(
new Contact(this.gun.user(key).get(`iris`).get(`identitiesBySearchKey`).get(k), undefined, this)
);
}
});
}
if (this.serializer) {
data = this.serializer.serialize(object);
} if (this.class) {
data = object.serialize();
}
// TODO: optionally use gun hash table
let node;
if (opt.id || data.id) {
node = this.gun.get(this.name).get(`id`).get(opt.id || data.id).put(data); // TODO: use .top()
} else if (object.getId) {
node = this.gun.get(this.name).get(`id`).get(object.getId()).put(data);
} else {
node = this.gun.get(this.name).get(`id`).set(data);
}
this._addToIndexes(data, node);
return data.id || Gun.node.soul(node) || node._.link;
}
async _addToIndexes(serializedObject, node) {
if (Gun.node.is(serializedObject)) {
serializedObject = await serializedObject.open();
}
const addToIndex = (indexName, indexKey) => {
this.gun.get(this.name).get(indexName).get(indexKey).put(node);
};
if (this.indexer) {
const customIndexes = await this.indexer(serializedObject);
const customIndexKeys = Object.keys(customIndexes);
for (let i = 0;i < customIndexKeys;i++) {
const key = customIndexKeys[i];
addToIndex(key, customIndexes[key]);
}
}
for (let i = 0;i < this.indexes.length; i++) {
const indexName = this.indexes[i];
if (Object.prototype.hasOwnProperty.call(serializedObject, indexName)) {