Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
Gun.chain.notificationById = function(notificationId: string) {
return this.get(TABLES.NOTIFICATIONS).get(notificationId);
};
// Profiles
Gun.chain.getUserProfile = function(username: string) {
return this.get(TABLES.PROFILES).get(username);
};
Gun.chain.allProfiles = function() {
this.get(TABLES.PROFILES);
};
Gun.chain.currentUserProfile = function() {
return this.get(TABLES.PROFILES).get(this.user().is.alias);
};
Gun.chain.profileByUsername = function(username: string) {
return this.get(TABLES.PROFILES).get(username);
};
Gun.chain.currentProfileFriends = function() {
return this.get(TABLES.PROFILES)
.get(this.user().is.alias)
.get(TABLE_ENUMS.FRIENDS);
};
Gun.chain.profileFriendsByUsername = function(username: string) {
return this.get(TABLES.PROFILES)
.get(username)
}
const t = term.toLowerCase();
const profiles = Object.entries(data).map(([key, value]) => value);
const res = profiles.filter((profile: any | undefined) => {
if (!profile || !Object.keys(profile).length) {
return false;
} else {
return ~profile.alias.toLowerCase().search(term) || ~profile.fullName.toLowerCase().search(term);
}
});
return res;
}
// from general to profiles specific
Gun.chain.find = function(
term: string,
cb: (data: any) => void,
) {
this.once((d: any) => {
if (!d) {
return cb(undefined);
}
if (!term) {
return cb(undefined);
}
if (term.length < 3) {
return cb(undefined);
}
let tries = 0;
const querySearch = () => {
// Accounts
Gun.chain.currentAccountRecover = function() {
return this.user().path(TABLE_ENUMS.RECOVER);
};
Gun.chain.accountByPub = function(pub: string) {
return this.user(pub);
};
// Comments
Gun.chain.commentsByPostPath = function(postPath: string) {
return this.path(`${TABLES.POSTS}.${postPath},${TABLE_ENUMS.COMMENTS}`);
};
Gun.chain.commentMetaById = function(commentId: string) {
return this.path(`${TABLES.COMMENT_META_BY_ID}.${commentId}`);
};
Gun.chain.likesByCommentPath = function(commentPath: string) {
return this.path(`${commentPath}.${TABLE_ENUMS.LIKES}`);
};
// Notifications
Gun.chain.notificationsByUsername = function(username: string) {
return this.get(TABLES.NOTIFICATIONS).get(username);
};
Gun.chain.notifications = function() {
return this.get(TABLES.NOTIFICATIONS).get(this.user().is.alias);
};
};
Gun.chain.accountByPub = function(pub: string) {
return this.user(pub);
};
// Comments
Gun.chain.commentsByPostPath = function(postPath: string) {
return this.path(`${TABLES.POSTS}.${postPath},${TABLE_ENUMS.COMMENTS}`);
};
Gun.chain.commentMetaById = function(commentId: string) {
return this.path(`${TABLES.COMMENT_META_BY_ID}.${commentId}`);
};
Gun.chain.likesByCommentPath = function(commentPath: string) {
return this.path(`${commentPath}.${TABLE_ENUMS.LIKES}`);
};
// Notifications
Gun.chain.notificationsByUsername = function(username: string) {
return this.get(TABLES.NOTIFICATIONS).get(username);
};
Gun.chain.notifications = function() {
return this.get(TABLES.NOTIFICATIONS).get(this.user().is.alias);
};
Gun.chain.notificationById = function(notificationId: string) {
return this.get(TABLES.NOTIFICATIONS).get(notificationId);
};
};
Gun.chain.notifications = function() {
return this.get(TABLES.NOTIFICATIONS).get(this.user().is.alias);
};
Gun.chain.notificationById = function(notificationId: string) {
return this.get(TABLES.NOTIFICATIONS).get(notificationId);
};
// Profiles
Gun.chain.getUserProfile = function(username: string) {
return this.get(TABLES.PROFILES).get(username);
};
Gun.chain.allProfiles = function() {
this.get(TABLES.PROFILES);
};
Gun.chain.currentUserProfile = function() {
return this.get(TABLES.PROFILES).get(this.user().is.alias);
};
Gun.chain.profileByUsername = function(username: string) {
return this.get(TABLES.PROFILES).get(username);
};
Gun.chain.currentProfileFriends = function() {
return this.get(TABLES.PROFILES)
.get(this.user().is.alias)
.get(TABLE_ENUMS.FRIENDS);
};
};
// Profiles
Gun.chain.getUserProfile = function(username: string) {
return this.get(TABLES.PROFILES).get(username);
};
Gun.chain.allProfiles = function() {
this.get(TABLES.PROFILES);
};
Gun.chain.currentUserProfile = function() {
return this.get(TABLES.PROFILES).get(this.user().is.alias);
};
Gun.chain.profileByUsername = function(username: string) {
return this.get(TABLES.PROFILES).get(username);
};
Gun.chain.currentProfileFriends = function() {
return this.get(TABLES.PROFILES)
.get(this.user().is.alias)
.get(TABLE_ENUMS.FRIENDS);
};
Gun.chain.profileFriendsByUsername = function(username: string) {
return this.get(TABLES.PROFILES)
.get(username)
.get(TABLE_ENUMS.FRIENDS);
};
// Posts
Gun.chain.postMetasByPostIdOfCurrentAccount = function(postId: string) {
return this.get(TABLES.POST_METAS_BY_USER)
.get(this.user().is.alias)
.get(postId);
};
Gun.chain.postByPath = function(postPath: string) {
return this.get(TABLES.POSTS).path(postPath);
};
Gun.chain.postsByDate = function(datePath: string) {
return this.path(`${TABLES.POSTS}.${datePath}.${TABLE_ENUMS.PUBLIC}`);
};
Gun.chain.likesByPostPath = function(postPath: string) {
return this.get(TABLES.POSTS).path(`${postPath}.${TABLE_ENUMS.LIKES}`);
};
Gun.chain.postLikesByCurrentUser = function(postPath: string) {
return this.path(`${TABLES.POSTS}.${postPath}.${TABLE_ENUMS.LIKES}.${this.user().is.alias}`);
};
;(function(){
var ify = Gun.node.ify, u;
Gun.chain.time = function(data, a, b){
if(data instanceof Function){
return travel(data, a, b, this);
}
var gun = this, root = gun.back(-1);
var cb = (a instanceof Function && a) || (b instanceof Function && b);
if(Gun.is(data)){
data.get(function(soul){
if(!soul){
return cb && cb({err: "Timegraph cannot link `undefined`!"});
}
gun.time(Gun.val.link.ify(soul), a, b);
}, true);
return gun;
}
opt = (cb === a)? b : a;
opt = Gun.text.is(opt)? {key: opt} : opt || {};
Gun.chain.postMetasByUsername = function(username: string) {
return this.get(TABLES.POST_METAS_BY_USER).get(username);
};
Gun.chain.postMetasByCurrentUser = function() {
return this.get(TABLES.POST_METAS_BY_USER).get(this.user().is.alias);
};
Gun.chain.postMetasByPostIdOfCurrentAccount = function(postId: string) {
return this.get(TABLES.POST_METAS_BY_USER)
.get(this.user().is.alias)
.get(postId);
};
Gun.chain.postByPath = function(postPath: string) {
return this.get(TABLES.POSTS).path(postPath);
};
Gun.chain.postsByDate = function(datePath: string) {
return this.path(`${TABLES.POSTS}.${datePath}.${TABLE_ENUMS.PUBLIC}`);
};
Gun.chain.likesByPostPath = function(postPath: string) {
return this.get(TABLES.POSTS).path(`${postPath}.${TABLE_ENUMS.LIKES}`);
};
Gun.chain.postLikesByCurrentUser = function(postPath: string) {
return this.path(`${TABLES.POSTS}.${postPath}.${TABLE_ENUMS.LIKES}.${this.user().is.alias}`);
};
import * as Gun from 'gun/gun';
Gun.chain.erase = function(dataKey: string, cb?: any) {
this.get(dataKey).put(null, () => {
this.get(dataKey).put({}, cb);
});
return this;
};