JS Wrapper or Higher Level API

I’m currently writing some functions to get keys from a container. Assuming one were to only do that operation, it takes something like 6 API calls in JS. This is fine, this is what APIs do.

But I’m also thinking that I can’t be the only one writing this exact higher level function. I know I’ll be writing more higher level functions that break down into a certain set of low level API calls.

I’ve seen there are Python and .NET wrappers people have posted in the forums. I don’t know if those are higher level wrappers or direct pass through wrappers, but I’m sticking with JavaScript.

Is anyone aware of any JS libraries that wrap over window.safeApp* calls? If not, would there be a sensible place for me to put the code I’m writing for others to use?


The best way to share code (and possibly get help from others: bug reports, feedback and even pull requests) is to publish it on github and then share a link in the forums.

Several of us are using JavaScript (I expect most will) but so far I’ve not needed to create a wrapper library. I expect there will be some but it’s early days yet so go for it :slight_smile:


Thanks @happybeing.

This sort of follows a discussion in another thread (which I think you were part of) regarding whether or not to save handles and reuse them, or to free them as soon as possible.

I plan to free them as soon as possible (arguments in favor of such methodology made in that thread), which means a lot of redundant initialization code for each operation. I could see the potential for reuse with some of the generalized wrappers I’m writing over top the API.


In case others are looking at this thread, someone else in the forums has indeed written a wrapper, though the post indicates some issues with it.

Post here: Problem with inserting data to app's own container
Code here: https://github.com/loziniak/maidsafe-test/tree/7f3d88274044280180566b1cc53ddd296d6fb0f6

I haven’t looked at it in detail yet.


Just created a quick repo websafe in case the community wants to contribute to another go at a wrapper.

Here’s a first issue so we can discuss the initial API, please join!


@BryanB Thank you for starting this discussion.

This will be a good place for us to get an idea about exactly what higher level functions should exist and be most useful for developers as well as where the line should be drawn for what is reasonable to maintain and what is not.


@hunterlester Well the beautiful thing about starting at the low level is that, ideally, developers will write the higher level functions they need and share them. Higher level interfaces should arise relatively organically based on need. It’ll take time: the steep learning curve of low level interfaces will keep people away until higher interfaces are available, which reduces the barrier to entry, and brings in more programmers who might build still higher abstractions. Positive feedback loop, just needs to hit a critical point.



I was having the same problem as you re: keeping track of handles and keeping a linear sequence of promises without nesting or chaining.

@loziniak did a good job tracking handles using objects. I souped up his code a little and it’s been working pretty well. This entire thread is probably worth reading as there are some other links.

Here’s an example using code from Loziniak’s repo (https://github.com/loziniak/maidsafe-test/blob/master/safe_api_example.html):

	let app = safeAPI.initialiseApp(app_info);
	app.authoriseAndConnect({_public: ['Read']});
	let md = app.quickRandomPublic({'this': 'is', 'a': 'test'});

There’s a single promise chain managed in app: all other calls and objects refer back to the promise chain in app. Each object (app, md) maintains its own handle, which is also extremely convenient. A call to safeMutableData.get(mdHandle, key) becomes md.get(key) because the handle is stored in md.