git ssb

0+

wanderer🌟 / js-primea-objects



Commit 19ce496560f9ea1fb3b35eefab4afbe9b8d581eb

rebuild docs

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 4/2/2018, 10:25:24 PM
Parent: 3de2cd903c7ffab608c66c08ebae41dc3d742d2f

Files changed

docs/index.mdchanged
index.jschanged
tests/index.jschanged
docs/index.mdView
@@ -3,23 +3,25 @@
33 ### Table of Contents
44
55 - [ID][1]
66 - [FunctionRef][2]
7-- [ModuleRef][3]
8- - [getFuncRef][4]
9-- [Message][5]
7 + - [copy][3]
8 +- [ModuleRef][4]
9 + - [getFuncRef][5]
10 +- [Message][6]
11 +- [getType][7]
1012
1113 ##
1214
13-[index.js:11-18][6]
15 +[index.js:5-10][8]
1416
1517 a cbor decoder for the objects
1618
17-Type: [Object][7]
19 +Type: [Object][9]
1820
1921 ## ID
2022
21-[index.js:45-60][8]
23 +[index.js:37-52][10]
2224
2325 an ID
2426
2527 **Parameters**
@@ -27,76 +29,102 @@
2729 - `id`
2830
2931 ## FunctionRef
3032
31-[index.js:65-87][9]
33 +[index.js:57-92][11]
3234
3335 A function reference
3436
3537 **Parameters**
3638
37-- `opts` **[Object][7]**
39 +- `opts` **[Object][9]**
3840
41 +### copy
42 +
43 +[index.js:84-91][12]
44 +
45 +Creates a copy of the funcRef
46 +
3947 ## ModuleRef
4048
41-[index.js:92-120][10]
49 +[index.js:97-125][13]
4250
4351 A module reference
4452
4553 **Parameters**
4654
47-- `exports` **[Object][7]** a map of exported function to params for the funcion if any
48-- `id` **[ID][11]** the id of the actor
55 +- `exports` **[Object][9]** a map of exported function to params for the funcion if any
56 +- `id` **[ID][14]** the id of the actor
4957
5058 ### getFuncRef
5159
52-[index.js:107-115][12]
60 +[index.js:112-120][15]
5361
5462 return a function refernce given the name of the function
5563
5664 **Parameters**
5765
58-- `name` **[string][13]**
66 +- `name` **[string][16]**
5967
60-Returns **[FunctionRef][14]**
68 +Returns **[FunctionRef][17]**
6169
6270 ## Message
6371
64-[index.js:125-157][15]
72 +[index.js:130-162][18]
6573
6674 **Extends EventEmitter**
6775
6876 This implements Messages for Primea
6977
7078 **Parameters**
7179
72-- `opts` **[Object][7]**
80 +- `opts` **[Object][9]**
7381
82 +## getType
83 +
84 +[index.js:169-188][19]
85 +
86 +returns the type that the object is
87 +
88 +**Parameters**
89 +
90 +- `obj` **any**
91 +
92 +Returns **[String][16]**
93 +
7494 [1]: #id
7595
7696 [2]: #functionref
7797
78-[3]: #moduleref
98 +[3]: #copy
7999
80-[4]: #getfuncref
100 +[4]: #moduleref
81101
82-[5]: #message
102 +[5]: #getfuncref
83103
84-[6]: https://github.com/primea/js-primea-objects/blob/3232a5e82edf2a3efc1f35a9be2159d416bca00d/index.js#L11-L18 "Source code on GitHub"
104 +[6]: #message
85105
86-[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
106 +[7]: #gettype
87107
88-[8]: https://github.com/primea/js-primea-objects/blob/3232a5e82edf2a3efc1f35a9be2159d416bca00d/index.js#L45-L60 "Source code on GitHub"
108 +[8]: https://github.com/primea/js-primea-objects/blob/3de2cd903c7ffab608c66c08ebae41dc3d742d2f/index.js#L5-L10 "Source code on GitHub"
89109
90-[9]: https://github.com/primea/js-primea-objects/blob/3232a5e82edf2a3efc1f35a9be2159d416bca00d/index.js#L65-L87 "Source code on GitHub"
110 +[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
91111
92-[10]: https://github.com/primea/js-primea-objects/blob/3232a5e82edf2a3efc1f35a9be2159d416bca00d/index.js#L92-L120 "Source code on GitHub"
112 +[10]: https://github.com/primea/js-primea-objects/blob/3de2cd903c7ffab608c66c08ebae41dc3d742d2f/index.js#L37-L52 "Source code on GitHub"
93113
94-[11]: #id
114 +[11]: https://github.com/primea/js-primea-objects/blob/3de2cd903c7ffab608c66c08ebae41dc3d742d2f/index.js#L57-L92 "Source code on GitHub"
95115
96-[12]: https://github.com/primea/js-primea-objects/blob/3232a5e82edf2a3efc1f35a9be2159d416bca00d/index.js#L107-L115 "Source code on GitHub"
116 +[12]: https://github.com/primea/js-primea-objects/blob/3de2cd903c7ffab608c66c08ebae41dc3d742d2f/index.js#L84-L91 "Source code on GitHub"
97117
98-[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
118 +[13]: https://github.com/primea/js-primea-objects/blob/3de2cd903c7ffab608c66c08ebae41dc3d742d2f/index.js#L97-L125 "Source code on GitHub"
99119
100-[14]: #functionref
120 +[14]: #id
101121
102-[15]: https://github.com/primea/js-primea-objects/blob/3232a5e82edf2a3efc1f35a9be2159d416bca00d/index.js#L125-L157 "Source code on GitHub"
122 +[15]: https://github.com/primea/js-primea-objects/blob/3de2cd903c7ffab608c66c08ebae41dc3d742d2f/index.js#L112-L120 "Source code on GitHub"
123 +
124 +[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
125 +
126 +[17]: #functionref
127 +
128 +[18]: https://github.com/primea/js-primea-objects/blob/3de2cd903c7ffab608c66c08ebae41dc3d742d2f/index.js#L130-L162 "Source code on GitHub"
129 +
130 +[19]: https://github.com/primea/js-primea-objects/blob/3de2cd903c7ffab608c66c08ebae41dc3d742d2f/index.js#L169-L188 "Source code on GitHub"
index.jsView
@@ -1,23 +1,15 @@
11 const cbor = require('borc')
22 const EventEmitter = require('events')
3 +const Buffer = require('safe-buffer').Buffer
34
45 const TAGS = {
56 id: 41,
67 link: 42,
78 func: 43,
89 mod: 44
910 }
1011
11-const DEFAULTS = {
12- elem: [],
13- data: Buffer.from([]),
14- id: new cbor.Tagged(TAGS.id, 0),
15- mod: new cbor.Tagged(TAGS.mod, [{}, new cbor.Tagged(TAGS.id, 0)]),
16- link: new cbor.Tagged(TAGS.link, null),
17- func: new cbor.Tagged(TAGS.func, 0)
18-}
19-
2012 /**
2113 * a cbor decoder for the objects
2214 * @type {Object}
2315 */
@@ -84,8 +76,12 @@
8476 this.gas
8577 ]))
8678 }
8779
80 + /**
81 + * Creates a copy of the funcRef
82 + * @retrun {FunctionRef}
83 + */
8884 copy () {
8985 return new FunctionRef({
9086 identifier: this.identifier,
9187 actorID: this.actorID,
@@ -164,12 +160,38 @@
164160 }
165161 }
166162 }
167163
164 +/**
165 + * returns the type that the object is
166 + * @param {*} obj
167 + * @return {String}
168 + */
169 +function getType (obj) {
170 + if (obj) {
171 + if (Buffer.isBuffer(obj)) {
172 + return 'data'
173 + } else if (Array.isArray(obj)) {
174 + return 'elem'
175 + } else if (obj['/']) {
176 + return 'link'
177 + } else if (obj.constructor === Message) {
178 + return 'message'
179 + } else if (obj.constructor === ID) {
180 + return 'id'
181 + } else if (obj.constructor === FunctionRef) {
182 + return 'func'
183 + } else if (obj.constructor === ModuleRef) {
184 + return 'mod'
185 + }
186 + }
187 + return 'invalid'
188 +}
189 +
168190 module.exports = {
169191 Message,
170192 ID,
171193 FunctionRef,
172194 ModuleRef,
173- DEFAULTS,
174- decoder
195 + decoder,
196 + getType
175197 }
tests/index.jsView
@@ -1,25 +1,32 @@
1 +const Buffer = require('safe-buffer').Buffer
12 const tape = require('tape')
23 const cbor = require('borc')
34 const objects = require('../')
45
56 tape('system objects', t => {
7 +
8 + t.equals(objects.getType(), 'invalid')
9 + t.equals(objects.getType(true), 'invalid')
610 const msg = new objects.Message({
711 ticks: 100
812 })
913
14 + t.equals(objects.getType(msg), 'message')
1015 t.equals(msg.ticks, 100)
1116 msg.ticks = 10
1217 t.equals(msg.ticks, 10)
1318
1419 const id = new objects.ID(Buffer.from([0x1]))
1520 const enid = cbor.encode(id)
1621 const rid = objects.decoder.decodeFirst(enid)
1722 t.equals(rid.toString(), '01')
23 + t.equals(objects.getType(id), 'id')
1824
1925 const modRef = new objects.ModuleRef({'name': ['i32']}, id)
2026 const enmod = cbor.encode(modRef)
2127 const rmodRef = objects.decoder.decodeFirst(enmod)
28 + t.equals(objects.getType(modRef), 'mod')
2229 t.deepEquals(modRef, rmodRef)
2330
2431 const funcRef = rmodRef.getFuncRef('name')
2532 funcRef.gas = 1000
@@ -28,12 +35,17 @@
2835 t.equals(funcRef.gas, 1000, 'should have correct gas amount')
2936 const enFuncRef = cbor.encode(funcRef)
3037 const rFuncRef = objects.decoder.decodeFirst(enFuncRef)
3138 t.deepEquals(funcRef, rFuncRef)
39 + t.equals(objects.getType(rFuncRef), 'func')
3240
3341 const link = new cbor.Tagged(42, 'data')
3442 const enLink = cbor.encode(link)
3543 const rLink = objects.decoder.decodeFirst(enLink)
3644 t.deepEquals(rLink, {'/': 'data'})
45 + t.equals(objects.getType(rLink), 'link')
3746
47 + t.equals(objects.getType([]), 'elem')
48 + t.equals(objects.getType(Buffer.from([])), 'data')
49 +
3850 t.end()
3951 })

Built with git-ssb-web