I started working on a JavaScript library that enables apps to support multiple 0data protocols with the same API, currently Fission, remoteStorage, and any object that conforms to a certain interface. Maybe SOLID someday?
My Fission proof has been reconfigured to log in via something like an email address (for example rosano@fission.codes
) and also to migrate local data to the cloud.
http://fission-proof.5apps.com
Comparing APIs
I work more with JSON than files so the API makes the Fission experience a bit simpler.
Setup
const state = await webnative.initialise({
permissions: {
fs: {
privatePaths: [
'bravo',
],
},
},
});
if ([webnative.Scenario.AuthSucceeded, webnative.Scenario.Continuation].includes(state.scenario)) {
const wnfs = state.fs
// ready
}
==
const api = await zerodatawrap.ZDRWrap({
ZDRParamLibrary: webnative,
ZDRParamScopes: [{
ZDRScopeKey: 'alfa',
ZDRScopeDirectory: 'bravo',
}],
});
// ready
Write an object
await wnfs.write('/private/bravo/charlie.json', JSON.stringify({
foo: 'bar',
}));
await wnfs.publish();
==
await api.alfa.ZDRStorageWriteObject('charlie.json', {
foo: 'bar',
});
Get an array of objects
(await Promise.all(Object.keys(await wnfs.ls('/private/bravo/')).map(function (e) {
return wnfs.cat(`/private/bravo/${ e }`);
}))).map(JSON.parse);
==
Object.values(await api.alfa.ZDRStorageListObjects());
Model logic
There is currently no equivalent for this in webnative, but just to give an idea, you can configure one or more schemas:
const api = zerodatawrap.ZDRWrap({
// …
ZDRParamScopes: [{
// …
ZDRScopeSchemas: [{
ZDRSchemaKey: 'cars',
// path for a given object
ZDRSchemaPath (object) {
return `cars/${ object.id }.json`;
},
// object information for a given path
ZDRSchemaStub (path) {
return {
id: path.split('/').pop().split('.json').shift(),
};
},
// truthy values cause a promise rejection
ZDRSchemaDispatchValidate (object) {
if (typeof object.id !== 'string') {
return {
not: 'so fast',
};
}
},
// logic before saving
ZDRSchemaMethods: {
clean (car) {
return this.alfa.cars.ZDRModelWriteObject(Object.assign(car, {
clean: true,
washed: new Date(),
}));
},
},
}],
// …
}],
// …
});
which adds functionality to the API:
// rejects
try {
await api.alfa.cars.ZDRModelWriteObject({
id: 123,
});
} catch (truthy) {
console.log(truthy.not); // so fast
}
// write `{"id":"batmobile","clean":true,"washed":"…"}` to "/private/bravo/cars/batmobile.json
await api.alfa.cars.clean({
id: 'batmobile',
});
Anyway, it’s a work in progress that has missing elements (like public folders), but I hope it can make things easier for other people to integrate with webnative. Any feedback or testing would be appreciated especially with storing files and buffers as I don’t use those much. I’ll share this more publicly once it’s more stable.
Looking forward to adding Fission support to my existing apps in the near future