-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Queries with inline data (p2p only) #88
Conversation
could add an invocation like |
That could work, although the repl's default printing of the query results isn't too great. For the example above you'd just get That's something we should probably tweak regardless though, to make working at the repl more useful. |
cd8df36
to
fe159fb
Compare
@@ -65,12 +65,20 @@ function loadOrGenerateIdentity (filePath: string): Promise<PeerId> { | |||
} | |||
|
|||
function inflateMultiaddr (multiaddrString: string): PeerInfo { | |||
// total hack to patch in support for /p2p/ multiaddrs, which should | |||
// be supported upstream soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's actively reference this multiformats/multiaddr#27
@@ -15,16 +28,18 @@ require('yargs') | |||
// this is the only way to get useful config in subcommands | |||
'config': true, | |||
'global': true, | |||
'default': home + 'config.json' | |||
'default': path.join(home, 'config.json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call
}, | ||
'remotePeer': { | ||
'global': true, | ||
'type': 'string', | ||
'describe': 'The remote peer to pair with (multiaddress)' | ||
} | ||
}) | ||
.coerce('config', filePath => ensureDirExists(filePath, 'config file')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't want to just put this into the config
key above as coerce : { filepath: ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sure, that does sound better.
[ci skip]
} | ||
} | ||
|
||
return _.cloneDeepWith(result, replacer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the lodash pieces are broken out so you can just import lodash.clonedeepwith
but it's not critical https://www.npmjs.com/package/lodash.clonedeepwith
@@ -177,6 +179,66 @@ function promiseTimeout<T> (timeout: number, promise: Promise<T>): Promise<T> { | |||
})]) | |||
} | |||
|
|||
function flatMap<T, U> (array: Array<T>, f: (x: T) => Array<U>): Array<U> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if only Thenables were monadic 😞
try { | ||
val = decode(obj.data) | ||
} catch (err) { | ||
val = obj.data.toString('base64') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nice to add a comment here explaining the logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, actually I might remove the base64 conversion here. After I wrote this, I added a pass to convert all Buffer
s to base64 just before printing the results. That's a better place for it than here, I think
const key = _.get(value, 'object') | ||
const data = objectMap[key] | ||
if (data != null) { | ||
return _.set(value, 'object', {key, data}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I guess we have all these other lodash calls too, let's take the whole package then
This adds a
remoteQueryWithData
method to theMediachainNode
class, which will fetch multihashobject
references in query results from the remote peer and replace the multihash with{key: multihashValue, data: actualObject}
An example at the repl
TODO:
I'd like to add a new subcommand to the aleph cli that executes a query string against a remote peer and pretty prints the results, so we can get a nice one-liner to use in the Attribution Engine.