protons 2.0.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +3 -20
  2. package/README.md +30 -122
  3. package/dist/bin/protons.js +34 -0
  4. package/dist/src/index.d.ts +2 -0
  5. package/dist/src/index.d.ts.map +1 -0
  6. package/dist/src/index.js +206 -0
  7. package/dist/src/index.js.map +1 -0
  8. package/package.json +148 -70
  9. package/src/index.ts +282 -0
  10. package/.aegir.js +0 -11
  11. package/.github/ISSUE_TEMPLATE/config.yml +0 -8
  12. package/.github/ISSUE_TEMPLATE/open_an_issue.md +0 -19
  13. package/.github/config.yml +0 -68
  14. package/.travis.yml +0 -42
  15. package/CHANGELOG.md +0 -88
  16. package/bench/bench.proto.js +0 -30
  17. package/bench/index.js +0 -57
  18. package/example.js +0 -19
  19. package/example.proto +0 -4
  20. package/src/compile/decode.js +0 -330
  21. package/src/compile/encode.js +0 -133
  22. package/src/compile/encoding-length.js +0 -102
  23. package/src/compile/encodings/bool.js +0 -21
  24. package/src/compile/encodings/bytes.js +0 -42
  25. package/src/compile/encodings/double.js +0 -21
  26. package/src/compile/encodings/encoder.js +0 -14
  27. package/src/compile/encodings/fixed32.js +0 -21
  28. package/src/compile/encodings/fixed64.js +0 -25
  29. package/src/compile/encodings/float.js +0 -21
  30. package/src/compile/encodings/index.js +0 -22
  31. package/src/compile/encodings/int32.js +0 -22
  32. package/src/compile/encodings/int64.js +0 -49
  33. package/src/compile/encodings/sfixed32.js +0 -21
  34. package/src/compile/encodings/sint64.js +0 -19
  35. package/src/compile/encodings/string.js +0 -41
  36. package/src/compile/encodings/varint.js +0 -19
  37. package/src/compile/index.js +0 -165
  38. package/src/compile/utils.js +0 -5
  39. package/src/index.js +0 -39
  40. package/test/basic.spec.js +0 -109
  41. package/test/booleans.spec.js +0 -37
  42. package/test/bytes.spec.js +0 -36
  43. package/test/corrupted.spec.js +0 -50
  44. package/test/custom-types.spec.js +0 -55
  45. package/test/defaults.spec.js +0 -44
  46. package/test/enums.spec.js +0 -21
  47. package/test/float.spec.js +0 -28
  48. package/test/integers.spec.js +0 -72
  49. package/test/map.spec.js +0 -35
  50. package/test/nan.spec.js +0 -28
  51. package/test/nested.spec.js +0 -70
  52. package/test/notpacked.spec.js +0 -33
  53. package/test/oneof.spec.js +0 -59
  54. package/test/optional.spec.js +0 -65
  55. package/test/packed.spec.js +0 -61
  56. package/test/repeated.spec.js +0 -74
  57. package/test/strings.spec.js +0 -45
  58. package/test/test.proto.js +0 -134
  59. package/test/utf-8.spec.js +0 -21
