libkernel
Advanced tools
Comparing version 0.0.76 to 0.0.77
export { download } from "./download.js"; | ||
export { addContextToErr, composeErr } from "./err.js"; | ||
export { init, newKernelQuery } from "./init.js"; | ||
export { init } from "./init.js"; | ||
export { callModule, testMessage } from "./messages.js"; | ||
export { upload } from "./upload.js"; |
export { download } from "./download.js"; | ||
export { addContextToErr, composeErr } from "./err.js"; | ||
export { init, newKernelQuery } from "./init.js"; | ||
export { init } from "./init.js"; | ||
export { callModule, testMessage } from "./messages.js"; | ||
export { upload } from "./upload.js"; |
@@ -49,3 +49,8 @@ import { logErr } from "./log.js"; | ||
// The first return value is a function that can be called to send a | ||
// 'queryUpdate' to the kernel for that nonce. | ||
// 'queryUpdate' to the kernel for that nonce. The second input should be a | ||
// function that can be called when a 'responseUpdate' message is provided. | ||
// | ||
// NOTE: newKernelQuery will provide return values before learning that init | ||
// has succeeded or failed. If init fails, the query will implicitly fail as | ||
// well. | ||
function newKernelQuery(data, update) { | ||
@@ -59,7 +64,9 @@ let nonce = nextNonce; | ||
queries[nonce] = { resolve, reject, update, handle: handleKernelResponse }; | ||
window.postMessage({ | ||
namespace, | ||
method: "newKernelQuery", | ||
nonce, | ||
data, | ||
init().then(() => { | ||
window.postMessage({ | ||
namespace, | ||
method: "newKernelQuery", | ||
nonce, | ||
data, | ||
}); | ||
}); | ||
@@ -66,0 +73,0 @@ }); |
declare function testMessage(): Promise<string>; | ||
declare function callModule(module: string, method: string, data: any): Promise<any>; | ||
export { callModule, testMessage }; | ||
declare function connectModule(module: string, method: string, data: any, receiveUpdate: any): [any, Promise<any>]; | ||
export { callModule, connectModule, testMessage }; |
@@ -100,2 +100,59 @@ import { addContextToErr, composeErr } from "./err.js"; | ||
} | ||
export { callModule, testMessage }; | ||
// connectModule opens a "connection" to a module. When using 'callModule', all | ||
// communications have a single round trip. You send a single query message, | ||
// then you get a single response message. With 'connectModule', the caller has | ||
// the ability to send updates, and the receiver has the ability to send | ||
// updates. | ||
// | ||
// The general structure of the communication is the same. A query is created | ||
// on a module that specifies a particular method. When creating the query, a | ||
// 'receiveUpdate' method needs to be provided that will be called when the | ||
// module provides an update. recieveUpdate should have the form: | ||
// | ||
// function receiveUpdate(data: any) { ... } | ||
// | ||
// updates are not guaranteed to be provided in any particular order. | ||
// | ||
// The return value is a tuple of a 'sendUpdate' function and a promise. The | ||
// promise will resolve or reject when the query is complete. The sendUpdate | ||
// value is a function of the form: | ||
// | ||
// function sendUpdate(data: any) { ... } | ||
// | ||
// If the caller wishes to send an update to the module, they should use the | ||
// sendUpdate function. | ||
// | ||
// TODO: At the moment it's unclear that the sendUpdate function is being | ||
// created in a way that is guaranteed to be specific to this one caller, | ||
// because the nonces may not be unique. We need to work that through with the | ||
// kernel. | ||
function connectModule(module, method, data, receiveUpdate) { | ||
// Create the kernel query. | ||
let [sendUpdate, query] = newKernelQuery({ | ||
method: "moduleCall", | ||
data: { | ||
module, | ||
method, | ||
data, | ||
}, | ||
}, receiveUpdate); | ||
let p = new Promise((resolve, reject) => { | ||
init() | ||
.then(() => { | ||
query | ||
.then((response) => { | ||
resolve(response); | ||
}) | ||
.catch((err) => { | ||
reject(addContextToErr(err, "moduleCall query to kernel failed")); | ||
}); | ||
}) | ||
.catch((err) => { | ||
let cErr = composeErr(noBridge, err); | ||
logErr(cErr); | ||
reject(cErr); | ||
}); | ||
}); | ||
return [sendUpdate, p]; | ||
} | ||
export { callModule, connectModule, testMessage }; |
{ | ||
"name": "libkernel", | ||
"version": "0.0.76", | ||
"version": "0.0.77", | ||
"description": "helper library to interact with skynet and the skynet kernel", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19058
447
0