This commit is contained in:
Daniel Lugo 2021-09-11 21:44:38 -04:00
parent 3ad9f0f5ef
commit f94646d67b
3 changed files with 22 additions and 10 deletions

View file

@ -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

View file

@ -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,

View file

@ -23,9 +23,6 @@ let gun
// eslint-disable-next-line init-declarations
let user
/** @type {Set<string>} */
const pendingOnces = new Set()
/**
* @returns {Promise<void>}
*/
@ -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