git ssb

0+

wanderer🌟 / js-primea-objects



Commit eed85c976be79699b77f859046143b69e0c94b5e

build docs

wanderer committed on 3/27/2018, 7:31:15 PM
Parent: 136ef4bd7ca697c515688fa0a7b42c49930b5710

Files changed

README.mdchanged
index.jschanged
.travis.ymladded
docs/index.mdadded
README.mdView
@@ -1,20 +1,32 @@
11 # SYNOPSIS
2-[![NPM Package](https://img.shields.io/npm/v/<modeule-name>.svg?style=flat-square)](https://www.npmjs.org/package/<module-name>)
3-[![Build Status](https://img.shields.io/travis/<gh-user>/<repo>.svg?branch=master&style=flat-square)](https://travis-ci.org/<gh-user>/<repo>)
4-[![Coverage Status](https://img.shields.io/coveralls/<gh-user>/<repo>.svg?style=flat-square)](https://coveralls.io/r/<gh-user>/<repo>)
2 +[![NPM Package](https://img.shields.io/npm/v/primea-objects.svg?style=flat-square)](https://www.npmjs.org/package/primea-objects)
3 +[![Build Status](https://img.shields.io/travis/primea/primea-objects.svg?branch=master&style=flat-square)](https://travis-ci.org/primea/primea-objects)
4 +[![Coverage Status](https://img.shields.io/coveralls/primea/primea-objects.svg?style=flat-square)](https://coveralls.io/r/primea/primea-objects)
55
66 [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
77
8-This isdi easdfkl; asdfj kal;sdjfkl ajsdklfj akls;j wat?
8 +Object helper classes for Primea's system Objects
99
1010 # INSTALL
11-`npm install <name>`
11 +`npm install primea-objects`
1212
1313 # USAGE
1414
1515 ```javascript
16- javascript = new Javascript()
16 +const objects = require('primea-objects')
17 +
18 +const id = new objects.ID(Buffer.from([0x1]))
19 +const modRef = new objects.ModuleRef({'name': ['i32']}, id)
20 +const funcRef = rmodRef.getFuncRef('name')
21 +
22 +// all objects can be encoded to cbor with borc
23 +const cbor = require('borc')
24 +const encodedModRef = cbor.encode(modRef)
25 +
26 +// and decoded with the decoder
27 +objects.decoder.decodeFirst(encodedModRef)
28 +
1729 ```
1830
1931 # API
2032 [./docs/](./docs/index.md)
index.jsView
@@ -16,8 +16,12 @@
1616 link: new cbor.Tagged(TAGS.link, null),
1717 func: new cbor.Tagged(TAGS.func, 0)
1818 }
1919
20 +/**
21 + * a cbor decoder for the objects
22 + * @type {Object}
23 + */
2024 const decoder = new cbor.Decoder({
2125 tags: {
2226 [TAGS.id]: val => new ID(val),
2327 [TAGS.func]: val => new FunctionRef({
@@ -34,32 +38,63 @@
3438 }
3539 }
3640 })
3741
42 +class ID {
43 + /**
44 + * an ID
45 + * @param {Buffer} id - the id as an buffer
46 + */
47 + constructor (id) {
48 + this.id = id
49 + }
50 +
51 + encodeCBOR (gen) {
52 + return gen.write(new cbor.Tagged(TAGS.id, this.id))
53 + }
54 +}
55 +
3856 class FunctionRef {
57 + /**
58 + * A function reference
59 + * @param {Object} opts
60 + * @param {*} opts.identifier - the function's identifier
61 + * @param {ID} opts.actorID - the id of the actor
62 + * @param {Array} opts.params - the params of the function
63 + */
3964 constructor (opts) {
4065 this.identifier = opts.identifier
41- this.destId = opts.id
66 + this.actorID = opts.actorID
4267 this.params = opts.params
4368 this.gas = opts.gas || 0
4469 }
4570
4671 encodeCBOR (gen) {
4772 return gen.write(new cbor.Tagged(TAGS.func, [
4873 this.identifier,
4974 this.params,
50- this.destId,
75 + this.actorID,
5176 this.gas
5277 ]))
5378 }
5479 }
5580
5681 class ModuleRef {
57- constructor (ex, id) {
58- this.exports = ex
82 + /**
83 + * A module reference
84 + * @param {Object} exports - a map of exported function to params for the funcion if any
85 + * @param {ID} id - the id of the actor
86 + */
87 + constructor (exports, id) {
88 + this.exports = exports
5989 this.id = id
6090 }
6191
92 + /**
93 + * return a function refernce given the name of the function
94 + * @param {string} name
95 + * @returns {FunctionRef}
96 + */
6297 getFuncRef (name) {
6398 const params = this.exports[name]
6499
65100 return new FunctionRef({
@@ -73,24 +108,11 @@
73108 return gen.write(new cbor.Tagged(TAGS.mod, [this.exports, this.id]))
74109 }
75110 }
76111
77-class ID {
78- constructor (id) {
79- this.id = id
80- }
81-
82- encodeCBOR (gen) {
83- return gen.write(new cbor.Tagged(TAGS.id, this.id))
84- }
85-}
86-
87-/**
88- * This implements Messages for Primea
89- * @module primea-message
90- */
91112 class Message extends EventEmitter {
92113 /**
114 + * This implements Messages for Primea
93115 * @param {Object} opts
94116 * @param {ArrayBuffer} opts.data - the payload of the message
95117 * @param {Array<Object>} opts.caps - an array of capabilities to send in the message
96118 */
.travis.ymlView
@@ -1,0 +1,24 @@
1 +language: node_js
2 +node_js:
3 + - "8"
4 +env:
5 + global:
6 + - CXX=g++-4.8
7 + matrix:
8 + - TEST_SUITE=test
9 +addons:
10 + apt:
11 + sources:
12 + - ubuntu-toolchain-r-test
13 + packages:
14 + - g++-4.8
15 +matrix:
16 + fast_finish: true
17 + include:
18 + - os: linux
19 + node_js: "8"
20 + env: TEST_SUITE=coveralls
21 + - os: linux
22 + node_js: "8"
23 + env: TEST_SUITE=lint
24 +script: npm run $TEST_SUITE
docs/index.mdView
@@ -1,0 +1,107 @@
1 +<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2 +
3 +### Table of Contents
4 +
5 +- [constructor][1]
6 +- [constructor][2]
7 +- [constructor][3]
8 +- [getFuncRef][4]
9 +- [constructor][5]
10 +
11 +##
12 +
13 +[index.js:11-18][6]
14 +
15 +a cbor decoder for the objects
16 +
17 +Type: [Object][7]
18 +
19 +## constructor
20 +
21 +[index.js:47-49][8]
22 +
23 +an ID
24 +
25 +**Parameters**
26 +
27 +- `id` **[Buffer][9]** the id as an buffer
28 +
29 +## constructor
30 +
31 +[index.js:64-69][10]
32 +
33 +A function reference
34 +
35 +**Parameters**
36 +
37 +- `opts` **[Object][7]**
38 + - `opts.identifier` **any** the function's identifier
39 + - `opts.actorID` **ID** the id of the actor
40 + - `opts.params` **[Array][11]** the params of the function
41 +
42 +## constructor
43 +
44 +[index.js:87-90][12]
45 +
46 +A module reference
47 +
48 +**Parameters**
49 +
50 +- `exports` **[Object][7]** a map of exported function to params for the funcion if any
51 +- `id` **ID** the id of the actor
52 +
53 +## getFuncRef
54 +
55 +[index.js:97-105][13]
56 +
57 +return a function refernce given the name of the function
58 +
59 +**Parameters**
60 +
61 +- `name` **[string][14]**
62 +
63 +Returns **FunctionRef**
64 +
65 +## constructor
66 +
67 +[index.js:119-133][15]
68 +
69 +This implements Messages for Primea
70 +
71 +**Parameters**
72 +
73 +- `opts` **[Object][7]**
74 + - `opts.data` **[ArrayBuffer][16]** the payload of the message
75 + - `opts.caps` **[Array][11]&lt;[Object][7]>** an array of capabilities to send in the message
76 +
77 +[1]: #constructor
78 +
79 +[2]: #constructor-1
80 +
81 +[3]: #constructor-2
82 +
83 +[4]: #getfuncref
84 +
85 +[5]: #constructor-3
86 +
87 +[6]: https://github.com/primea/js-primea-objects/blob/136ef4bd7ca697c515688fa0a7b42c49930b5710/index.js#L11-L18 "Source code on GitHub"
88 +
89 +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
90 +
91 +[8]: https://github.com/primea/js-primea-objects/blob/136ef4bd7ca697c515688fa0a7b42c49930b5710/index.js#L47-L49 "Source code on GitHub"
92 +
93 +[9]: https://nodejs.org/api/buffer.html
94 +
95 +[10]: https://github.com/primea/js-primea-objects/blob/136ef4bd7ca697c515688fa0a7b42c49930b5710/index.js#L64-L69 "Source code on GitHub"
96 +
97 +[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
98 +
99 +[12]: https://github.com/primea/js-primea-objects/blob/136ef4bd7ca697c515688fa0a7b42c49930b5710/index.js#L87-L90 "Source code on GitHub"
100 +
101 +[13]: https://github.com/primea/js-primea-objects/blob/136ef4bd7ca697c515688fa0a7b42c49930b5710/index.js#L97-L105 "Source code on GitHub"
102 +
103 +[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
104 +
105 +[15]: https://github.com/primea/js-primea-objects/blob/136ef4bd7ca697c515688fa0a7b42c49930b5710/index.js#L119-L133 "Source code on GitHub"
106 +
107 +[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer

Built with git-ssb-web