How to use the gun/gun.chain function in gun

To help you get started, we’ve selected a few gun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / handles.ts View on Github external
};

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)
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / find.ts View on Github external
}
  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 = () => {
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / handles.ts View on Github external
// 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);
};
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / handles.ts View on Github external
};

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);
};
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / handles.ts View on Github external
};

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);
};
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / handles.ts View on Github external
};

// 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
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / handles.ts View on Github external
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}`);
};
github amark / gun / lib / time.js View on Github external
;(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 || {};
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / handles.ts View on Github external
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}`);
};
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / erase.ts View on Github external
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;
};

gun

A realtime, decentralized, offline-first, graph data synchronization engine.

(Zlib OR MIT OR Apache-2.0)
Latest version published 1 year ago

Package Health Score

69 / 100
Full package analysis