stage-browser 0.1.0 → 0.2.0
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.
- package/README.md +92 -45
- package/build/icon.icns +0 -0
- package/build/icon.png +0 -0
- package/dist/bin/stage.js +111 -0
- package/dist/main/cli-args.js +28 -0
- package/dist/main/context-menu.js +68 -0
- package/dist/main/context.js +2 -0
- package/dist/main/extensions.js +78 -0
- package/dist/main/ipc.js +73 -0
- package/dist/main/main.js +282 -0
- package/dist/main/menu.js +140 -0
- package/dist/main/reveal.js +170 -0
- package/dist/main/selftest.js +570 -0
- package/dist/main/store.js +85 -0
- package/dist/main/suggest.js +43 -0
- package/dist/main/tabs.js +324 -0
- package/dist/main/ui-window.js +133 -0
- package/dist/main/url.js +38 -0
- package/dist/main/window.js +133 -0
- package/dist/preload/extension-compat.js +163 -0
- package/dist/preload/ui-preload.js +34 -0
- package/dist/shared/contract.js +6 -0
- package/dist/ui/app.js +692 -0
- package/{src → dist}/ui/index.html +15 -5
- package/dist/ui/mock.js +500 -0
- package/{src → dist}/ui/styles.css +55 -14
- package/node_modules/@types/chrome/LICENSE +21 -0
- package/node_modules/@types/chrome/README.md +15 -0
- package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
- package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
- package/node_modules/@types/chrome/index.d.ts +13786 -0
- package/node_modules/@types/chrome/package.json +99 -0
- package/node_modules/@types/filesystem/LICENSE +21 -0
- package/node_modules/@types/filesystem/README.md +15 -0
- package/node_modules/@types/filesystem/index.d.ts +564 -0
- package/node_modules/@types/filesystem/package.json +26 -0
- package/node_modules/@types/filewriter/LICENSE +21 -0
- package/node_modules/@types/filewriter/README.md +15 -0
- package/node_modules/@types/filewriter/index.d.ts +166 -0
- package/node_modules/@types/filewriter/package.json +25 -0
- package/node_modules/@types/har-format/LICENSE +21 -0
- package/node_modules/@types/har-format/README.md +15 -0
- package/node_modules/@types/har-format/index.d.ts +938 -0
- package/node_modules/@types/har-format/package.json +31 -0
- package/node_modules/adm-zip/LICENSE +21 -0
- package/node_modules/adm-zip/README.md +90 -0
- package/node_modules/adm-zip/adm-zip.js +1020 -0
- package/node_modules/adm-zip/headers/entryHeader.js +396 -0
- package/node_modules/adm-zip/headers/index.js +2 -0
- package/node_modules/adm-zip/headers/mainHeader.js +177 -0
- package/node_modules/adm-zip/methods/deflater.js +33 -0
- package/node_modules/adm-zip/methods/index.js +3 -0
- package/node_modules/adm-zip/methods/inflater.js +64 -0
- package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
- package/node_modules/adm-zip/package.json +56 -0
- package/node_modules/adm-zip/types.d.ts +223 -0
- package/node_modules/adm-zip/util/constants.js +142 -0
- package/node_modules/adm-zip/util/decoder.js +5 -0
- package/node_modules/adm-zip/util/errors.js +66 -0
- package/node_modules/adm-zip/util/fattr.js +76 -0
- package/node_modules/adm-zip/util/index.js +5 -0
- package/node_modules/adm-zip/util/utils.js +481 -0
- package/node_modules/adm-zip/zipEntry.js +415 -0
- package/node_modules/adm-zip/zipFile.js +466 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/electron-chrome-web-store/README.md +143 -0
- package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
- package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
- package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
- package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
- package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
- package/node_modules/electron-chrome-web-store/package.json +43 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/pbf/LICENSE +27 -0
- package/node_modules/pbf/README.md +293 -0
- package/node_modules/pbf/bin/pbf +17 -0
- package/node_modules/pbf/compile.js +441 -0
- package/node_modules/pbf/dist/pbf-dev.js +838 -0
- package/node_modules/pbf/dist/pbf.js +1 -0
- package/node_modules/pbf/index.d.ts +206 -0
- package/node_modules/pbf/index.js +830 -0
- package/node_modules/pbf/package.json +63 -0
- package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
- package/node_modules/protocol-buffers-schema/LICENSE +21 -0
- package/node_modules/protocol-buffers-schema/README.md +122 -0
- package/node_modules/protocol-buffers-schema/example.js +11 -0
- package/node_modules/protocol-buffers-schema/example.proto +13 -0
- package/node_modules/protocol-buffers-schema/index.js +6 -0
- package/node_modules/protocol-buffers-schema/package.json +31 -0
- package/node_modules/protocol-buffers-schema/parse.js +769 -0
- package/node_modules/protocol-buffers-schema/stringify.js +206 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
- package/node_modules/protocol-buffers-schema/test/index.js +157 -0
- package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
- package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
- package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
- package/node_modules/resolve-protobuf-schema/README.md +49 -0
- package/node_modules/resolve-protobuf-schema/index.js +50 -0
- package/node_modules/resolve-protobuf-schema/package.json +25 -0
- package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
- package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
- package/package.json +35 -11
- package/bin/stage.js +0 -52
- package/src/main/cli-args.js +0 -28
- package/src/main/context-menu.js +0 -64
- package/src/main/extensions.js +0 -61
- package/src/main/main.js +0 -310
- package/src/main/menu.js +0 -171
- package/src/main/reveal.js +0 -141
- package/src/main/selftest.js +0 -383
- package/src/main/store.js +0 -77
- package/src/main/suggest.js +0 -50
- package/src/main/tabs.js +0 -351
- package/src/main/url.js +0 -37
- package/src/main/window.js +0 -71
- package/src/preload/extension-compat.js +0 -34
- package/src/preload/ui-preload.js +0 -40
- package/src/ui/app.js +0 -588
- package/src/ui/mock.js +0 -455
- /package/{src → dist}/ui/newtab.html +0 -0
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
var tokenize = require('./tokenize')
|
|
2
|
+
var MAX_RANGE = 0x1FFFFFFF
|
|
3
|
+
|
|
4
|
+
// "Only repeated fields of primitive numeric types (types which use the varint, 32-bit, or 64-bit wire types) can be declared "packed"."
|
|
5
|
+
// https://developers.google.com/protocol-buffers/docs/encoding#optional
|
|
6
|
+
var PACKABLE_TYPES = [
|
|
7
|
+
// varint wire types
|
|
8
|
+
'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64', 'bool',
|
|
9
|
+
// + ENUMS
|
|
10
|
+
// 64-bit wire types
|
|
11
|
+
'fixed64', 'sfixed64', 'double',
|
|
12
|
+
// 32-bit wire types
|
|
13
|
+
'fixed32', 'sfixed32', 'float'
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
var onfieldoptionvalue = function (tokens) {
|
|
17
|
+
var value = tokens.shift()
|
|
18
|
+
if (value !== '{') {
|
|
19
|
+
return value
|
|
20
|
+
}
|
|
21
|
+
value = Object.create(null)
|
|
22
|
+
var field = ''
|
|
23
|
+
while (tokens.length) {
|
|
24
|
+
switch (tokens[0]) {
|
|
25
|
+
case '}':
|
|
26
|
+
tokens.shift()
|
|
27
|
+
return value
|
|
28
|
+
case ':':
|
|
29
|
+
tokens.shift()
|
|
30
|
+
value[field] = onfieldoptionvalue(tokens)
|
|
31
|
+
break
|
|
32
|
+
default:
|
|
33
|
+
field = tokens.shift()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var onfieldoptions = function (tokens) {
|
|
39
|
+
var opts = Object.create(null)
|
|
40
|
+
|
|
41
|
+
while (tokens.length) {
|
|
42
|
+
switch (tokens[0]) {
|
|
43
|
+
case '[':
|
|
44
|
+
case ',': {
|
|
45
|
+
tokens.shift()
|
|
46
|
+
var name = tokens.shift()
|
|
47
|
+
if (name === '(') { // handling [(A) = B]
|
|
48
|
+
name = tokens.shift()
|
|
49
|
+
tokens.shift() // remove the end of bracket
|
|
50
|
+
}
|
|
51
|
+
var field = []
|
|
52
|
+
if (tokens[0][0] === '.') {
|
|
53
|
+
field = tokens[0].substr(1).split('.')
|
|
54
|
+
tokens.shift()
|
|
55
|
+
}
|
|
56
|
+
if (tokens[0] !== '=') throw new Error('Unexpected token in field options: ' + tokens[0])
|
|
57
|
+
tokens.shift()
|
|
58
|
+
if (tokens[0] === ']') throw new Error('Unexpected ] in field option')
|
|
59
|
+
|
|
60
|
+
// for option (A).b.c
|
|
61
|
+
// path will be ['A', 'b'] and lastFieldName 'c'
|
|
62
|
+
var path = [name].concat(field)
|
|
63
|
+
var lastFieldName = path.pop()
|
|
64
|
+
|
|
65
|
+
// opt references opts.A.b
|
|
66
|
+
var opt = path.reduce(function (opt, n, index) {
|
|
67
|
+
if (opt[n] == null) {
|
|
68
|
+
opt[n] = Object.create(null)
|
|
69
|
+
}
|
|
70
|
+
return opt[n]
|
|
71
|
+
}, opts)
|
|
72
|
+
|
|
73
|
+
// now set opt['c'] that references opts.A.b['c']
|
|
74
|
+
opt[lastFieldName] = onfieldoptionvalue(tokens)
|
|
75
|
+
break
|
|
76
|
+
}
|
|
77
|
+
case ']':
|
|
78
|
+
tokens.shift()
|
|
79
|
+
return opts
|
|
80
|
+
|
|
81
|
+
default:
|
|
82
|
+
throw new Error('Unexpected token in field options: ' + tokens[0])
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
throw new Error('No closing tag for field options')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var onfield = function (tokens) {
|
|
90
|
+
var field = {
|
|
91
|
+
name: null,
|
|
92
|
+
type: null,
|
|
93
|
+
tag: -1,
|
|
94
|
+
map: null,
|
|
95
|
+
oneof: null,
|
|
96
|
+
required: false,
|
|
97
|
+
repeated: false,
|
|
98
|
+
options: Object.create(null)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
while (tokens.length) {
|
|
102
|
+
switch (tokens[0]) {
|
|
103
|
+
case '=':
|
|
104
|
+
tokens.shift()
|
|
105
|
+
field.tag = Number(tokens.shift())
|
|
106
|
+
break
|
|
107
|
+
|
|
108
|
+
case 'map':
|
|
109
|
+
field.type = 'map'
|
|
110
|
+
field.map = { from: null, to: null }
|
|
111
|
+
tokens.shift()
|
|
112
|
+
if (tokens[0] !== '<') throw new Error('Unexpected token in map type: ' + tokens[0])
|
|
113
|
+
tokens.shift()
|
|
114
|
+
field.map.from = tokens.shift()
|
|
115
|
+
if (tokens[0] !== ',') throw new Error('Unexpected token in map type: ' + tokens[0])
|
|
116
|
+
tokens.shift()
|
|
117
|
+
field.map.to = tokens.shift()
|
|
118
|
+
if (tokens[0] !== '>') throw new Error('Unexpected token in map type: ' + tokens[0])
|
|
119
|
+
tokens.shift()
|
|
120
|
+
field.name = tokens.shift()
|
|
121
|
+
break
|
|
122
|
+
|
|
123
|
+
case 'repeated':
|
|
124
|
+
case 'required':
|
|
125
|
+
case 'optional':
|
|
126
|
+
var t = tokens.shift()
|
|
127
|
+
field.required = t === 'required'
|
|
128
|
+
field.repeated = t === 'repeated'
|
|
129
|
+
field.type = tokens.shift()
|
|
130
|
+
field.name = tokens.shift()
|
|
131
|
+
break
|
|
132
|
+
|
|
133
|
+
case '[':
|
|
134
|
+
field.options = onfieldoptions(tokens)
|
|
135
|
+
break
|
|
136
|
+
|
|
137
|
+
case ';':
|
|
138
|
+
if (field.name === null) throw new Error('Missing field name')
|
|
139
|
+
if (field.type === null) throw new Error('Missing type in message field: ' + field.name)
|
|
140
|
+
if (field.tag === -1) throw new Error('Missing tag number in message field: ' + field.name)
|
|
141
|
+
tokens.shift()
|
|
142
|
+
return field
|
|
143
|
+
|
|
144
|
+
default:
|
|
145
|
+
throw new Error('Unexpected token in message field: ' + tokens[0])
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
throw new Error('No ; found for message field')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
var onmessagebody = function (tokens) {
|
|
153
|
+
var body = {
|
|
154
|
+
enums: [],
|
|
155
|
+
options: Object.create(null),
|
|
156
|
+
messages: [],
|
|
157
|
+
fields: [],
|
|
158
|
+
extends: [],
|
|
159
|
+
extensions: null
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
while (tokens.length) {
|
|
163
|
+
switch (tokens[0]) {
|
|
164
|
+
case 'map':
|
|
165
|
+
case 'repeated':
|
|
166
|
+
case 'optional':
|
|
167
|
+
case 'required':
|
|
168
|
+
body.fields.push(onfield(tokens))
|
|
169
|
+
break
|
|
170
|
+
|
|
171
|
+
case 'enum':
|
|
172
|
+
body.enums.push(onenum(tokens))
|
|
173
|
+
break
|
|
174
|
+
|
|
175
|
+
case 'message':
|
|
176
|
+
body.messages.push(onmessage(tokens))
|
|
177
|
+
break
|
|
178
|
+
|
|
179
|
+
case 'extensions':
|
|
180
|
+
body.extensions = onextensions(tokens)
|
|
181
|
+
break
|
|
182
|
+
|
|
183
|
+
case 'oneof':
|
|
184
|
+
tokens.shift()
|
|
185
|
+
var name = tokens.shift()
|
|
186
|
+
if (tokens[0] !== '{') throw new Error('Unexpected token in oneof: ' + tokens[0])
|
|
187
|
+
tokens.shift()
|
|
188
|
+
while (tokens[0] !== '}') {
|
|
189
|
+
tokens.unshift('optional')
|
|
190
|
+
var field = onfield(tokens)
|
|
191
|
+
field.oneof = name
|
|
192
|
+
body.fields.push(field)
|
|
193
|
+
}
|
|
194
|
+
tokens.shift()
|
|
195
|
+
break
|
|
196
|
+
|
|
197
|
+
case 'extend':
|
|
198
|
+
body.extends.push(onextend(tokens))
|
|
199
|
+
break
|
|
200
|
+
|
|
201
|
+
case ';':
|
|
202
|
+
tokens.shift()
|
|
203
|
+
break
|
|
204
|
+
|
|
205
|
+
case 'reserved':
|
|
206
|
+
tokens.shift()
|
|
207
|
+
while (tokens[0] !== ';') {
|
|
208
|
+
tokens.shift()
|
|
209
|
+
}
|
|
210
|
+
break
|
|
211
|
+
|
|
212
|
+
case 'option':
|
|
213
|
+
var opt = onoption(tokens)
|
|
214
|
+
if (body.options[opt.name] !== undefined) throw new Error('Duplicate option ' + opt.name)
|
|
215
|
+
body.options[opt.name] = opt.value
|
|
216
|
+
break
|
|
217
|
+
|
|
218
|
+
default:
|
|
219
|
+
// proto3 does not require the use of optional/required, assumed as optional
|
|
220
|
+
// "singular: a well-formed message can have zero or one of this field (but not more than one)."
|
|
221
|
+
// https://developers.google.com/protocol-buffers/docs/proto3#specifying-field-rules
|
|
222
|
+
tokens.unshift('optional')
|
|
223
|
+
body.fields.push(onfield(tokens))
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return body
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
var onextend = function (tokens) {
|
|
231
|
+
var out = {
|
|
232
|
+
name: tokens[1],
|
|
233
|
+
message: onmessage(tokens)
|
|
234
|
+
}
|
|
235
|
+
return out
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
var onextensions = function (tokens) {
|
|
239
|
+
tokens.shift()
|
|
240
|
+
var from = Number(tokens.shift())
|
|
241
|
+
if (isNaN(from)) throw new Error('Invalid from in extensions definition')
|
|
242
|
+
if (tokens.shift() !== 'to') throw new Error("Expected keyword 'to' in extensions definition")
|
|
243
|
+
var to = tokens.shift()
|
|
244
|
+
if (to === 'max') to = MAX_RANGE
|
|
245
|
+
to = Number(to)
|
|
246
|
+
if (isNaN(to)) throw new Error('Invalid to in extensions definition')
|
|
247
|
+
if (tokens.shift() !== ';') throw new Error('Missing ; in extensions definition')
|
|
248
|
+
return { from: from, to: to }
|
|
249
|
+
}
|
|
250
|
+
var onmessage = function (tokens) {
|
|
251
|
+
tokens.shift()
|
|
252
|
+
|
|
253
|
+
var lvl = 1
|
|
254
|
+
var body = []
|
|
255
|
+
var msg = {
|
|
256
|
+
name: tokens.shift(),
|
|
257
|
+
options: Object.create(null),
|
|
258
|
+
enums: [],
|
|
259
|
+
extends: [],
|
|
260
|
+
messages: [],
|
|
261
|
+
fields: []
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (tokens[0] !== '{') throw new Error('Expected { but found ' + tokens[0])
|
|
265
|
+
tokens.shift()
|
|
266
|
+
|
|
267
|
+
while (tokens.length) {
|
|
268
|
+
if (tokens[0] === '{') lvl++
|
|
269
|
+
else if (tokens[0] === '}') lvl--
|
|
270
|
+
|
|
271
|
+
if (!lvl) {
|
|
272
|
+
tokens.shift()
|
|
273
|
+
body = onmessagebody(body)
|
|
274
|
+
msg.enums = body.enums
|
|
275
|
+
msg.messages = body.messages
|
|
276
|
+
msg.fields = body.fields
|
|
277
|
+
msg.extends = body.extends
|
|
278
|
+
msg.extensions = body.extensions
|
|
279
|
+
msg.options = body.options
|
|
280
|
+
return msg
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
body.push(tokens.shift())
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (lvl) throw new Error('No closing tag for message')
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
var onpackagename = function (tokens) {
|
|
290
|
+
tokens.shift()
|
|
291
|
+
var name = tokens.shift()
|
|
292
|
+
if (tokens[0] !== ';') throw new Error('Expected ; but found ' + tokens[0])
|
|
293
|
+
tokens.shift()
|
|
294
|
+
return name
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
var onsyntaxversion = function (tokens) {
|
|
298
|
+
tokens.shift()
|
|
299
|
+
|
|
300
|
+
if (tokens[0] !== '=') throw new Error('Expected = but found ' + tokens[0])
|
|
301
|
+
tokens.shift()
|
|
302
|
+
|
|
303
|
+
var version = tokens.shift()
|
|
304
|
+
switch (version) {
|
|
305
|
+
case '"proto2"':
|
|
306
|
+
version = 2
|
|
307
|
+
break
|
|
308
|
+
|
|
309
|
+
case '"proto3"':
|
|
310
|
+
version = 3
|
|
311
|
+
break
|
|
312
|
+
|
|
313
|
+
default:
|
|
314
|
+
throw new Error('Expected protobuf syntax version but found ' + version)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (tokens[0] !== ';') throw new Error('Expected ; but found ' + tokens[0])
|
|
318
|
+
tokens.shift()
|
|
319
|
+
|
|
320
|
+
return version
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
var onenumvalue = function (tokens) {
|
|
324
|
+
if (tokens.length < 4) throw new Error('Invalid enum value: ' + tokens.slice(0, 3).join(' '))
|
|
325
|
+
if (tokens[0] === 'reserved') {
|
|
326
|
+
tokens.shift()
|
|
327
|
+
while (tokens[0] !== ';') {
|
|
328
|
+
tokens.shift()
|
|
329
|
+
}
|
|
330
|
+
tokens.shift()
|
|
331
|
+
return null
|
|
332
|
+
}
|
|
333
|
+
if (tokens[1] !== '=') throw new Error('Expected = but found ' + tokens[1])
|
|
334
|
+
if (tokens[3] !== ';' && tokens[3] !== '[') throw new Error('Expected ; or [ but found ' + tokens[1])
|
|
335
|
+
|
|
336
|
+
var name = tokens.shift()
|
|
337
|
+
tokens.shift()
|
|
338
|
+
var val = {
|
|
339
|
+
value: null,
|
|
340
|
+
options: Object.create(null)
|
|
341
|
+
}
|
|
342
|
+
val.value = Number(tokens.shift())
|
|
343
|
+
if (tokens[0] === '[') {
|
|
344
|
+
val.options = onfieldoptions(tokens)
|
|
345
|
+
}
|
|
346
|
+
tokens.shift() // expecting the semicolon here
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
name: name,
|
|
350
|
+
val: val
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
var onenum = function (tokens) {
|
|
355
|
+
tokens.shift()
|
|
356
|
+
var options = {}
|
|
357
|
+
var e = {
|
|
358
|
+
name: tokens.shift(),
|
|
359
|
+
values: {},
|
|
360
|
+
options: Object.create(null)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (tokens[0] !== '{') throw new Error('Expected { but found ' + tokens[0])
|
|
364
|
+
tokens.shift()
|
|
365
|
+
|
|
366
|
+
while (tokens.length) {
|
|
367
|
+
if (tokens[0] === '}') {
|
|
368
|
+
tokens.shift()
|
|
369
|
+
// there goes optional semicolon after the enclosing "}"
|
|
370
|
+
if (tokens[0] === ';') tokens.shift()
|
|
371
|
+
return e
|
|
372
|
+
}
|
|
373
|
+
if (tokens[0] === 'option') {
|
|
374
|
+
options = onoption(tokens)
|
|
375
|
+
e.options[options.name] = options.value
|
|
376
|
+
continue
|
|
377
|
+
}
|
|
378
|
+
var val = onenumvalue(tokens)
|
|
379
|
+
if (val !== null) {
|
|
380
|
+
e.values[val.name] = val.val
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
throw new Error('No closing tag for enum')
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
var onoption = function (tokens) {
|
|
388
|
+
var name = null
|
|
389
|
+
var value = null
|
|
390
|
+
|
|
391
|
+
var parse = function (value) {
|
|
392
|
+
if (value === 'true') return true
|
|
393
|
+
if (value === 'false') return false
|
|
394
|
+
return value.replace(/^"+|"+$/gm, '')
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
while (tokens.length) {
|
|
398
|
+
if (tokens[0] === ';') {
|
|
399
|
+
tokens.shift()
|
|
400
|
+
return { name: name, value: value }
|
|
401
|
+
}
|
|
402
|
+
switch (tokens[0]) {
|
|
403
|
+
case 'option':
|
|
404
|
+
tokens.shift()
|
|
405
|
+
|
|
406
|
+
var hasBracket = tokens[0] === '('
|
|
407
|
+
if (hasBracket) tokens.shift()
|
|
408
|
+
|
|
409
|
+
name = tokens.shift()
|
|
410
|
+
|
|
411
|
+
if (hasBracket) {
|
|
412
|
+
if (tokens[0] !== ')') throw new Error('Expected ) but found ' + tokens[0])
|
|
413
|
+
tokens.shift()
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (tokens[0][0] === '.') {
|
|
417
|
+
name += tokens.shift()
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
break
|
|
421
|
+
|
|
422
|
+
case '=':
|
|
423
|
+
tokens.shift()
|
|
424
|
+
if (name === null) throw new Error('Expected key for option with value: ' + tokens[0])
|
|
425
|
+
value = parse(tokens.shift())
|
|
426
|
+
|
|
427
|
+
if (name === 'optimize_for' && !/^(SPEED|CODE_SIZE|LITE_RUNTIME)$/.test(value)) {
|
|
428
|
+
throw new Error('Unexpected value for option optimize_for: ' + value)
|
|
429
|
+
} else if (value === '{') {
|
|
430
|
+
// option foo = {bar: baz}
|
|
431
|
+
value = onoptionMap(tokens)
|
|
432
|
+
}
|
|
433
|
+
break
|
|
434
|
+
|
|
435
|
+
default:
|
|
436
|
+
throw new Error('Unexpected token in option: ' + tokens[0])
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
var onoptionMap = function (tokens) {
|
|
442
|
+
var parse = function (value) {
|
|
443
|
+
if (value === 'true') return true
|
|
444
|
+
if (value === 'false') return false
|
|
445
|
+
return value.replace(/^"+|"+$/gm, '')
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
var map = Object.create(null)
|
|
449
|
+
|
|
450
|
+
while (tokens.length) {
|
|
451
|
+
if (tokens[0] === '}') {
|
|
452
|
+
tokens.shift()
|
|
453
|
+
return map
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
var hasBracket = tokens[0] === '('
|
|
457
|
+
if (hasBracket) tokens.shift()
|
|
458
|
+
|
|
459
|
+
var key = tokens.shift()
|
|
460
|
+
if (hasBracket) {
|
|
461
|
+
if (tokens[0] !== ')') throw new Error('Expected ) but found ' + tokens[0])
|
|
462
|
+
tokens.shift()
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
var value = null
|
|
466
|
+
|
|
467
|
+
switch (tokens[0]) {
|
|
468
|
+
case ':':
|
|
469
|
+
if (map[key] !== undefined) throw new Error('Duplicate option map key ' + key)
|
|
470
|
+
|
|
471
|
+
tokens.shift()
|
|
472
|
+
|
|
473
|
+
value = parse(tokens.shift())
|
|
474
|
+
|
|
475
|
+
if (value === '{') {
|
|
476
|
+
// option foo = {bar: baz}
|
|
477
|
+
value = onoptionMap(tokens)
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
map[key] = value
|
|
481
|
+
|
|
482
|
+
if (tokens[0] === ';') {
|
|
483
|
+
tokens.shift()
|
|
484
|
+
}
|
|
485
|
+
break
|
|
486
|
+
|
|
487
|
+
case '{':
|
|
488
|
+
tokens.shift()
|
|
489
|
+
value = onoptionMap(tokens)
|
|
490
|
+
|
|
491
|
+
if (map[key] === undefined) map[key] = []
|
|
492
|
+
if (!Array.isArray(map[key])) throw new Error('Duplicate option map key ' + key)
|
|
493
|
+
|
|
494
|
+
map[key].push(value)
|
|
495
|
+
break
|
|
496
|
+
|
|
497
|
+
default:
|
|
498
|
+
throw new Error('Unexpected token in option map: ' + tokens[0])
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
throw new Error('No closing tag for option map')
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
var onimport = function (tokens) {
|
|
506
|
+
tokens.shift()
|
|
507
|
+
var file = tokens.shift().replace(/^"+|"+$/gm, '')
|
|
508
|
+
|
|
509
|
+
if (tokens[0] !== ';') throw new Error('Unexpected token: ' + tokens[0] + '. Expected ";"')
|
|
510
|
+
|
|
511
|
+
tokens.shift()
|
|
512
|
+
return file
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
var onservice = function (tokens) {
|
|
516
|
+
tokens.shift()
|
|
517
|
+
|
|
518
|
+
var service = {
|
|
519
|
+
name: tokens.shift(),
|
|
520
|
+
methods: [],
|
|
521
|
+
options: Object.create(null)
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (tokens[0] !== '{') throw new Error('Expected { but found ' + tokens[0])
|
|
525
|
+
tokens.shift()
|
|
526
|
+
|
|
527
|
+
while (tokens.length) {
|
|
528
|
+
if (tokens[0] === '}') {
|
|
529
|
+
tokens.shift()
|
|
530
|
+
// there goes optional semicolon after the enclosing "}"
|
|
531
|
+
if (tokens[0] === ';') tokens.shift()
|
|
532
|
+
return service
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
switch (tokens[0]) {
|
|
536
|
+
case 'option':
|
|
537
|
+
var opt = onoption(tokens)
|
|
538
|
+
if (service.options[opt.name] !== undefined) throw new Error('Duplicate option ' + opt.name)
|
|
539
|
+
service.options[opt.name] = opt.value
|
|
540
|
+
break
|
|
541
|
+
case 'rpc':
|
|
542
|
+
service.methods.push(onrpc(tokens))
|
|
543
|
+
break
|
|
544
|
+
default:
|
|
545
|
+
throw new Error('Unexpected token in service: ' + tokens[0])
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
throw new Error('No closing tag for service')
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
var onrpc = function (tokens) {
|
|
553
|
+
tokens.shift()
|
|
554
|
+
|
|
555
|
+
var rpc = {
|
|
556
|
+
name: tokens.shift(),
|
|
557
|
+
input_type: null,
|
|
558
|
+
output_type: null,
|
|
559
|
+
client_streaming: false,
|
|
560
|
+
server_streaming: false,
|
|
561
|
+
options: Object.create(null)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (tokens[0] !== '(') throw new Error('Expected ( but found ' + tokens[0])
|
|
565
|
+
tokens.shift()
|
|
566
|
+
|
|
567
|
+
if (tokens[0] === 'stream') {
|
|
568
|
+
tokens.shift()
|
|
569
|
+
rpc.client_streaming = true
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
rpc.input_type = tokens.shift()
|
|
573
|
+
|
|
574
|
+
if (tokens[0] !== ')') throw new Error('Expected ) but found ' + tokens[0])
|
|
575
|
+
tokens.shift()
|
|
576
|
+
|
|
577
|
+
if (tokens[0] !== 'returns') throw new Error('Expected returns but found ' + tokens[0])
|
|
578
|
+
tokens.shift()
|
|
579
|
+
|
|
580
|
+
if (tokens[0] !== '(') throw new Error('Expected ( but found ' + tokens[0])
|
|
581
|
+
tokens.shift()
|
|
582
|
+
|
|
583
|
+
if (tokens[0] === 'stream') {
|
|
584
|
+
tokens.shift()
|
|
585
|
+
rpc.server_streaming = true
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
rpc.output_type = tokens.shift()
|
|
589
|
+
|
|
590
|
+
if (tokens[0] !== ')') throw new Error('Expected ) but found ' + tokens[0])
|
|
591
|
+
tokens.shift()
|
|
592
|
+
|
|
593
|
+
if (tokens[0] === ';') {
|
|
594
|
+
tokens.shift()
|
|
595
|
+
return rpc
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
if (tokens[0] !== '{') throw new Error('Expected { but found ' + tokens[0])
|
|
599
|
+
tokens.shift()
|
|
600
|
+
|
|
601
|
+
while (tokens.length) {
|
|
602
|
+
if (tokens[0] === '}') {
|
|
603
|
+
tokens.shift()
|
|
604
|
+
// there goes optional semicolon after the enclosing "}"
|
|
605
|
+
if (tokens[0] === ';') tokens.shift()
|
|
606
|
+
return rpc
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (tokens[0] === 'option') {
|
|
610
|
+
var opt = onoption(tokens)
|
|
611
|
+
if (rpc.options[opt.name] !== undefined) throw new Error('Duplicate option ' + opt.name)
|
|
612
|
+
rpc.options[opt.name] = opt.value
|
|
613
|
+
} else {
|
|
614
|
+
throw new Error('Unexpected token in rpc options: ' + tokens[0])
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
throw new Error('No closing tag for rpc')
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
var parse = function (buf) {
|
|
622
|
+
var tokens = tokenize(buf.toString())
|
|
623
|
+
// check for isolated strings in tokens by looking for opening quote
|
|
624
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
625
|
+
if (/^("|')([^'"]*)$/.test(tokens[i])) {
|
|
626
|
+
var j
|
|
627
|
+
if (tokens[i].length === 1) {
|
|
628
|
+
j = i + 1
|
|
629
|
+
} else {
|
|
630
|
+
j = i
|
|
631
|
+
}
|
|
632
|
+
// look ahead for the closing quote and collapse all
|
|
633
|
+
// in-between tokens into a single token
|
|
634
|
+
for (j; j < tokens.length; j++) {
|
|
635
|
+
if (/^[^'"\\]*(?:\\.[^'"\\]*)*("|')$/.test(tokens[j])) {
|
|
636
|
+
tokens = tokens.slice(0, i).concat(tokens.slice(i, j + 1).join('')).concat(tokens.slice(j + 1))
|
|
637
|
+
break
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
var schema = {
|
|
643
|
+
syntax: 3,
|
|
644
|
+
package: null,
|
|
645
|
+
imports: [],
|
|
646
|
+
enums: [],
|
|
647
|
+
messages: [],
|
|
648
|
+
options: Object.create(null),
|
|
649
|
+
extends: []
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
var firstline = true
|
|
653
|
+
|
|
654
|
+
while (tokens.length) {
|
|
655
|
+
switch (tokens[0]) {
|
|
656
|
+
case 'package':
|
|
657
|
+
schema.package = onpackagename(tokens)
|
|
658
|
+
break
|
|
659
|
+
|
|
660
|
+
case 'syntax':
|
|
661
|
+
if (!firstline) throw new Error('Protobuf syntax version should be first thing in file')
|
|
662
|
+
schema.syntax = onsyntaxversion(tokens)
|
|
663
|
+
break
|
|
664
|
+
|
|
665
|
+
case 'message':
|
|
666
|
+
schema.messages.push(onmessage(tokens))
|
|
667
|
+
break
|
|
668
|
+
|
|
669
|
+
case 'enum':
|
|
670
|
+
schema.enums.push(onenum(tokens))
|
|
671
|
+
break
|
|
672
|
+
|
|
673
|
+
case 'option':
|
|
674
|
+
var opt = onoption(tokens)
|
|
675
|
+
if (schema.options[opt.name]) throw new Error('Duplicate option ' + opt.name)
|
|
676
|
+
schema.options[opt.name] = opt.value
|
|
677
|
+
break
|
|
678
|
+
|
|
679
|
+
case 'import':
|
|
680
|
+
schema.imports.push(onimport(tokens))
|
|
681
|
+
break
|
|
682
|
+
|
|
683
|
+
case 'extend':
|
|
684
|
+
schema.extends.push(onextend(tokens))
|
|
685
|
+
break
|
|
686
|
+
|
|
687
|
+
case 'service':
|
|
688
|
+
if (!schema.services) schema.services = []
|
|
689
|
+
schema.services.push(onservice(tokens))
|
|
690
|
+
break
|
|
691
|
+
|
|
692
|
+
default:
|
|
693
|
+
throw new Error('Unexpected token: ' + tokens[0])
|
|
694
|
+
}
|
|
695
|
+
firstline = false
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// now iterate over messages and propagate extends
|
|
699
|
+
schema.extends.forEach(function (ext) {
|
|
700
|
+
schema.messages.forEach(function (msg) {
|
|
701
|
+
if (msg.name === ext.name) {
|
|
702
|
+
ext.message.fields.forEach(function (field) {
|
|
703
|
+
if (!msg.extensions || field.tag < msg.extensions.from || field.tag > msg.extensions.to) {
|
|
704
|
+
throw new Error(msg.name + ' does not declare ' + field.tag + ' as an extension number')
|
|
705
|
+
}
|
|
706
|
+
msg.fields.push(field)
|
|
707
|
+
})
|
|
708
|
+
}
|
|
709
|
+
})
|
|
710
|
+
})
|
|
711
|
+
|
|
712
|
+
schema.messages.forEach(function (msg) {
|
|
713
|
+
msg.fields.forEach(function (field) {
|
|
714
|
+
var fieldSplit
|
|
715
|
+
var messageName
|
|
716
|
+
var nestedEnumName
|
|
717
|
+
var message
|
|
718
|
+
|
|
719
|
+
function enumNameIsFieldType (en) {
|
|
720
|
+
return en.name === field.type
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function enumNameIsNestedEnumName (en) {
|
|
724
|
+
return en.name === nestedEnumName
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (field.options && field.options.packed === 'true') {
|
|
728
|
+
if (PACKABLE_TYPES.indexOf(field.type) === -1) {
|
|
729
|
+
// let's see if it's an enum
|
|
730
|
+
if (field.type.indexOf('.') === -1) {
|
|
731
|
+
if (msg.enums && msg.enums.some(enumNameIsFieldType)) {
|
|
732
|
+
return
|
|
733
|
+
}
|
|
734
|
+
} else {
|
|
735
|
+
fieldSplit = field.type.split('.')
|
|
736
|
+
if (fieldSplit.length > 2) {
|
|
737
|
+
throw new Error('what is this?')
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
messageName = fieldSplit[0]
|
|
741
|
+
nestedEnumName = fieldSplit[1]
|
|
742
|
+
|
|
743
|
+
schema.messages.some(function (msg) {
|
|
744
|
+
if (msg.name === messageName) {
|
|
745
|
+
message = msg
|
|
746
|
+
return msg
|
|
747
|
+
}
|
|
748
|
+
})
|
|
749
|
+
|
|
750
|
+
if (message && message.enums && message.enums.some(enumNameIsNestedEnumName)) {
|
|
751
|
+
return
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
throw new Error(
|
|
756
|
+
'Fields of type ' + field.type + ' cannot be declared [packed=true]. ' +
|
|
757
|
+
'Only repeated fields of primitive numeric types (types which use ' +
|
|
758
|
+
'the varint, 32-bit, or 64-bit wire types) can be declared "packed". ' +
|
|
759
|
+
'See https://developers.google.com/protocol-buffers/docs/encoding#optional'
|
|
760
|
+
)
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
})
|
|
764
|
+
})
|
|
765
|
+
|
|
766
|
+
return schema
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
module.exports = parse
|