libkernel
Advanced tools
Comparing version 0.0.29 to 0.0.30
@@ -0,2 +1,4 @@ | ||
export declare function log(...inputs: any): void; | ||
export declare function logErr(...inputs: any): void; | ||
export declare function postKernelQuery(kernelQuery: any): Promise<any>; | ||
export declare function init(): Promise<string>; |
// log provides a wrapper for console.log that prefixes 'libkernel'. | ||
var log = function (...inputs) { | ||
export function log(...inputs) { | ||
console.log("[libkernel]", ...inputs); | ||
}; | ||
} | ||
// logErr provides a wrapper for console.error that prefixes '[libkernel]' to | ||
// the output. | ||
var logErr = function (...inputs) { | ||
export function logErr(...inputs) { | ||
console.error("[libkernel]", ...inputs); | ||
}; | ||
} | ||
var initialized; | ||
@@ -11,0 +11,0 @@ var bridgeExists; |
@@ -1,4 +0,5 @@ | ||
import { init, postKernelQuery } from './init'; | ||
import { logErr, init, postKernelQuery } from './init'; | ||
// testMessage will send a test message to the kernel, ensuring that basic | ||
// kernel communications are working. | ||
// kernel communications are working. The promise will resolve to the version | ||
// of the kernel. | ||
export function testMessage() { | ||
@@ -20,13 +21,23 @@ // Retrun a promise that will resolve when a response is received from | ||
.then(response => { | ||
if (!("version" in response)) { | ||
resolve("kernel did not report a version"); | ||
return; | ||
} | ||
resolve(response.version); | ||
}) | ||
.catch(response => { | ||
if (!("err" in response) || typeof response.err !== "string") { | ||
logErr("unrecognized response in postKernelQuery catch", response); | ||
reject("unrecognized repsonse"); | ||
return; | ||
} | ||
reject(response.err); | ||
}); | ||
}) | ||
.catch(x => { | ||
.catch(err => { | ||
// For some reason, the bridge is not available. | ||
// Likely, this means that the user has not installed | ||
// the browser extension. | ||
reject(x); | ||
logErr("bridge is not initialized:", err); | ||
reject(err); | ||
}); | ||
@@ -40,3 +51,6 @@ }); | ||
// | ||
// TODO: The secure upload caps at about 4 MB of data right now. | ||
// NOTE: The largest allowed file is currently slightly less than 4 MiB | ||
// (roughly 500 bytes less) | ||
// | ||
// TODO: Clean this function up (the response should be a bit more helpful) | ||
export function upload(filename, fileData) { | ||
@@ -43,0 +57,0 @@ return new Promise((resolve, reject) => { |
{ | ||
"name": "libkernel", | ||
"version": "0.0.29", | ||
"version": "0.0.30", | ||
"description": "helper library to interact with the skynet kernel", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
10617
276