From f94646d67b793b55d7f2d1ed0777f6334ec33e90 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 11 Sep 2021 21:44:38 -0400 Subject: [PATCH] Work --- services/gunDB/Mediator/index.js | 4 ++-- utils/GunSmith/GunSmith.js | 24 +++++++++++++++++++----- utils/GunSmith/gun.js | 4 +--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 1cfd24d2..52867399 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -2,12 +2,12 @@ * @format */ const Common = require('shock-common') -const Gun = require('gun') +const Gun = require('../../../utils/GunSmith') // @ts-ignore require('gun/nts') const logger = require('../../../config/log') // @ts-ignore -Gun.log = () => {} +// Gun.log = () => {} // @ts-ignore require('gun/lib/open') // @ts-ignore diff --git a/utils/GunSmith/GunSmith.js b/utils/GunSmith/GunSmith.js index 9fd1884d..99d75dd6 100644 --- a/utils/GunSmith/GunSmith.js +++ b/utils/GunSmith/GunSmith.js @@ -64,6 +64,8 @@ let currentGun = fork('./gun') let lastAlias = '' let lastPass = '' +/** @type {import('gun/types/options').IGunConstructorOptions} */ +let lastOpts = {} /** * @param {string} alias @@ -120,6 +122,13 @@ const forge = () => { const newGun = fork('./gun') currentGun = newGun + /** @type {Smith.SmithMsgInit} */ + const initMsg = { + opts: lastOpts, + type: 'init' + } + currentGun.send(initMsg) + currentGun.on('message', handleMsg) const lastGunListeners = Object.keys(pathToListeners).map(path => { @@ -130,7 +139,6 @@ const forge = () => { } return msg }) - currentGun.send(lastGunListeners) autoAuth().then(() => { @@ -151,9 +159,12 @@ function createReplica(path, afterMap = false) { _: { get: '', opt: { + // TODO peers: {} }, - put: {} + put: { + // TODO + } }, get(key) { if (afterMap) { @@ -202,17 +213,18 @@ function createReplica(path, afterMap = false) { once(cb, opts = { wait: 200 }) { const tmp = createReplica(path, afterMap) if (afterMap) { - // + // TODO } else { + /** @type {GunT.ListenerData} */ let lastVal = null - tmp.on((data, key) => { + tmp.on(data => { lastVal = data }) setTimeout(() => { if (cb) { - cb(lastVal, path.split('>').lastItem) + cb(lastVal, path.split('>')[path.split('>').length - 1]) } }, opts.wait) } @@ -360,6 +372,8 @@ function createUserReplica() { * @param {import('gun/types/options').IGunConstructorOptions} opts */ const Gun = opts => { + lastOpts = opts + /** @type {Smith.SmithMsgInit} */ const msg = { opts, diff --git a/utils/GunSmith/gun.js b/utils/GunSmith/gun.js index 839acde8..f2a5f9ba 100644 --- a/utils/GunSmith/gun.js +++ b/utils/GunSmith/gun.js @@ -23,9 +23,6 @@ let gun // eslint-disable-next-line init-declarations let user -/** @type {Set} */ -const pendingOnces = new Set() - /** * @returns {Promise} */ @@ -49,6 +46,7 @@ const handleMsg = msg => { } if (msg.type === 'init') { gun = /** @type {any} */ (new Gun(msg.opts)) + user = gun.user() } if (msg.type === 'auth') { const { alias, pass } = msg