diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0b3cb79fd9fca0b6513ffc7fa9100a6c7f6b0a50 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +native/target +native/index.node +native/artifacts.json +**/*~ +**/node_modules +**/.DS_Store diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..ba913673776d9fbaeb8a5f71d3fd45276240ca0e --- /dev/null +++ b/lib/index.js @@ -0,0 +1,124 @@ +"use strict"; + +const addon = require('../native'); +const path = require('path'); + +module.exports = { + + /*newFileInstance: (filePath) => { + const instance = Object.create(WotB) + if (process.platform == 'win32') { + let bufferedPath = new Buffer(filePath,'ascii'); + instance.init(wotb.newFileInstanceWin32(bufferedPath, bufferedPath.length)) + } else { + instance.init(wotb.new_file_instance(filePath)); + } + instance.setFilePath(filePath) + return instance + },*/ + + newMemoryInstance: (sigStock) => { + const instance = Object.create(WotB) + const id = addon.new_memory_instance(sigStock); + instance.init(id) + return instance + }, + + +}; + +const WotB = { + + instanceID: -1, + filePath: "", + + init: function(instanceId){ + this.instanceID = instanceId + }, + + /** + * Eventually has a file path if it is a file instance. + * @param filePath + */ + setFilePath: function(filePath) { + this.filePath = filePath + }, + + memCopy: function() { + const copy = Object.create(WotB) + copy.instanceID = addon.mem_copy(this.instanceID); + return copy; + }, + + getMaxCert: function() { + return addon.get_max_links(this.instanceID); + }, + + getWoTSize: function() { + return addon.get_wot_size(this.instanceID); + }, + + isEnabled: function(nodeId) { + return addon.is_enabled(this.instanceID, nodeId); + }, + + getEnabled: function() { + var wot_size = addon.get_wot_size(this.instanceID); + var enabled_array = new Array(); + for (let i = 0; i < wot_size; i++) { + if (addon.is_enabled(this.instanceID, i)) { + enabled_array.push(i); + } + } + return enabled_array; + }, + + getDisabled: function() { + var wot_size = addon.get_wot_size(this.instanceID); + var enabled_array = new Array(); + for (let i = 0; i < wot_size; i++) { + if (!addon.is_enabled(this.instanceID, i)) { + enabled_array.push(i); + } + } + return enabled_array; + }, + + existsLink: function(source, target) { + return addon.exist_link(this.instanceID, source, target); + }, + + setMaxCert: function(maxCert) { + return addon.set_max_links(this.instanceID, maxCert); + }, + + + addNode: function() { + return addon.add_node(this.instanceID); + }, + + removeNode: function() { + return addon.rem_node(this.instanceID); + }, + + setEnabled: function(is_enabled, nodeId) { + return addon.set_enabled(this.instanceID, is_enabled, nodeId); + }, + + addLink: function(source, target) { + return addon.add_link(this.instanceID, source, target); + }, + + removeLink: function(source, target) { + return addon.rem_link(this.instanceID, source, target); + }, + + isOutdistanced: function(node, sentry_requirement, step_max, x_percent) { + var distance_result = addon.compute_distance(this.instanceID, node, sentry_requirement, step_max, x_percent); + return distance_result.outdistanced; + }, + + clear: function() { + return addon.remove_wot(this.instanceID); + } +} \ No newline at end of file diff --git a/native/Cargo.lock b/native/Cargo.lock new file mode 100644 index 0000000000000000000000000000000000000000..095b10cf13e48fe9b2cfa1dd8b8ccde94c61ec97 --- /dev/null +++ b/native/Cargo.lock @@ -0,0 +1,408 @@ +[[package]] +name = "aho-corasick" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "arrayvec" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bincode" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitflags" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "crossbeam-deque" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cslice" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "duniter-wotb" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "either" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "gcc" +version = "0.3.54" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "lazy_static" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.40" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "memchr" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memoffset" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "neon" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cslice 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "neon-build 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "neon-runtime 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "neon-build" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "neon-runtime" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cslice 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "nodrop" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num_cpus" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro2" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon-core" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde_derive" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive_internals 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_derive_internals" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syn" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "thread_local" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ucd-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "utf8-ranges" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "wotb-rs" +version = "0.1.0" +dependencies = [ + "duniter-wotb 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "neon 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "neon-build 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4" +"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" +"checksum bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9a6301db0b49fb63551bc15b5ae348147101cdf323242b93ec7546d5002ff1af" +"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" +"checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87" +"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" +"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" +"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" +"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" +"checksum cslice 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "697c714f50560202b1f4e2e09cd50a421881c83e9025db75d15f276616f04f40" +"checksum duniter-wotb 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "834b85bd66552e19e45245c3fe2f96bd350fa11adad679902ae6a127ed9f4dc1" +"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" +"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" +"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" +"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" +"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" +"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" +"checksum neon 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "6f6078a0767408131206f802cb4ee2b1d78a035f23c209c3c0cb1dbe258a8737" +"checksum neon-build 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "0220c1150ca0ac00df8fc1001dde699cf17762f208f43c497d90e91c910c0a17" +"checksum neon-runtime 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "9a53b08f4dfc0ebc9ecb8bd8a02ace763e833d657f03614293254420a413c036" +"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" +"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" +"checksum proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "49b6a521dc81b643e9a51e0d1cf05df46d5a2f3c0280ea72bcb68276ba64a118" +"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8" +"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" +"checksum rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80e811e76f1dbf68abf87a759083d34600017fc4e10b6bd5ad84a700f9dba4b1" +"checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" +"checksum regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "aec3f58d903a7d2a9dc2bf0e41a746f4530e0cab6b615494e058f67a3ef947fb" +"checksum regex-syntax 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bd90079345f4a4c3409214734ae220fd773c6f2e8a543d07370c6c1c369cfbfb" +"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum serde 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)" = "a73973861352c932ed1365ce22b32467ce260ac4c8db11cf750ce56334ff2dcf" +"checksum serde_derive 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b392c5a0cebb98121454531c50e60e2ffe0fbeb1a44da277da2d681d08d7dc0b" +"checksum serde_derive_internals 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9d30c4596450fd7bbda79ef15559683f9a79ac0193ea819db90000d7e1cae794" +"checksum syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "91b52877572087400e83d24b9178488541e3d535259e04ff17a63df1e5ceff59" +"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" +"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" +"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/native/Cargo.toml b/native/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..715d044c4817902806cae7bbf50f1af2f5833eb5 --- /dev/null +++ b/native/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "wotb-rs" +version = "0.1.0" +authors = ["librelois <elois@ifee.fr>"] +license = "AGPL-3.0" +build = "build.rs" + +[lib] +name = "wotb_rs" +crate-type = ["dylib"] + +[build-dependencies] +neon-build = "0.1.22" + +[dependencies] +neon = "0.1.22" +num_cpus = "1.8.0" +duniter-wotb = "0.7.1" diff --git a/native/build.rs b/native/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..687a6619460e768d374855902515d54e52d23a56 --- /dev/null +++ b/native/build.rs @@ -0,0 +1,7 @@ +extern crate neon_build; + +fn main() { + neon_build::setup(); // must be called in build.rs + + // add project-specific build logic here... +} diff --git a/native/src/lib.rs b/native/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..846077eab3893242dc676e3b1ef4c3606504c9e3 --- /dev/null +++ b/native/src/lib.rs @@ -0,0 +1,332 @@ +#[macro_use] +extern crate neon; + +extern crate duniter_wotb; +extern crate num_cpus; + +use duniter_wotb::rusty::RustyWebOfTrust; +use duniter_wotb::{HasLinkResult, NewLinkResult, NodeId, RemLinkResult, WebOfTrust, WotDistance, + WotDistanceParameters}; +use neon::js::{JsArray, JsBoolean, JsInteger, JsNumber, JsObject, JsString, Object}; +use neon::vm::{Call, JsResult}; +use std::collections::HashMap; +use std::ops::{Deref, DerefMut}; + +static mut WOT_INSTANCES: Option<HashMap<usize, Box<RustyWebOfTrust>>> = None; + +fn get_wots() -> &'static mut HashMap<usize, Box<RustyWebOfTrust>> { + unsafe { + match WOT_INSTANCES { + Some(ref mut x) => &mut *x, + None => { + WOT_INSTANCES = Some(HashMap::new()); + match WOT_INSTANCES { + Some(ref mut x) => &mut *x, + None => panic!(), + } + } + } + } +} + +fn new_wot(max_links: usize) -> usize { + let wots = get_wots(); + let mut instance_id = 0; + while wots.contains_key(&instance_id) { + instance_id += 1; + } + wots.insert(instance_id, Box::new(RustyWebOfTrust::new(max_links))); + instance_id +} + +fn get_wot<'a>(instance_id: usize) -> &'a RustyWebOfTrust { + let wots = get_wots(); + let wot = wots.get(&instance_id); + match wot { + Some(wot) => wot.deref(), + None => panic!("This instance don't exist !"), + } +} + +fn get_mut_wot<'a>(instance_id: usize) -> &'a mut RustyWebOfTrust { + let wots = get_wots(); + let wot = wots.get_mut(&instance_id); + match wot { + Some(wot) => wot.deref_mut(), + None => panic!("This instance don't exist !"), + } +} + +fn hello(call: Call) -> JsResult<JsString> { + let scope = call.scope; + let args = call.arguments; + let mut str_ = String::from("hello node"); + //let x = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + if let Some(arg) = args.get(scope, 0) { + let x = try!(arg.check::<JsInteger>()).value(); + str_.push_str(&format!(" {}", x)); + } + Ok(JsString::new(scope, &str_).unwrap()) +} + +fn threading_hint(call: Call) -> JsResult<JsNumber> { + Ok(JsNumber::new(call.scope, num_cpus::get() as f64)) +} + +fn new_memory_instance(call: Call) -> JsResult<JsInteger> { + let scope = call.scope; + let max_links = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let _instance_id = new_wot(max_links as usize); + Ok(JsInteger::new(scope, _instance_id as i32)) +} + +fn mem_copy(call: Call) -> JsResult<JsInteger> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value() as usize; + let wots = get_wots(); + let wot_copy = wots.get(&instance_id).expect("This instance don't exist !").deref().clone(); + let mut new_instance_id = 0; + while wots.contains_key(&new_instance_id) { + new_instance_id += 1; + } + wots.insert(new_instance_id, Box::new(wot_copy)); + Ok(JsInteger::new(scope, new_instance_id as i32)) +} + +fn get_max_links(call: Call) -> JsResult<JsInteger> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let mut _max_links = 0; + _max_links = get_wot(instance_id as usize).get_max_link(); + Ok(JsInteger::new(scope, _max_links as i32)) +} + +fn get_wot_size(call: Call) -> JsResult<JsInteger> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let mut _size = 0; + _size = get_wot(instance_id as usize).size(); + Ok(JsInteger::new(scope, _size as i32)) +} + +fn is_enabled(call: Call) -> JsResult<JsBoolean> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let node_id = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value(); + if get_wot(instance_id as usize) + .is_enabled(NodeId(node_id as usize)) + .unwrap() + { + Ok(JsBoolean::new(scope, true)) + } else { + Ok(JsBoolean::new(scope, false)) + } +} + +fn get_enabled(call: Call) -> JsResult<JsObject> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let enabled = get_mut_wot(instance_id as usize).get_enabled(); + let mut js_array = JsObject::new(scope); + let mut index: u32 = 0; + for node_id in enabled { + let _bool = JsObject::set( + *js_array.deref_mut(), + index, + JsInteger::new(scope, node_id.0 as i32), + ); + index += 1; + } + Ok(js_array) +} + +fn get_disabled(call: Call) -> JsResult<JsArray> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let disabled = get_mut_wot(instance_id as usize).get_disabled(); + let js_array = JsArray::new(scope, disabled.len() as u32); + let mut index: u32 = 0; + for node_id in disabled { + let _bool = JsArray::set( + *js_array.deref(), + index, + JsInteger::new(scope, node_id.0 as i32), + ); + index += 1; + } + Ok(js_array) +} + +fn exist_link(call: Call) -> JsResult<JsBoolean> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let source = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value(); + let target = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value(); + let result = + get_wot(instance_id as usize).has_link(NodeId(source as usize), NodeId(target as usize)); + if let HasLinkResult::Link(has_link) = result { + Ok(JsBoolean::new(scope, has_link)) + } else { + panic!("Fatal Error : {:?}", result) + } +} + +fn set_max_links(call: Call) -> JsResult<JsBoolean> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let max_links = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value(); + let _result = get_mut_wot(instance_id as usize).set_max_link(max_links as usize); + Ok(JsBoolean::new(scope, true)) +} + +fn add_node(call: Call) -> JsResult<JsInteger> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let _node_id = get_mut_wot(instance_id as usize).add_node(); + Ok(JsInteger::new(scope, _node_id.0 as i32)) +} + +fn rem_node(call: Call) -> JsResult<JsInteger> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + if let Some(node_id) = get_mut_wot(instance_id as usize).rem_node() { + Ok(JsInteger::new(scope, node_id.0 as i32)) + } else { + panic!("Fatal error : wotb : you try to remove a node to empty wot !") + } +} + +fn set_enabled(call: Call) -> JsResult<JsBoolean> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let is_enabled = try!(try!(call.arguments.require(scope, 1)).check::<JsBoolean>()).value(); + let node_id = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value(); + if let Some(enabled) = + get_mut_wot(instance_id as usize).set_enabled(NodeId(node_id as usize), is_enabled) + { + Ok(JsBoolean::new(scope, enabled)) + } else { + panic!("Fatal error : wotb : node id don't exist !") + } +} + +fn add_link(call: Call) -> JsResult<JsInteger> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let source = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value(); + let target = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value(); + let result = get_mut_wot(instance_id as usize) + .add_link(NodeId(source as usize), NodeId(target as usize)); + if let NewLinkResult::Ok(links_count) = result { + Ok(JsInteger::new(scope, links_count as i32)) + } else { + panic!("Fatal error wotb : {:?}", result) + } +} + +fn rem_link(call: Call) -> JsResult<JsInteger> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let source = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value(); + let target = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value(); + let result = get_mut_wot(instance_id as usize) + .rem_link(NodeId(source as usize), NodeId(target as usize)); + if let RemLinkResult::Removed(links_count) = result { + Ok(JsInteger::new(scope, links_count as i32)) + } else { + panic!("Fatal Error : {:?}", result) + } +} + +fn compute_distance(call: Call) -> JsResult<JsObject> { + let scope = call.scope; + let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value(); + let node_id = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value(); + let sentry_requirement = + try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value() as u32; + let step_max = try!(try!(call.arguments.require(scope, 3)).check::<JsInteger>()).value() as u32; + let x_percent = try!(try!(call.arguments.require(scope, 4)).check::<JsNumber>()).value() as f64; + let distance_params = WotDistanceParameters { + node: NodeId(node_id as usize), + sentry_requirement, + step_max, + x_percent, + }; + let WotDistance { + sentries, + success, + success_at_border, + reached, + reached_at_border, + outdistanced, + } = get_wot(instance_id as usize) + .compute_distance(distance_params) + .unwrap(); + let js_object = JsObject::new(scope); + let _bool = JsObject::set( + *js_object.deref(), + "sentries", + JsInteger::new(scope, sentries as i32), + ); + let _bool = JsObject::set( + *js_object.deref(), + "success", + JsInteger::new(scope, success as i32), + ); + let _bool = JsObject::set( + *js_object.deref(), + "success_at_border", + JsInteger::new(scope, success_at_border as i32), + ); + let _bool = JsObject::set( + *js_object.deref(), + "reached", + JsInteger::new(scope, reached as i32), + ); + let _bool = JsObject::set( + *js_object.deref(), + "reached_at_border", + JsInteger::new(scope, reached_at_border as i32), + ); + let _bool = JsObject::set( + *js_object.deref(), + "outdistanced", + JsBoolean::new(scope, outdistanced), + ); + Ok(js_object) +} + +fn remove_wot(call: Call) -> JsResult<JsBoolean> { + let scope = call.scope; + let instance_id = + try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value() as usize; + let wots = get_wots(); + if wots.len() > instance_id { + wots.remove(&instance_id).unwrap(); + Ok(JsBoolean::new(scope, true)) + } else { + Ok(JsBoolean::new(scope, false)) + } +} + +register_module!(m, { + m.export("hello", hello)?; + m.export("threadingHint", threading_hint)?; + m.export("new_memory_instance", new_memory_instance)?; + m.export("mem_copy", mem_copy)?; + m.export("get_max_links", get_max_links)?; + m.export("get_wot_size", get_wot_size)?; + m.export("is_enabled", is_enabled)?; + m.export("get_enabled", get_enabled)?; + m.export("get_disabled", get_disabled)?; + m.export("exist_link", exist_link)?; + m.export("set_max_links", set_max_links)?; + m.export("add_node", add_node)?; + m.export("rem_node", rem_node)?; + m.export("set_enabled", set_enabled)?; + m.export("add_link", add_link)?; + m.export("rem_link", rem_link)?; + m.export("compute_distance", compute_distance)?; + m.export("remove_wot", remove_wot)?; + Ok(()) +}); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000000000000000000000000000000000000..3aa43206c8efac6f698458fd7d3fd2056fbfff82 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,989 @@ +{ + "name": "wotb-rs", + "version": "0.1.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "align-text": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", + "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", + "requires": { + "kind-of": "3.2.2", + "longest": "1.0.1", + "repeat-string": "1.6.1" + } + }, + "amdefine": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", + "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=" + }, + "ansi-escape-sequences": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/ansi-escape-sequences/-/ansi-escape-sequences-4.0.0.tgz", + "integrity": "sha512-v+0wW9Wezwsyb0uF4aBVCjmSqit3Ru7PZFziGF0o2KwTvN2zWfTi3BRLq9EkJFdg3eBbyERXGTntVpBxH1J68Q==", + "requires": { + "array-back": "2.0.0" + } + }, + "ansi-escapes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", + "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==" + }, + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "1.9.1" + } + }, + "array-back": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-2.0.0.tgz", + "integrity": "sha512-eJv4pLLufP3g5kcZry0j6WXpIbzYw9GUB4mVJZno9wfwiBxbizTnHCw3VJb07cBihbFX48Y7oSrW9y+gt4glyw==", + "requires": { + "typical": "2.6.1" + } + }, + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" + }, + "aws-sdk": { + "version": "2.2.43", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.2.43.tgz", + "integrity": "sha1-aQWANKrhdTN3QJYcztd3ZkpuvU0=", + "dev": true, + "requires": { + "sax": "1.1.5", + "xml2js": "0.4.15", + "xmlbuilder": "2.6.2" + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "builtins": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/builtins/-/builtins-1.0.3.tgz", + "integrity": "sha1-y5T662HIaWRR2zZTThQi+U8K7og=" + }, + "camelcase": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", + "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", + "optional": true + }, + "center-align": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", + "integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=", + "optional": true, + "requires": { + "align-text": "0.1.4", + "lazy-cache": "1.0.4" + } + }, + "chalk": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.1.0.tgz", + "integrity": "sha512-LUHGS/dge4ujbXMJrnihYMcL4AoOweGnw9Tp3kQuqy1Kx5c1qKjqvMJZ6nVJPMWJtKCTN72ZogH3oeSO9g9rXQ==", + "requires": { + "ansi-styles": "3.2.1", + "escape-string-regexp": "1.0.5", + "supports-color": "4.5.0" + } + }, + "chardet": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", + "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=" + }, + "cli-cursor": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", + "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", + "requires": { + "restore-cursor": "2.0.0" + } + }, + "cli-width": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", + "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=" + }, + "cliui": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", + "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", + "optional": true, + "requires": { + "center-align": "0.1.3", + "right-align": "0.1.3", + "wordwrap": "0.0.2" + }, + "dependencies": { + "wordwrap": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", + "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", + "optional": true + } + } + }, + "color-convert": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", + "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "command-line-args": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-4.0.7.tgz", + "integrity": "sha512-aUdPvQRAyBvQd2n7jXcsMDz68ckBJELXNzBybCHOibUWEg0mWTnaYCSRU8h9R+aNRSvDihJtssSRCiDRpLaezA==", + "requires": { + "array-back": "2.0.0", + "find-replace": "1.0.3", + "typical": "2.6.1" + } + }, + "command-line-commands": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/command-line-commands/-/command-line-commands-2.0.1.tgz", + "integrity": "sha512-m8c2p1DrNd2ruIAggxd/y6DgygQayf6r8RHwchhXryaLF8I6koYjoYroVP+emeROE9DXN5b9sP1Gh+WtvTTdtQ==", + "requires": { + "array-back": "2.0.0" + } + }, + "command-line-usage": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/command-line-usage/-/command-line-usage-4.1.0.tgz", + "integrity": "sha512-MxS8Ad995KpdAC0Jopo/ovGIroV/m0KHwzKfXxKag6FHOkGsH8/lv5yjgablcRxCJJC0oJeUMuO/gmaq+Wq46g==", + "requires": { + "ansi-escape-sequences": "4.0.0", + "array-back": "2.0.0", + "table-layout": "0.4.3", + "typical": "2.6.1" + } + }, + "commander": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz", + "integrity": "sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM=", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "debug": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.0.0.tgz", + "integrity": "sha1-ib2d9nMrUSVrxnBTQrugLtEhMe8=", + "dev": true, + "requires": { + "ms": "0.6.2" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "optional": true + }, + "deep-extend": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.0.tgz", + "integrity": "sha1-bvSgmwX5iw41jW2T1Mo8rsZnKAM=" + }, + "diff": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz", + "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "external-editor": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", + "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", + "requires": { + "chardet": "0.4.2", + "iconv-lite": "0.4.21", + "tmp": "0.0.33" + } + }, + "figures": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", + "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", + "requires": { + "escape-string-regexp": "1.0.5" + } + }, + "find-replace": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-1.0.3.tgz", + "integrity": "sha1-uI5zZNLZyVlVnziMZmcNYTBEH6A=", + "requires": { + "array-back": "1.0.4", + "test-value": "2.1.0" + }, + "dependencies": { + "array-back": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-1.0.4.tgz", + "integrity": "sha1-ZEun8JX3/898Q7Xw3DnTwfA8Bjs=", + "requires": { + "typical": "2.6.1" + } + } + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "git-config": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/git-config/-/git-config-0.0.7.tgz", + "integrity": "sha1-qcij7wendsPXImE1bYtye2IgKyg=", + "requires": { + "iniparser": "1.0.5" + } + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "graceful-fs": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz", + "integrity": "sha1-fNLNsiiko/Nule+mzBQt59GhNtA=", + "dev": true + }, + "growl": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.8.1.tgz", + "integrity": "sha1-Sy3sjZB+k9szZiTc7AGDUC+MlCg=", + "dev": true + }, + "handlebars": { + "version": "4.0.11", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", + "integrity": "sha1-Ywo13+ApS8KB7a5v/F0yn8eYLcw=", + "requires": { + "async": "1.5.2", + "optimist": "0.6.1", + "source-map": "0.4.4", + "uglify-js": "2.8.29" + } + }, + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" + }, + "iconv-lite": { + "version": "0.4.21", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.21.tgz", + "integrity": "sha512-En5V9za5mBt2oUA03WGD3TwDv0MKAruqsuxstbMUZaj9W9k/m1CV/9py3l0L5kw9Bln8fdHQmzHSYtvpvTLpKw==", + "requires": { + "safer-buffer": "2.1.2" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "iniparser": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/iniparser/-/iniparser-1.0.5.tgz", + "integrity": "sha1-g21r7+bfv87gvM8c+fKsxwJ/eD0=" + }, + "inquirer": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz", + "integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==", + "requires": { + "ansi-escapes": "3.1.0", + "chalk": "2.1.0", + "cli-cursor": "2.1.0", + "cli-width": "2.2.0", + "external-editor": "2.2.0", + "figures": "2.0.0", + "lodash": "4.17.5", + "mute-stream": "0.0.7", + "run-async": "2.3.0", + "rx-lite": "4.0.8", + "rx-lite-aggregates": "4.0.8", + "string-width": "2.1.1", + "strip-ansi": "4.0.0", + "through": "2.3.8" + } + }, + "is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==" + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" + }, + "jade": { + "version": "0.26.3", + "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", + "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", + "dev": true, + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, + "dependencies": { + "commander": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", + "dev": true + }, + "mkdirp": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", + "dev": true + } + } + }, + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "requires": { + "is-buffer": "1.1.6" + } + }, + "lazy-cache": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", + "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", + "optional": true + }, + "lodash": { + "version": "4.17.5", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" + }, + "lodash.padend": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/lodash.padend/-/lodash.padend-4.6.1.tgz", + "integrity": "sha1-U8y6BH0G4VjTEfRdpiX05J5vFm4=" + }, + "longest": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", + "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=" + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "mimic-fn": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "1.1.11" + } + }, + "minimist": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + } + } + }, + "mocha": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-2.2.5.tgz", + "integrity": "sha1-07cqT+SeyUOTU/GsiT28Qw2ZMUA=", + "dev": true, + "requires": { + "commander": "2.3.0", + "debug": "2.0.0", + "diff": "1.4.0", + "escape-string-regexp": "1.0.2", + "glob": "3.2.3", + "growl": "1.8.1", + "jade": "0.26.3", + "mkdirp": "0.5.0", + "supports-color": "1.2.1" + }, + "dependencies": { + "escape-string-regexp": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz", + "integrity": "sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=", + "dev": true + }, + "glob": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz", + "integrity": "sha1-4xPusknHr/qlxHUoaw4RW1mDlGc=", + "dev": true, + "requires": { + "graceful-fs": "2.0.3", + "inherits": "2.0.3", + "minimatch": "0.2.14" + } + }, + "minimatch": { + "version": "0.2.14", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", + "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", + "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "supports-color": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.2.1.tgz", + "integrity": "sha1-Eu4hUHCGzZjBBY2ewPSsR2t687I=", + "dev": true + } + } + }, + "ms": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz", + "integrity": "sha1-2JwhJMb9wTU9Zai3e/GqxLGTcIw=", + "dev": true + }, + "mute-stream": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", + "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=" + }, + "neon-cli": { + "version": "0.1.22", + "resolved": "https://registry.npmjs.org/neon-cli/-/neon-cli-0.1.22.tgz", + "integrity": "sha512-347dLid0g82Jc/wD0crX2sRXBdcu7fnZdlUVCE96xrjoJBqhgKxCB/3+W+jYPtI1x5nl9vWIqcHbiD8PhlwdVw==", + "requires": { + "chalk": "2.1.0", + "command-line-args": "4.0.7", + "command-line-commands": "2.0.1", + "command-line-usage": "4.1.0", + "git-config": "0.0.7", + "handlebars": "4.0.11", + "inquirer": "3.3.0", + "mkdirp": "0.5.1", + "quickly-copy-file": "1.0.0", + "rimraf": "2.6.2", + "rsvp": "4.8.2", + "semver": "5.5.0", + "toml": "2.3.3", + "ts-typed-json": "0.2.2", + "validate-npm-package-license": "3.0.3", + "validate-npm-package-name": "3.0.0" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1.0.2" + } + }, + "onetime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", + "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "requires": { + "mimic-fn": "1.2.0" + } + }, + "optimist": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", + "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", + "requires": { + "minimist": "0.0.10", + "wordwrap": "0.0.3" + } + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "quickly-copy-file": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/quickly-copy-file/-/quickly-copy-file-1.0.0.tgz", + "integrity": "sha1-n4/wZiMFEO50IrASFHKwk6hpCFk=", + "requires": { + "mkdirp": "0.5.1" + } + }, + "reduce-flatten": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/reduce-flatten/-/reduce-flatten-1.0.1.tgz", + "integrity": "sha1-JYx479FT3fk8tWEjf2EYTzaW4yc=" + }, + "repeat-string": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", + "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=" + }, + "restore-cursor": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", + "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", + "requires": { + "onetime": "2.0.1", + "signal-exit": "3.0.2" + } + }, + "right-align": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", + "integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=", + "optional": true, + "requires": { + "align-text": "0.1.4" + } + }, + "rimraf": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "requires": { + "glob": "7.1.2" + } + }, + "rsvp": { + "version": "4.8.2", + "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.2.tgz", + "integrity": "sha512-8CU1Wjxvzt6bt8zln+hCjyieneU9s0LRW+lPRsjyVCY8Vm1kTbK7btBIrCGg6yY9U4undLDm/b1hKEEi1tLypg==" + }, + "run-async": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "requires": { + "is-promise": "2.1.0" + } + }, + "rx-lite": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", + "integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=" + }, + "rx-lite-aggregates": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz", + "integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=", + "requires": { + "rx-lite": "4.0.8" + } + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "sax": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.1.5.tgz", + "integrity": "sha1-HaUKjQDN7NWUBWWfX/hTSf53N0M=", + "dev": true + }, + "semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + }, + "should": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/should/-/should-8.1.1.tgz", + "integrity": "sha1-ZHlt3Ci997OMQ0UY0pL+/1HxPGU=", + "dev": true, + "requires": { + "should-equal": "0.6.0", + "should-format": "0.3.2", + "should-type": "0.2.0" + } + }, + "should-equal": { + "version": "0.6.0", + "resolved": "http://registry.npmjs.org/should-equal/-/should-equal-0.6.0.tgz", + "integrity": "sha1-W0cDA6iPW5YKfRCRciS0VU2rRww=", + "dev": true, + "requires": { + "should-type": "0.2.0" + } + }, + "should-format": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/should-format/-/should-format-0.3.2.tgz", + "integrity": "sha1-pZgx4Bot3uFJkRvHFIvlyAMZ4f8=", + "dev": true, + "requires": { + "should-type": "0.2.0" + } + }, + "should-type": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/should-type/-/should-type-0.2.0.tgz", + "integrity": "sha1-ZwfvlVKdmJ3MCY/gdTqx+RNrt/Y=", + "dev": true + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" + }, + "source-map": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", + "requires": { + "amdefine": "1.0.1" + } + }, + "spdx-correct": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz", + "integrity": "sha512-N19o9z5cEyc8yQQPukRCZ9EUmb4HUpnrmaL/fxS2pBo2jbfcFRVuFZ/oFC+vZz0MNNk0h80iMn5/S6qGZOL5+g==", + "requires": { + "spdx-expression-parse": "3.0.0", + "spdx-license-ids": "3.0.0" + } + }, + "spdx-exceptions": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.1.0.tgz", + "integrity": "sha512-4K1NsmrlCU1JJgUrtgEeTVyfx8VaYea9J9LvARxhbHtVtohPs/gFGG5yy49beySjlIMhhXZ4QqujIZEfS4l6Cg==" + }, + "spdx-expression-parse": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", + "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "requires": { + "spdx-exceptions": "2.1.0", + "spdx-license-ids": "3.0.0" + } + }, + "spdx-license-ids": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.0.tgz", + "integrity": "sha512-2+EPwgbnmOIl8HjGBXXMd9NAu02vLjOO1nWw4kmeRDFyHn+M/ETfHxQUK0oXg8ctgVnl9t3rosNVsZ1jG61nDA==" + }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "requires": { + "is-fullwidth-code-point": "2.0.0", + "strip-ansi": "4.0.0" + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "requires": { + "ansi-regex": "3.0.0" + } + }, + "supports-color": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", + "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", + "requires": { + "has-flag": "2.0.0" + } + }, + "table-layout": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/table-layout/-/table-layout-0.4.3.tgz", + "integrity": "sha512-MIhflPM38ejKrFwWwC3P9x3eHvMo5G5AmNo29Qtz2HpBl5KD2GCcmOErjgNtUQLv/qaqVDagfJY3rJLPDvEgLg==", + "requires": { + "array-back": "2.0.0", + "deep-extend": "0.5.0", + "lodash.padend": "4.6.1", + "typical": "2.6.1", + "wordwrapjs": "3.0.0" + } + }, + "test-value": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/test-value/-/test-value-2.1.0.tgz", + "integrity": "sha1-Edpv9nDzRxpztiXKTz/c97t0gpE=", + "requires": { + "array-back": "1.0.4", + "typical": "2.6.1" + }, + "dependencies": { + "array-back": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-1.0.4.tgz", + "integrity": "sha1-ZEun8JX3/898Q7Xw3DnTwfA8Bjs=", + "requires": { + "typical": "2.6.1" + } + } + } + }, + "through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" + }, + "tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "requires": { + "os-tmpdir": "1.0.2" + } + }, + "toml": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/toml/-/toml-2.3.3.tgz", + "integrity": "sha512-O7L5hhSQHxuufWUdcTRPfuTh3phKfAZ/dqfxZFoxPCj2RYmpaSGLEIs016FCXItQwNr08yefUB5TSjzRYnajTA==" + }, + "ts-typed-json": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/ts-typed-json/-/ts-typed-json-0.2.2.tgz", + "integrity": "sha1-UxhL7ok+RZkbc8jEY6OLWeJ81H4=", + "requires": { + "rsvp": "3.6.2" + }, + "dependencies": { + "rsvp": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-3.6.2.tgz", + "integrity": "sha512-OfWGQTb9vnwRjwtA2QwpG2ICclHC3pgXZO5xt8H2EfgDquO0qVdSb5T88L4qJVAEugbS56pAuV4XZM58UX8ulw==" + } + } + }, + "typical": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", + "integrity": "sha1-XAgOXWYcu+OCWdLnCjxyU+hziB0=" + }, + "uglify-js": { + "version": "2.8.29", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", + "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", + "optional": true, + "requires": { + "source-map": "0.5.7", + "uglify-to-browserify": "1.0.2", + "yargs": "3.10.0" + }, + "dependencies": { + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "optional": true + } + } + }, + "uglify-to-browserify": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", + "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", + "optional": true + }, + "validate-npm-package-license": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz", + "integrity": "sha512-63ZOUnL4SIXj4L0NixR3L1lcjO38crAbgrTpl28t8jjrfuiOBL5Iygm+60qPs/KsZGzPNg6Smnc/oY16QTjF0g==", + "requires": { + "spdx-correct": "3.0.0", + "spdx-expression-parse": "3.0.0" + } + }, + "validate-npm-package-name": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz", + "integrity": "sha1-X6kS2B630MdK/BQN5zF/DKffQ34=", + "requires": { + "builtins": "1.0.3" + } + }, + "window-size": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", + "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=", + "optional": true + }, + "wordwrap": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", + "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=" + }, + "wordwrapjs": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/wordwrapjs/-/wordwrapjs-3.0.0.tgz", + "integrity": "sha512-mO8XtqyPvykVCsrwj5MlOVWvSnCdT+C+QVbm6blradR7JExAhbkZ7hZ9A+9NUtwzSqrlUo9a67ws0EiILrvRpw==", + "requires": { + "reduce-flatten": "1.0.1", + "typical": "2.6.1" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "xml2js": { + "version": "0.4.15", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.15.tgz", + "integrity": "sha1-lc0D/y3RROwovGJzvysokMWBrQw=", + "dev": true, + "requires": { + "sax": "1.1.5", + "xmlbuilder": "2.6.2" + } + }, + "xmlbuilder": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-2.6.2.tgz", + "integrity": "sha1-+Rb20Q1F3BcbG+Lm5nP7bgzDXQo=", + "dev": true, + "requires": { + "lodash": "3.5.0" + }, + "dependencies": { + "lodash": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.5.0.tgz", + "integrity": "sha1-Gbs/TVEnjwuMgY7RRcdOz5/kDm0=", + "dev": true + } + } + }, + "yargs": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", + "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", + "optional": true, + "requires": { + "camelcase": "1.2.1", + "cliui": "2.1.0", + "decamelize": "1.2.0", + "window-size": "0.1.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000000000000000000000000000000000000..478510008d2640a9434e760c1446bd5adc6ed384 --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "wotb-rs", + "version": "0.1.0", + "description": "Makes Web of Trust computations for the Duniter project.", + "main": "lib/index.js", + "repository": { + "type": "git", + "url": "https://git.duniter.org/nodes/typescript/wotb-rust" + }, + "author": "librelois <elois@ifee.fr>", + "license": "AGPL-3.0", + "engines": { + "node": ">=9.4.0", + "npm": ">=5.6.0" + }, + "dependencies": { + "neon-cli": "^0.1.22" + }, + "devDependencies": { + "aws-sdk": "2.2.43", + "mocha": "2.2.5", + "should": "8.1.1" + }, + "scripts": { + "test": "node \"node_modules/mocha/bin/mocha\" tests/", + "install": "neon build" + } +} diff --git a/tests/test.js b/tests/test.js new file mode 100644 index 0000000000000000000000000000000000000000..2ebc8039eccc219d06938ed5095b94f85142d8c7 --- /dev/null +++ b/tests/test.js @@ -0,0 +1,245 @@ +"use strict"; + +const addon = require('./../lib/index'); +var assert = require('assert'); +var fs = require('fs'); +var path = require('path'); +var should = require('should'); + +const FILE = path.join(__dirname, 'test.wot'); +const X_PERCENT = 1.0; +const _100_PERCENT = 1.0; +const MAX_DISTANCE_1 = 1; +const MAX_DISTANCE_2 = 2; +const MAX_DISTANCE_3 = 3; +const MAX_DISTANCE_4 = 4; +const MAX_DISTANCE_5 = 5; +const FROM_1_LINK_SENTRIES = 1; +const FROM_2_LINKS_SENTRIES = 2; +const FROM_3_LINKS_SENTRIES = 3; +const __OUTDISTANCED__ = true; +const __OK__ = false; +const MEMORY_MODE = true; +const FILE_MODE = false; + +testSuite("MEMORY", MEMORY_MODE); + +function testSuite(title, mode) { + function newInstance(launchTests) { + return () => { + if (mode === FILE_MODE) { + let wot = addon.newFileInstance(FILE); + launchTests(wot, () => { + wot.drop(); + wot.setMaxCert(3); + }); + } else { + let wot = addon.newMemoryInstance(3); + launchTests(wot, () => {}); + } + } + } + + describe(title, () => { + describe('Basic operations', newInstance((wot, cleanInstance) => { + + it('should have an instanceID zero', function() { + assert.equal(wot.instanceID, 0) + }); + + it('should have 3 max links', function() { + assert.equal(wot.getMaxCert(), 3) + }); + + it('should have an initial size of 0', function() { + should.equal(wot.getWoTSize(), 0); + }); + + it('should give number 0 if we add a node', function() { + // Add a node + should.equal(wot.addNode(), 0); + should.equal(wot.getWoTSize(), 1); + should.equal(wot.isEnabled(0), true); + should.equal(wot.getEnabled().length, 1); + should.equal(wot.getDisabled().length, 0); + // Add another + should.equal(wot.addNode(), 1); + should.equal(wot.getWoTSize(), 2); + should.equal(wot.getEnabled().length, 2); + should.equal(wot.getDisabled().length, 0); + // Add 10 nodes + for (let i = 0; i < 10; i++) { + should.equal(wot.addNode(), i + 2); + } + should.equal(wot.getWoTSize(), 2 + 10); + should.equal(wot.getEnabled().length, 2 + 10); + }); + + it('should add certs only in the boundaries of maxCert', () => { + wot.addLink(0, 1); + wot.addLink(0, 2); + wot.addLink(0, 3); + //wot.addLink(0, 4); + should.equal(wot.getMaxCert(), 3); + should.equal(wot.existsLink(0, 1), true); + should.equal(wot.existsLink(0, 2), true); + should.equal(wot.existsLink(0, 3), true); + should.equal(wot.existsLink(0, 4), false); + wot.setMaxCert(4); + should.equal(wot.getMaxCert(), 4); + should.equal(wot.existsLink(0, 4), false); + wot.addLink(0, 4); + should.equal(wot.existsLink(0, 4), true); + wot.removeLink(0,1); + wot.removeLink(0,2); + wot.removeLink(0,3); + wot.removeLink(0,4); + }); + + it('should not throw if testing existsLink() with inbounds link', function() { + should.equal(wot.existsLink(4, 6), false); + }); + + it('first 4 nodes should be enabled', function() { + should.equal(wot.isEnabled(0), true); + should.equal(wot.isEnabled(1), true); + should.equal(wot.isEnabled(2), true); + should.equal(wot.isEnabled(3), true); + }); + + it('last node should be enabled', function() { + should.equal(wot.isEnabled(11), true); + }); + + it('should be able to disable some nodes', function() { + should.equal(wot.setEnabled(false, 0), false); + should.equal(wot.setEnabled(false, 1), false); + should.equal(wot.setEnabled(false, 2), false); + should.equal(wot.getDisabled().length, 3); + should.equal(wot.setEnabled(true, 1), true); + }); + + it('nodes 0 and 2 should be disabled', function() { + should.equal(wot.isEnabled(0), false); + should.equal(wot.isEnabled(1), true); + should.equal(wot.isEnabled(2), false); + should.equal(wot.isEnabled(3), true); + // Set enabled again + should.equal(wot.setEnabled(true, 0), true); + should.equal(wot.setEnabled(true, 1), true); + should.equal(wot.setEnabled(true, 2), true); + should.equal(wot.setEnabled(true, 1), true); + should.equal(wot.getDisabled().length, 0); + }); + + it('should not exist a link from 2 to 0', function() { + should.equal(wot.existsLink(2, 0), false); + }); + + it('should be able to add some links', function() { + should.equal(wot.addLink(2, 0), 1); + should.equal(wot.addLink(4, 0), 2); + //should.equal(wot.addLink(4, 0), 2); + should.equal(wot.addLink(5, 0), 3); + }); + + it('should exist new links', function() { + /** + * WoT is: + * + * 2 --> 0 + * 4 --> 0 + * 5 --> 0 + */ + should.equal(wot.existsLink(2, 0), true); + should.equal(wot.existsLink(4, 0), true); + should.equal(wot.existsLink(5, 0), true); + should.equal(wot.existsLink(2, 1), false); + }); + + it('should be able to remove some links', function() { + should.equal(wot.removeLink(4, 0), 2); + /** + * WoT is now: + * + * 2 --> 0 + * 5 --> 0 + */ + }); + + it('should exist less links', function() { + should.equal(wot.existsLink(2, 0), true); + should.equal(wot.existsLink(4, 0), false); + should.equal(wot.existsLink(5, 0), true); + should.equal(wot.existsLink(2, 1), false); + }); + + it('should successfully use distance rule', function() { + should.equal(wot.isOutdistanced(0, FROM_1_LINK_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // No because 2,4,5 have certified him + should.equal(wot.isOutdistanced(0, FROM_2_LINKS_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // No because only member 2 has 2 certs, and has certified him + should.equal(wot.isOutdistanced(0, FROM_3_LINKS_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // No because no member has issued 3 certifications + // We add links from member 3 + should.equal(wot.addLink(3, 1), 1); + should.equal(wot.addLink(3, 2), 1); + /** + * WoT is now: + * + * 2 --> 0 + * 5 --> 0 + * 3 --> 1 + * 3 --> 2 + */ + should.equal(wot.getWoTSize(), 12); + should.equal(wot.isOutdistanced(0, FROM_1_LINK_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // OK: 2 --> 0 + should.equal(wot.isOutdistanced(0, FROM_2_LINKS_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // OK: 2 --> 0 + should.equal(wot.isOutdistanced(0, FROM_3_LINKS_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // OK: no sentry with 3 links issued + should.equal(wot.isOutdistanced(0, FROM_2_LINKS_SENTRIES, MAX_DISTANCE_2, X_PERCENT), __OK__); // OK: 2 --> 0 + + wot.addLink(1, 3); + wot.addLink(2, 3); + + should.equal(wot.getWoTSize(), 12); + should.equal(wot.isOutdistanced(0, FROM_1_LINK_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OUTDISTANCED__); // KO: No path 3 --> 0 + should.equal(wot.isOutdistanced(0, FROM_2_LINKS_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OUTDISTANCED__); // KO: No path 3 --> 0 + should.equal(wot.isOutdistanced(0, FROM_3_LINKS_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // OK: no sentry with 3 links issued + should.equal(wot.isOutdistanced(0, FROM_2_LINKS_SENTRIES, MAX_DISTANCE_2, X_PERCENT), __OK__); // OK: 3 --> 2 --> 0 + }); + + it('should have 12 nodes', function() { + should.equal(wot.getWoTSize(), 12); + }); + + it('delete top node', function() { + should.equal(wot.removeNode(), 10); + }); + + it('should have 11 nodes', function() { + should.equal(wot.getWoTSize(), 11); + }); + + it('should work with member 3 disabled', function() { + // With member 3 disabled (non-member) + should.equal(wot.setEnabled(false, 3), false); + should.equal(wot.getDisabled().length, 1); + should.equal(wot.isOutdistanced(0, FROM_2_LINKS_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // OK: No path 3 --> 0, but is disabled + }); + + it('should be able to make a mem copy', function() { + const copy = wot.memCopy(); + should.equal(copy.setEnabled(false, 3), false); + should.equal(wot.getDisabled().length, 1); + should.equal(copy.isOutdistanced(0, FROM_2_LINKS_SENTRIES, MAX_DISTANCE_1, X_PERCENT), __OK__); // OK: No path 3 --> 0, but is disabled + copy.clear(); + }); + + it('should drop this instance and create new instance with id zero', function() { + wot.clear(); + var wot2 = addon.newMemoryInstance(100); + should.equal(wot2.instanceID, 0); + wot2.clear() + }); + + after(cleanInstance); + })); + }); +} \ No newline at end of file