@aptre/protobuf-es-lite 0.2.0 → 0.2.3
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/dist/binary.js +24 -9
- package/dist/json.js +8 -2
- package/package.json +8 -3
package/dist/binary.js
CHANGED
|
@@ -12,7 +12,11 @@ function readField(target, // eslint-disable-line @typescript-eslint/no-explicit
|
|
|
12
12
|
reader, field, wireType, options) {
|
|
13
13
|
let { repeated, localName } = field;
|
|
14
14
|
if (field.oneof) {
|
|
15
|
-
|
|
15
|
+
var oneofMsg = target[field.oneof.localName];
|
|
16
|
+
if (!oneofMsg) {
|
|
17
|
+
oneofMsg = target[field.oneof.localName] = {};
|
|
18
|
+
}
|
|
19
|
+
target = oneofMsg;
|
|
16
20
|
if (target.case != localName) {
|
|
17
21
|
delete target.value;
|
|
18
22
|
}
|
|
@@ -29,18 +33,21 @@ reader, field, wireType, options) {
|
|
|
29
33
|
read = readScalarLTString;
|
|
30
34
|
}
|
|
31
35
|
if (repeated) {
|
|
32
|
-
|
|
36
|
+
var tgtArr = target[localName];
|
|
37
|
+
if (!Array.isArray(tgtArr)) {
|
|
38
|
+
tgtArr = target[localName] = [];
|
|
39
|
+
}
|
|
33
40
|
const isPacked = wireType == protobuf_1.WireType.LengthDelimited &&
|
|
34
41
|
scalarType != protobuf_1.ScalarType.STRING &&
|
|
35
42
|
scalarType != protobuf_1.ScalarType.BYTES;
|
|
36
43
|
if (isPacked) {
|
|
37
44
|
let e = reader.uint32() + reader.pos;
|
|
38
45
|
while (reader.pos < e) {
|
|
39
|
-
|
|
46
|
+
tgtArr.push(read(reader, scalarType));
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
49
|
else {
|
|
43
|
-
|
|
50
|
+
tgtArr.push(read(reader, scalarType));
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
else {
|
|
@@ -50,8 +57,11 @@ reader, field, wireType, options) {
|
|
|
50
57
|
case "message":
|
|
51
58
|
const messageType = field.T;
|
|
52
59
|
if (repeated) {
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
var tgtArr = target[localName];
|
|
61
|
+
if (!Array.isArray(tgtArr)) {
|
|
62
|
+
tgtArr = target[localName] = [];
|
|
63
|
+
}
|
|
64
|
+
tgtArr.push(readMessageField(reader, messageType.create(), messageType.fields, options, field));
|
|
55
65
|
}
|
|
56
66
|
else {
|
|
57
67
|
if ((0, is_message_js_1.isCompleteMessage)(target[localName], messageType.fields.list())) {
|
|
@@ -67,6 +77,9 @@ reader, field, wireType, options) {
|
|
|
67
77
|
break;
|
|
68
78
|
case "map":
|
|
69
79
|
let [mapKey, mapVal] = readMapEntry(field, reader, options);
|
|
80
|
+
if (typeof target[localName] !== "object") {
|
|
81
|
+
target[localName] = {};
|
|
82
|
+
}
|
|
70
83
|
// safe to assume presence of map object, oneof cannot contain repeated values
|
|
71
84
|
target[localName][mapKey] = mapVal;
|
|
72
85
|
break;
|
|
@@ -293,12 +306,12 @@ function writeMessageField(writer, options, field, value) {
|
|
|
293
306
|
if (field.delimited)
|
|
294
307
|
writer
|
|
295
308
|
.tag(field.no, protobuf_1.WireType.StartGroup)
|
|
296
|
-
.raw(
|
|
309
|
+
.raw(field.T.toBinary(message, options))
|
|
297
310
|
.tag(field.no, protobuf_1.WireType.EndGroup);
|
|
298
311
|
else
|
|
299
312
|
writer
|
|
300
313
|
.tag(field.no, protobuf_1.WireType.LengthDelimited)
|
|
301
|
-
.bytes(
|
|
314
|
+
.bytes(field.T.toBinary(message, options));
|
|
302
315
|
}
|
|
303
316
|
function writeScalar(writer, type, fieldNo, value) {
|
|
304
317
|
(0, assert_js_1.assert)(value !== undefined);
|
|
@@ -381,7 +394,9 @@ function writeMapEntry(writer, options, field, key, value) {
|
|
|
381
394
|
break;
|
|
382
395
|
case "message":
|
|
383
396
|
(0, assert_js_1.assert)(value !== undefined);
|
|
384
|
-
writer
|
|
397
|
+
writer
|
|
398
|
+
.tag(2, protobuf_1.WireType.LengthDelimited)
|
|
399
|
+
.bytes(field.V.T.toBinary(value, options));
|
|
385
400
|
break;
|
|
386
401
|
}
|
|
387
402
|
writer.join();
|
package/dist/json.js
CHANGED
|
@@ -165,7 +165,10 @@ function readField(target, jsonValue, field, options) {
|
|
|
165
165
|
if (!Array.isArray(jsonValue)) {
|
|
166
166
|
throw new Error(`cannot decode field ${field.name} from JSON: ${debugJsonValue(jsonValue)}`);
|
|
167
167
|
}
|
|
168
|
-
|
|
168
|
+
var targetArray = target[localName];
|
|
169
|
+
if (!Array.isArray(targetArray)) {
|
|
170
|
+
targetArray = target[localName] = [];
|
|
171
|
+
}
|
|
169
172
|
for (const jsonItem of jsonValue) {
|
|
170
173
|
if (jsonItem === null) {
|
|
171
174
|
throw new Error(`cannot decode field ${field.name} from JSON: ${debugJsonValue(jsonItem)}`);
|
|
@@ -202,7 +205,10 @@ function readField(target, jsonValue, field, options) {
|
|
|
202
205
|
if (typeof jsonValue != "object" || Array.isArray(jsonValue)) {
|
|
203
206
|
throw new Error(`cannot decode field ${field.name} from JSON: ${debugJsonValue(jsonValue)}`);
|
|
204
207
|
}
|
|
205
|
-
|
|
208
|
+
var targetMap = target[localName];
|
|
209
|
+
if (typeof targetMap !== "object") {
|
|
210
|
+
targetMap = target[localName] = {};
|
|
211
|
+
}
|
|
206
212
|
for (const [jsonMapKey, jsonMapValue] of Object.entries(jsonValue)) {
|
|
207
213
|
if (jsonMapValue === null) {
|
|
208
214
|
throw new Error(`cannot decode field ${field.name} from JSON: map value null`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptre/protobuf-es-lite",
|
|
3
3
|
"description": "Lightweight Protobuf codegen for TypeScript and JavaScript.",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "git+ssh://git@github.com/aperturerobotics/protobuf-es-lite.git"
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"build": "npm run clean && tsc --project tsconfig.json --outDir ./dist",
|
|
37
37
|
"release:version": "npm version patch -m \"release: v%s\" --no-git-tag-version",
|
|
38
38
|
"release:commit": "git reset && git add package.json && git commit -s -m \"release: v$npm_package_version\" && git tag v$npm_package_version",
|
|
39
|
-
"release:publish": "git push --
|
|
39
|
+
"release:publish": "git push && git push --tags && npm run build && npm publish",
|
|
40
40
|
"release": "npm run release:version && npm run release:commit",
|
|
41
41
|
"typecheck": "tsc --noEmit --project tsconfig.json --outDir ./dist",
|
|
42
42
|
"example": "npm run build && protoc --plugin=./bin/protoc-gen-es-lite --es-lite_out=. --es-lite_opt target=ts --es-lite_opt ts_nocheck=false ./example/example.proto",
|
|
43
43
|
"format": "prettier --write './src/**/(*.ts|*.tsx|*.html|*.css|*.scss)'",
|
|
44
|
-
"precommit": "
|
|
44
|
+
"precommit": "lint-staged"
|
|
45
45
|
},
|
|
46
46
|
"preferUnplugged": true,
|
|
47
47
|
"pre-commit": [
|
|
@@ -60,9 +60,14 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
+
"lint-staged": ">=10",
|
|
63
64
|
"pre-commit": "^1.2.2",
|
|
64
65
|
"prettier": "^3.2.5",
|
|
65
66
|
"rimraf": "^5.0.5",
|
|
66
67
|
"typescript": "^5.4.5"
|
|
68
|
+
},
|
|
69
|
+
"lint-staged": {
|
|
70
|
+
"package.json": "prettier --write",
|
|
71
|
+
"./src/**/(*.ts|*.tsx|*.html|*.css|*.scss)": "prettier --write"
|
|
67
72
|
}
|
|
68
73
|
}
|