@@ -1,65 +0,0 @@
1
- /* eslint-env mocha */
2
-
3
- 'use strict'
4
-
5
- const { expect } = require('aegir/utils/chai')
6
- const protobuf = require('../src')
7
- const proto = require('./test.proto')
8
- const Optional = protobuf(proto).Optional
9
-
10
- describe('optional', () => {
11
- it('should encode and decode zero value for optional value', () => {
12
- const o1 = {}
13
- const b1 = Optional.encode(o1)
14
- const o2 = Optional.decode(b1)
15
-
16
- expect(o1).to.not.have.property('value')
17
- expect(o2).to.have.property('value', 0)
18
- })
19
-
20
- it('should create accessors for optional values', () => {
21
- const o1 = Optional.decode(Optional.encode({}))
22
-
23
- expect(o1).to.have.property('hasValue').that.is.a('function')
24
- expect(o1.hasValue()).to.be.false()
25
-
26
- expect(o1).to.have.property('setValue').that.is.a('function')
27
- o1.setValue(5)
28
- expect(o1.hasValue()).to.be.true()
29
-
30
- expect(o1).to.have.property('getValue').that.is.a('function')
31
- expect(o1.getValue()).to.equal(5)
32
-
33
- expect(o1).to.have.property('clearValue').that.is.a('function')
34
- o1.clearValue()
35
-
36
- expect(o1.hasValue()).to.be.false()
37
- expect(o1.getValue()).to.be.undefined()
38
- })
39
-
40
- it('should have non-enumerable accessors for optional values', () => {
41
- const o1 = Optional.decode(Optional.encode({}))
42
- const methods = Object.keys(o1)
43
-
44
- expect(methods).to.not.include('getValue')
45
- expect(methods).to.not.include('setValue')
46
- expect(methods).to.not.include('hasValue')
47
- expect(methods).to.not.include('clearValue')
48
- })
49
-
50
- it('should return zero values from optional accessors when no value has been set', () => {
51
- const o1 = Optional.decode(Optional.encode({}))
52
-
53
- expect(o1.hasValue()).to.be.false()
54
- o1.setValue(0)
55
- expect(o1.hasValue()).to.be.true()
56
-
57
- expect(o1.getValue).to.be.a('function')
58
- expect(o1.getValue()).to.equal(0)
59
-
60
- const o2 = Optional.decode(Optional.encode(o1))
61
-
62
- expect(o2.hasValue()).to.be.ok()
63
- expect(o2.getValue()).to.equal(0)
64
- })
65
- })
@@ -1,61 +0,0 @@
1
- /* eslint-env mocha */
2
-
3
- 'use strict'
4
-
5
- const { expect } = require('aegir/utils/chai')
6
- const protobuf = require('../src')
7
- const Packed = protobuf(require('./test.proto')).Packed
8
-
9
- describe('packed', () => {
10
- it('should encode packed fields', () => {
11
- const b1 = Packed.encode({
12
- packed: [
13
- 12,
14
- 13,
15
- 14
16
- ]
17
- })
18
-
19
- const b2 = Packed.encode({
20
- packed: [
21
- 12,
22
- 13,
23
- 14
24
- ],
25
- meeh: 42
26
- })
27
-
28
- expect(b2).to.deep.equal(b1)
29
- })
30
-
31
- it('should decode packed fields', () => {
32
- const b1 = Packed.encode({
33
- packed: [
34
- 12,
35
- 13,
36
- 14
37
- ]
38
- })
39
-
40
- const o1 = Packed.decode(b1)
41
-
42
- expect(o1).to.have.deep.property('packed', [
43
- 12,
44
- 13,
45
- 14
46
- ])
47
-
48
- const b2 = Packed.encode({
49
- packed: [
50
- 12,
51
- 13,
52
- 14
53
- ],
54
- meeh: 42
55
- })
56
-
57
- const o2 = Packed.decode(b2)
58
-
59
- expect(o2).to.deep.equal(o1)
60
- })
61
- })
@@ -1,74 +0,0 @@
1
- /* eslint-env mocha */
2
-
3
- 'use strict'
4
-
5
- const { expect } = require('aegir/utils/chai')
6
- const protobuf = require('../src')
7
- const Repeated = protobuf(require('./test.proto')).Repeated
8
- const uint8ArrayFromString = require('uint8arrays/from-string')
9
-
10
- describe('repeated', () => {
11
- it('should encode repeated fields', () => {
12
- const b1 = Repeated.encode({
13
- list: [{
14
- num: 1,
15
- payload: uint8ArrayFromString('lol')
16
- }, {
17
- num: 2,
18
- payload: uint8ArrayFromString('lol1')
19
- }]
20
- })
21
-
22
- const b2 = Repeated.encode({
23
- list: [{
24
- num: 1,
25
- payload: uint8ArrayFromString('lol')
26
- }, {
27
- num: 2,
28
- payload: uint8ArrayFromString('lol1'),
29
- meeeeh: 100
30
- }],
31
- meeh: 42
32
- })
33
-
34
- expect(b2).to.deep.equal(b1)
35
- })
36
-
37
- it('should decode repeated fields', () => {
38
- const b1 = Repeated.encode({
39
- list: [{
40
- num: 1,
41
- payload: uint8ArrayFromString('lol')
42
- }, {
43
- num: 2,
44
- payload: uint8ArrayFromString('lol1')
45
- }]
46
- })
47
-
48
- const o1 = Repeated.decode(b1)
49
-
50
- expect(o1).to.have.deep.nested.property('list', [{
51
- num: 1,
52
- payload: uint8ArrayFromString('lol')
53
- }, {
54
- num: 2,
55
- payload: uint8ArrayFromString('lol1')
56
- }])
57
-
58
- const b2 = Repeated.encode({
59
- list: [{
60
- num: 1,
61
- payload: uint8ArrayFromString('lol')
62
- }, {
63
- num: 2,
64
- payload: uint8ArrayFromString('lol1'),
65
- meeeeh: 100
66
- }],
67
- meeh: 42
68
- })
69
-
70
- const o2 = Repeated.decode(b2)
71
-
72
- expect(o2).to.deep.equal(o1)
73
- })
74
- })
@@ -1,45 +0,0 @@
1
- /* eslint-env mocha */
2
-
3
- 'use strict'
4
-
5
- const { expect } = require('aegir/utils/chai')
6
- const protobuf = require('../src')
7
- const Strings = protobuf(require('./test.proto')).Strings
8
-
9
- describe('strings', () => {
10
- it('should encode and decode strings', () => {
11
- const b1 = Strings.encode({
12
- name: 'hello',
13
- desc: 'world'
14
- })
15
-
16
- const o1 = Strings.decode(b1)
17
-
18
- expect(o1).to.deep.equal({
19
- name: 'hello',
20
- desc: 'world'
21
- })
22
- })
23
-
24
- it('should encode and decode optional strings', () => {
25
- const b1 = Strings.encode({
26
- name: 'hello'
27
- })
28
-
29
- const o1 = Strings.decode(b1)
30
-
31
- expect(o1).to.have.property('name', 'hello')
32
- expect(o1.hasDesc()).to.be.false()
33
- })
34
-
35
- it('should encode and decode empty strings', () => {
36
- const b1 = Strings.encode({
37
- name: ''
38
- })
39
-
40
- const o1 = Strings.decode(b1)
41
-
42
- expect(o1).to.have.property('name', '')
43
- expect(o1.hasDesc()).to.be.false()
44
- })
45
- })
@@ -1,134 +0,0 @@
1
- 'use strict'
2
- module.exports = `message Basic {
3
- required double num = 1;
4
- required bytes payload = 2;
5
- }
6
-
7
- message Map {
8
- map<string, string> foo = 1;
9
- }
10
-
11
- message UTF8 {
12
- required string foo = 1;
13
- required uint32 bar = 2;
14
- }
15
-
16
- message Nested {
17
- required double num = 1;
18
- required bytes payload = 2;
19
- required Basic meh = 3;
20
- }
21
-
22
- message Repeated {
23
- repeated Basic list = 1;
24
- }
25
-
26
- message Optional {
27
- optional int32 value = 1;
28
- }
29
-
30
- message Integers {
31
- optional sint32 sint32 = 1;
32
- optional sint64 sint64 = 2;
33
- optional int32 int32 = 3;
34
- optional uint32 uint32 = 4;
35
- optional int64 int64 = 5;
36
- optional fixed32 fixed32 = 6;
37
- }
38
-
39
- message Float {
40
- optional float float1 = 1;
41
- optional float float2 = 2;
42
- optional float float3 = 3;
43
- }
44
-
45
- message Strings {
46
- required string name = 1;
47
- optional string desc = 2;
48
- }
49
-
50
- message Booleans {
51
- required bool bool1 = 1;
52
- optional bool bool2 = 2;
53
- }
54
-
55
- message Bytes {
56
- required bytes req = 1;
57
- optional bytes opt = 2;
58
- }
59
-
60
- message CustomType {
61
- required Basic req = 1;
62
- optional Basic opt = 2;
63
- }
64
-
65
- message Packed {
66
- repeated Basic list = 1;
67
- repeated int32 packed = 2 [packed=true];
68
- }
69
-
70
- message NotPacked {
71
- repeated int64 id = 2;
72
- optional int64 value = 5;
73
- }
74
- message FalsePacked {
75
- repeated int64 id = 2 [packed=false];
76
- optional int64 value = 5;
77
- }
78
-
79
- enum FOO {
80
- A = 1;
81
- B = 2;
82
- }
83
-
84
- message Defaults {
85
- optional int32 num = 1 [default = 42];
86
- optional FOO foo1 = 2 [default = B];
87
- optional FOO foo2 = 3;
88
- repeated FOO foos = 4;
89
- }
90
-
91
- enum FOO_HEX {
92
- A = 0x01;
93
- B = 0x02;
94
- }
95
-
96
- message Property {
97
- required string name = 1;
98
- optional string desc = 2;
99
-
100
- oneof value {
101
- bool bool_value = 3;
102
- float float_value = 4;
103
- int32 int_value = 5;
104
- string string_value = 6;
105
- }
106
- }
107
-
108
- message PropertyNoOneof {
109
- required string name = 1;
110
- optional string desc = 2;
111
-
112
- optional bool bool_value = 3;
113
- optional float float_value = 4;
114
- optional int32 int_value = 5;
115
- optional string string_value = 6;
116
- }
117
-
118
- message ComplexProperty {
119
- required string name = 1;
120
-
121
- oneof value {
122
- bool bool_value = 3;
123
- float float_value = 4;
124
- int32 int_value = 5;
125
- string string_value = 6;
126
- }
127
-
128
- oneof another_value {
129
- bool bool_value = 7;
130
- float float_value = 8;
131
- int32 int_value = 9;
132
- string string_value = 10;
133
- }
134
- }`
@@ -1,21 +0,0 @@
1
- /* eslint-env mocha */
2
-
3
- 'use strict'
4
-
5
- const { expect } = require('aegir/utils/chai')
6
- const protobuf = require('../src')
7
- const UTF8 = protobuf(require('./test.proto')).UTF8
8
-
9
- describe('utf-8', () => {
10
- it('should encode multi-byte strings', () => {
11
- const ex = {
12
- foo: 'ビッグデータ「人間の解釈が必要」「量の問題ではない」論と、もう一つのビッグデータ「人間の解釈が必要」「量の問題ではない」論と、もう一つの',
13
- bar: 42
14
- }
15
-
16
- const b1 = UTF8.encode(ex)
17
- const b2 = UTF8.decode(b1)
18
-
19
- expect(b2).to.deep.equal(ex)
20
- })
21
- })