From 958c25cfba9bc628d5ee7dc35e95f94bf81a9db2 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Mon, 13 Sep 2021 10:57:48 -0400 Subject: [PATCH] Sort out Gun.text.random() --- utils/GunSmith/GunSmith.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/utils/GunSmith/GunSmith.js b/utils/GunSmith/GunSmith.js index 087c032e..1cd45ac8 100644 --- a/utils/GunSmith/GunSmith.js +++ b/utils/GunSmith/GunSmith.js @@ -6,11 +6,21 @@ // @ts-check /// /// +const RealGun = require('gun') const uuid = require('uuid/v1') const { fork } = require('child_process') const logger = require('../../config/log') +const gunUUID = () => { + const RG = /** @type {any} */ (RealGun) + if (typeof RG.text === 'object' && typeof RG.text.random === 'function') { + return RG.text.random() + } + // This probably won't happen + throw new ReferenceError() +} + /** * Maps a path to `on()` listeners * @type {Record|undefined>} @@ -349,8 +359,8 @@ function createReplica(path, afterMap = false) { if (afterMap) { throw new Error('Cannot call set() after map() on a GunSmith node') } - // @ts-expect-error - const id = Gun.text.random() + + const id = gunUUID() this.put( { [id]: data