@bufbuild/protobuf 2.2.5 → 2.3.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/dist/cjs/clone.js +4 -6
- package/dist/cjs/codegenv1/boot.js +1 -1
- package/dist/cjs/codegenv1/embed.js +0 -1
- package/dist/cjs/codegenv1/file.js +1 -1
- package/dist/cjs/codegenv1/symbols.js +1 -1
- package/dist/cjs/create.js +0 -1
- package/dist/cjs/equals.js +2 -1
- package/dist/cjs/extensions.js +1 -1
- package/dist/cjs/from-binary.js +5 -3
- package/dist/cjs/from-json.js +8 -10
- package/dist/cjs/proto-int64.js +4 -1
- package/dist/cjs/reflect/guard.js +2 -1
- package/dist/cjs/reflect/index.d.ts +1 -0
- package/dist/cjs/reflect/index.js +1 -0
- package/dist/cjs/reflect/names.d.ts +8 -0
- package/dist/cjs/reflect/names.js +28 -0
- package/dist/cjs/reflect/path.d.ts +107 -0
- package/dist/cjs/reflect/path.js +376 -0
- package/dist/cjs/reflect/reflect-check.js +3 -3
- package/dist/cjs/reflect/reflect-types.d.ts +1 -1
- package/dist/cjs/reflect/reflect.js +9 -7
- package/dist/cjs/reflect/scalar.js +4 -5
- package/dist/cjs/reflect/unsafe.d.ts +3 -6
- package/dist/cjs/reflect/unsafe.js +11 -10
- package/dist/cjs/registry.js +17 -25
- package/dist/cjs/to-binary.js +1 -1
- package/dist/cjs/to-json.d.ts +6 -0
- package/dist/cjs/to-json.js +16 -18
- package/dist/cjs/wire/base64-encoding.js +4 -3
- package/dist/cjs/wire/binary-encoding.js +7 -6
- package/dist/cjs/wire/text-encoding.js +1 -1
- package/dist/cjs/wire/text-format.js +3 -4
- package/dist/cjs/wire/varint.js +0 -1
- package/dist/esm/clone.js +4 -6
- package/dist/esm/codegenv1/boot.js +1 -1
- package/dist/esm/codegenv1/embed.js +0 -1
- package/dist/esm/codegenv1/file.js +1 -1
- package/dist/esm/codegenv1/symbols.js +1 -1
- package/dist/esm/create.js +0 -2
- package/dist/esm/equals.js +2 -1
- package/dist/esm/extensions.js +1 -1
- package/dist/esm/from-binary.js +5 -3
- package/dist/esm/from-json.js +8 -10
- package/dist/esm/proto-int64.js +4 -1
- package/dist/esm/reflect/guard.js +2 -1
- package/dist/esm/reflect/index.d.ts +1 -0
- package/dist/esm/reflect/index.js +1 -0
- package/dist/esm/reflect/names.d.ts +8 -0
- package/dist/esm/reflect/names.js +27 -0
- package/dist/esm/reflect/path.d.ts +107 -0
- package/dist/esm/reflect/path.js +369 -0
- package/dist/esm/reflect/reflect-check.js +3 -3
- package/dist/esm/reflect/reflect-types.d.ts +1 -1
- package/dist/esm/reflect/reflect-types.js +0 -1
- package/dist/esm/reflect/reflect.js +9 -7
- package/dist/esm/reflect/scalar.js +4 -5
- package/dist/esm/reflect/unsafe.d.ts +3 -6
- package/dist/esm/reflect/unsafe.js +11 -10
- package/dist/esm/registry.js +17 -25
- package/dist/esm/to-binary.js +1 -1
- package/dist/esm/to-json.d.ts +6 -0
- package/dist/esm/to-json.js +16 -18
- package/dist/esm/wire/base64-encoding.js +4 -3
- package/dist/esm/wire/binary-encoding.js +7 -6
- package/dist/esm/wire/text-encoding.js +1 -1
- package/dist/esm/wire/text-format.js +3 -4
- package/dist/esm/wire/varint.js +0 -1
- package/package.json +9 -24
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-2025 Buf Technologies, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.InvalidPathError = void 0;
|
|
17
|
+
exports.buildPath = buildPath;
|
|
18
|
+
exports.parsePath = parsePath;
|
|
19
|
+
exports.pathToString = pathToString;
|
|
20
|
+
const descriptors_js_1 = require("../descriptors.js");
|
|
21
|
+
/**
|
|
22
|
+
* Create a PathBuilder.
|
|
23
|
+
*/
|
|
24
|
+
function buildPath(schema) {
|
|
25
|
+
return new PathBuilderImpl(schema, schema, []);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse a Path from a string.
|
|
29
|
+
*
|
|
30
|
+
* Throws an InvalidPathError if the path is invalid.
|
|
31
|
+
*
|
|
32
|
+
* Note that a Registry must be provided via the options argument to parse
|
|
33
|
+
* paths that refer to an extension.
|
|
34
|
+
*/
|
|
35
|
+
function parsePath(schema, path, options) {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const builder = new PathBuilderImpl(schema, schema, []);
|
|
38
|
+
const err = (message, i) => new InvalidPathError(schema, message + " at column " + (i + 1), path);
|
|
39
|
+
for (let i = 0; i < path.length;) {
|
|
40
|
+
const token = nextToken(i, path);
|
|
41
|
+
const left = builder.getLeft();
|
|
42
|
+
let right = undefined;
|
|
43
|
+
if ("field" in token) {
|
|
44
|
+
right =
|
|
45
|
+
(left === null || left === void 0 ? void 0 : left.kind) != "message"
|
|
46
|
+
? undefined
|
|
47
|
+
: ((_a = left.fields.find((field) => field.name === token.field)) !== null && _a !== void 0 ? _a : left.oneofs.find((oneof) => oneof.name === token.field));
|
|
48
|
+
if (!right) {
|
|
49
|
+
throw err(`Unknown field "${token.field}"`, i);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if ("ext" in token) {
|
|
53
|
+
right = (_b = options === null || options === void 0 ? void 0 : options.registry) === null || _b === void 0 ? void 0 : _b.getExtension(token.ext);
|
|
54
|
+
if (!right) {
|
|
55
|
+
throw err(`Unknown extension "${token.ext}"`, i);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if ("val" in token) {
|
|
59
|
+
// list or map
|
|
60
|
+
right =
|
|
61
|
+
(left === null || left === void 0 ? void 0 : left.kind) == "field" &&
|
|
62
|
+
left.fieldKind == "list" &&
|
|
63
|
+
typeof token.val == "bigint"
|
|
64
|
+
? { kind: "list_sub", index: Number(token.val) }
|
|
65
|
+
: { kind: "map_sub", key: token.val };
|
|
66
|
+
}
|
|
67
|
+
else if ("err" in token) {
|
|
68
|
+
throw err(token.err, token.i);
|
|
69
|
+
}
|
|
70
|
+
if (right) {
|
|
71
|
+
try {
|
|
72
|
+
builder.add([right]);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
throw err(e instanceof InvalidPathError ? e.message : String(e), i);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
i = token.i;
|
|
79
|
+
}
|
|
80
|
+
return builder.toPath();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Stringify a path.
|
|
84
|
+
*/
|
|
85
|
+
function pathToString(path) {
|
|
86
|
+
const str = [];
|
|
87
|
+
for (const ele of path) {
|
|
88
|
+
switch (ele.kind) {
|
|
89
|
+
case "field":
|
|
90
|
+
case "oneof":
|
|
91
|
+
if (str.length > 0) {
|
|
92
|
+
str.push(".");
|
|
93
|
+
}
|
|
94
|
+
str.push(ele.name);
|
|
95
|
+
break;
|
|
96
|
+
case "extension":
|
|
97
|
+
str.push("[", ele.typeName, "]");
|
|
98
|
+
break;
|
|
99
|
+
case "list_sub":
|
|
100
|
+
str.push("[", ele.index, "]");
|
|
101
|
+
break;
|
|
102
|
+
case "map_sub":
|
|
103
|
+
if (typeof ele.key == "string") {
|
|
104
|
+
str.push('["', ele.key
|
|
105
|
+
.split("\\")
|
|
106
|
+
.join("\\\\")
|
|
107
|
+
.split('"')
|
|
108
|
+
.join('\\"')
|
|
109
|
+
.split("\r")
|
|
110
|
+
.join("\\r")
|
|
111
|
+
.split("\n")
|
|
112
|
+
.join("\\n"), '"]');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
str.push("[", ele.key, "]");
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return str.join("");
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* InvalidPathError is thrown for invalid Paths, for example during parsing from
|
|
124
|
+
* a string, or when a new Path is built.
|
|
125
|
+
*/
|
|
126
|
+
class InvalidPathError extends Error {
|
|
127
|
+
constructor(schema, message, path) {
|
|
128
|
+
super(message);
|
|
129
|
+
this.name = "InvalidPathError";
|
|
130
|
+
this.schema = schema;
|
|
131
|
+
this.path = path;
|
|
132
|
+
// see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#example
|
|
133
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.InvalidPathError = InvalidPathError;
|
|
137
|
+
class PathBuilderImpl {
|
|
138
|
+
constructor(schema, left, path) {
|
|
139
|
+
this.schema = schema;
|
|
140
|
+
this.left = left;
|
|
141
|
+
this.path = path;
|
|
142
|
+
}
|
|
143
|
+
getLeft() {
|
|
144
|
+
return this.left;
|
|
145
|
+
}
|
|
146
|
+
field(field) {
|
|
147
|
+
return this.push(field);
|
|
148
|
+
}
|
|
149
|
+
oneof(oneof) {
|
|
150
|
+
return this.push(oneof);
|
|
151
|
+
}
|
|
152
|
+
extension(extension) {
|
|
153
|
+
return this.push(extension);
|
|
154
|
+
}
|
|
155
|
+
list(index) {
|
|
156
|
+
return this.push({ kind: "list_sub", index });
|
|
157
|
+
}
|
|
158
|
+
map(key) {
|
|
159
|
+
return this.push({ kind: "map_sub", key });
|
|
160
|
+
}
|
|
161
|
+
add(pathOrBuilder) {
|
|
162
|
+
const path = Array.isArray(pathOrBuilder)
|
|
163
|
+
? pathOrBuilder
|
|
164
|
+
: pathOrBuilder.toPath();
|
|
165
|
+
const l = this.path.length;
|
|
166
|
+
try {
|
|
167
|
+
for (const ele of path) {
|
|
168
|
+
this.push(ele);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
// undo pushes
|
|
173
|
+
this.path.splice(l);
|
|
174
|
+
throw e;
|
|
175
|
+
}
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
toPath() {
|
|
179
|
+
return this.path.concat();
|
|
180
|
+
}
|
|
181
|
+
clone() {
|
|
182
|
+
return new PathBuilderImpl(this.schema, this.left, this.path.concat());
|
|
183
|
+
}
|
|
184
|
+
push(ele) {
|
|
185
|
+
switch (ele.kind) {
|
|
186
|
+
case "field":
|
|
187
|
+
if (!this.left ||
|
|
188
|
+
this.left.kind != "message" ||
|
|
189
|
+
this.left.typeName != ele.parent.typeName) {
|
|
190
|
+
throw this.err("field access");
|
|
191
|
+
}
|
|
192
|
+
this.path.push(ele);
|
|
193
|
+
this.left =
|
|
194
|
+
ele.fieldKind == "message"
|
|
195
|
+
? ele.message
|
|
196
|
+
: ele.fieldKind == "list" || ele.fieldKind == "map"
|
|
197
|
+
? ele
|
|
198
|
+
: undefined;
|
|
199
|
+
return this;
|
|
200
|
+
case "oneof":
|
|
201
|
+
if (!this.left ||
|
|
202
|
+
this.left.kind != "message" ||
|
|
203
|
+
this.left.typeName != ele.parent.typeName) {
|
|
204
|
+
throw this.err("oneof access");
|
|
205
|
+
}
|
|
206
|
+
this.path.push(ele);
|
|
207
|
+
this.left = undefined;
|
|
208
|
+
return this;
|
|
209
|
+
case "extension":
|
|
210
|
+
if (!this.left ||
|
|
211
|
+
this.left.kind != "message" ||
|
|
212
|
+
this.left.typeName != ele.extendee.typeName) {
|
|
213
|
+
throw this.err("extension access");
|
|
214
|
+
}
|
|
215
|
+
this.path.push(ele);
|
|
216
|
+
this.left = ele.fieldKind == "message" ? ele.message : undefined;
|
|
217
|
+
return this;
|
|
218
|
+
case "list_sub":
|
|
219
|
+
if (!this.left ||
|
|
220
|
+
this.left.kind != "field" ||
|
|
221
|
+
this.left.fieldKind != "list") {
|
|
222
|
+
throw this.err("list access");
|
|
223
|
+
}
|
|
224
|
+
if (ele.index < 0 || !Number.isInteger(ele.index)) {
|
|
225
|
+
throw this.err("list index");
|
|
226
|
+
}
|
|
227
|
+
this.path.push(ele);
|
|
228
|
+
this.left =
|
|
229
|
+
this.left.listKind == "message" ? this.left.message : undefined;
|
|
230
|
+
return this;
|
|
231
|
+
case "map_sub":
|
|
232
|
+
if (!this.left ||
|
|
233
|
+
this.left.kind != "field" ||
|
|
234
|
+
this.left.fieldKind != "map") {
|
|
235
|
+
throw this.err("map access");
|
|
236
|
+
}
|
|
237
|
+
if (!checkKeyType(ele.key, this.left.mapKey)) {
|
|
238
|
+
throw this.err("map key");
|
|
239
|
+
}
|
|
240
|
+
this.path.push(ele);
|
|
241
|
+
this.left =
|
|
242
|
+
this.left.mapKind == "message" ? this.left.message : undefined;
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
err(what) {
|
|
247
|
+
return new InvalidPathError(this.schema, "Invalid " + what, this.path);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function checkKeyType(key, type) {
|
|
251
|
+
switch (type) {
|
|
252
|
+
case descriptors_js_1.ScalarType.STRING:
|
|
253
|
+
return typeof key == "string";
|
|
254
|
+
case descriptors_js_1.ScalarType.INT32:
|
|
255
|
+
case descriptors_js_1.ScalarType.UINT32:
|
|
256
|
+
case descriptors_js_1.ScalarType.SINT32:
|
|
257
|
+
case descriptors_js_1.ScalarType.SFIXED32:
|
|
258
|
+
case descriptors_js_1.ScalarType.FIXED32:
|
|
259
|
+
return typeof key == "number";
|
|
260
|
+
case descriptors_js_1.ScalarType.UINT64:
|
|
261
|
+
case descriptors_js_1.ScalarType.INT64:
|
|
262
|
+
case descriptors_js_1.ScalarType.FIXED64:
|
|
263
|
+
case descriptors_js_1.ScalarType.SFIXED64:
|
|
264
|
+
case descriptors_js_1.ScalarType.SINT64:
|
|
265
|
+
return typeof key == "bigint";
|
|
266
|
+
case descriptors_js_1.ScalarType.BOOL:
|
|
267
|
+
return typeof key == "boolean";
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function nextToken(i, path) {
|
|
271
|
+
const re_extension = /^[A-Za-z_][A-Za-z_0-9]*(?:\.[A-Za-z_][A-Za-z_0-9]*)*$/;
|
|
272
|
+
const re_field = /^[A-Za-z_][A-Za-z_0-9]*$/;
|
|
273
|
+
if (path[i] == "[") {
|
|
274
|
+
i++;
|
|
275
|
+
while (path[i] == " ") {
|
|
276
|
+
// skip leading whitespace
|
|
277
|
+
i++;
|
|
278
|
+
}
|
|
279
|
+
if (i >= path.length) {
|
|
280
|
+
return { err: "Premature end", i: path.length - 1 };
|
|
281
|
+
}
|
|
282
|
+
let token;
|
|
283
|
+
if (path[i] == `"`) {
|
|
284
|
+
// string literal
|
|
285
|
+
i++;
|
|
286
|
+
let val = "";
|
|
287
|
+
for (;;) {
|
|
288
|
+
if (path[i] == `"`) {
|
|
289
|
+
// end of string literal
|
|
290
|
+
i++;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
if (path[i] == "\\") {
|
|
294
|
+
switch (path[i + 1]) {
|
|
295
|
+
case `"`:
|
|
296
|
+
case "\\":
|
|
297
|
+
val += path[i + 1];
|
|
298
|
+
break;
|
|
299
|
+
case "r":
|
|
300
|
+
val += "\r";
|
|
301
|
+
break;
|
|
302
|
+
case "n":
|
|
303
|
+
val += "\n";
|
|
304
|
+
break;
|
|
305
|
+
default:
|
|
306
|
+
return { err: "Invalid escape sequence", i };
|
|
307
|
+
}
|
|
308
|
+
i++;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
val += path[i];
|
|
312
|
+
}
|
|
313
|
+
if (i >= path.length) {
|
|
314
|
+
return { err: "Premature end of string", i: path.length - 1 };
|
|
315
|
+
}
|
|
316
|
+
i++;
|
|
317
|
+
}
|
|
318
|
+
token = { val };
|
|
319
|
+
}
|
|
320
|
+
else if (path[i].match(/\d/)) {
|
|
321
|
+
// integer literal
|
|
322
|
+
const start = i;
|
|
323
|
+
while (i < path.length && /\d/.test(path[i])) {
|
|
324
|
+
i++;
|
|
325
|
+
}
|
|
326
|
+
token = { val: BigInt(path.substring(start, i)) };
|
|
327
|
+
}
|
|
328
|
+
else if (path[i] == "]") {
|
|
329
|
+
return { err: "Premature ]", i };
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
// extension identifier or bool literal
|
|
333
|
+
const start = i;
|
|
334
|
+
while (i < path.length && path[i] != " " && path[i] != "]") {
|
|
335
|
+
i++;
|
|
336
|
+
}
|
|
337
|
+
const name = path.substring(start, i);
|
|
338
|
+
if (name === "true") {
|
|
339
|
+
token = { val: true };
|
|
340
|
+
}
|
|
341
|
+
else if (name === "false") {
|
|
342
|
+
token = { val: false };
|
|
343
|
+
}
|
|
344
|
+
else if (re_extension.test(name)) {
|
|
345
|
+
token = { ext: name };
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
return { err: "Invalid ident", i: start };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
while (path[i] == " ") {
|
|
352
|
+
// skip trailing whitespace
|
|
353
|
+
i++;
|
|
354
|
+
}
|
|
355
|
+
if (path[i] != "]") {
|
|
356
|
+
return { err: "Missing ]", i };
|
|
357
|
+
}
|
|
358
|
+
i++;
|
|
359
|
+
return Object.assign(Object.assign({}, token), { i });
|
|
360
|
+
}
|
|
361
|
+
// field identifier
|
|
362
|
+
if (i > 0) {
|
|
363
|
+
if (path[i] != ".") {
|
|
364
|
+
return { err: `Expected "."`, i };
|
|
365
|
+
}
|
|
366
|
+
i++;
|
|
367
|
+
}
|
|
368
|
+
const start = i;
|
|
369
|
+
while (i < path.length && path[i] != "." && path[i] != "[") {
|
|
370
|
+
i++;
|
|
371
|
+
}
|
|
372
|
+
const field = path.substring(start, i);
|
|
373
|
+
return re_field.test(field)
|
|
374
|
+
? { field, i }
|
|
375
|
+
: { err: "Invalid ident", i: start };
|
|
376
|
+
}
|
|
@@ -142,7 +142,7 @@ function checkScalarValue(value, scalar) {
|
|
|
142
142
|
proto_int64_js_1.protoInt64.parse(value);
|
|
143
143
|
return true;
|
|
144
144
|
}
|
|
145
|
-
catch (
|
|
145
|
+
catch (_) {
|
|
146
146
|
return `${value} out of range`;
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -157,7 +157,7 @@ function checkScalarValue(value, scalar) {
|
|
|
157
157
|
proto_int64_js_1.protoInt64.uParse(value);
|
|
158
158
|
return true;
|
|
159
159
|
}
|
|
160
|
-
catch (
|
|
160
|
+
catch (_) {
|
|
161
161
|
return `${value} out of range`;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -170,7 +170,7 @@ function reasonSingular(field, val, details) {
|
|
|
170
170
|
if (field.scalar !== undefined) {
|
|
171
171
|
return `expected ${scalarTypeDescription(field.scalar)}` + details;
|
|
172
172
|
}
|
|
173
|
-
|
|
173
|
+
if (field.enum !== undefined) {
|
|
174
174
|
return `expected ${field.enum.toString()}` + details;
|
|
175
175
|
}
|
|
176
176
|
return `expected ${formatReflectMessage(field.message)}` + details;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DescField, DescMessage, DescOneof } from "../descriptors.js";
|
|
2
2
|
import { unsafeLocal } from "./unsafe.js";
|
|
3
3
|
import type { Message, UnknownField } from "../types.js";
|
|
4
4
|
import type { ScalarValue } from "./scalar.js";
|
|
@@ -42,7 +42,9 @@ check = true) {
|
|
|
42
42
|
class ReflectMessageImpl {
|
|
43
43
|
get sortedFields() {
|
|
44
44
|
var _a;
|
|
45
|
-
return ((_a = this._sortedFields) !== null && _a !== void 0 ? _a :
|
|
45
|
+
return ((_a = this._sortedFields) !== null && _a !== void 0 ? _a :
|
|
46
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
47
|
+
(this._sortedFields = this.desc.fields
|
|
46
48
|
.concat()
|
|
47
49
|
.sort((a, b) => a.number - b.number)));
|
|
48
50
|
}
|
|
@@ -82,14 +84,17 @@ class ReflectMessageImpl {
|
|
|
82
84
|
// eslint-disable-next-line no-case-declarations
|
|
83
85
|
let list = this.lists.get(field);
|
|
84
86
|
if (!list || list[unsafe_js_1.unsafeLocal] !== value) {
|
|
85
|
-
this.lists.set(field,
|
|
87
|
+
this.lists.set(field,
|
|
88
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
89
|
+
(list = new ReflectListImpl(field, value, this.check)));
|
|
86
90
|
}
|
|
87
91
|
return list;
|
|
88
92
|
case "map":
|
|
89
|
-
// eslint-disable-next-line no-case-declarations
|
|
90
93
|
let map = this.maps.get(field);
|
|
91
94
|
if (!map || map[unsafe_js_1.unsafeLocal] !== value) {
|
|
92
|
-
this.maps.set(field,
|
|
95
|
+
this.maps.set(field,
|
|
96
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
97
|
+
(map = new ReflectMapImpl(field, value, this.check)));
|
|
93
98
|
}
|
|
94
99
|
return map;
|
|
95
100
|
case "message":
|
|
@@ -412,7 +417,6 @@ function mapKeyToReflect(key, type) {
|
|
|
412
417
|
return key;
|
|
413
418
|
}
|
|
414
419
|
function longToReflect(field, value) {
|
|
415
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
416
420
|
switch (field.scalar) {
|
|
417
421
|
case descriptors_js_1.ScalarType.INT64:
|
|
418
422
|
case descriptors_js_1.ScalarType.SFIXED64:
|
|
@@ -435,7 +439,6 @@ function longToReflect(field, value) {
|
|
|
435
439
|
return value;
|
|
436
440
|
}
|
|
437
441
|
function longToLocal(field, value) {
|
|
438
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
439
442
|
switch (field.scalar) {
|
|
440
443
|
case descriptors_js_1.ScalarType.INT64:
|
|
441
444
|
case descriptors_js_1.ScalarType.SFIXED64:
|
|
@@ -496,7 +499,6 @@ function wktValueToReflect(json) {
|
|
|
496
499
|
$typeName: "google.protobuf.Value",
|
|
497
500
|
kind: { case: undefined },
|
|
498
501
|
};
|
|
499
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- invalid input is unselected kind
|
|
500
502
|
switch (typeof json) {
|
|
501
503
|
case "number":
|
|
502
504
|
value.kind = { case: "numberValue", value: json };
|
|
@@ -42,7 +42,6 @@ function scalarEquals(type, a, b) {
|
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
44
44
|
// Special case 64-bit integers - we support number, string and bigint representation.
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
46
45
|
switch (type) {
|
|
47
46
|
case descriptors_js_1.ScalarType.UINT64:
|
|
48
47
|
case descriptors_js_1.ScalarType.FIXED64:
|
|
@@ -65,10 +64,6 @@ function scalarZeroValue(type, longAsString) {
|
|
|
65
64
|
return "";
|
|
66
65
|
case descriptors_js_1.ScalarType.BOOL:
|
|
67
66
|
return false;
|
|
68
|
-
default:
|
|
69
|
-
// Handles INT32, UINT32, SINT32, FIXED32, SFIXED32.
|
|
70
|
-
// We do not use individual cases to save a few bytes code size.
|
|
71
|
-
return 0;
|
|
72
67
|
case descriptors_js_1.ScalarType.DOUBLE:
|
|
73
68
|
case descriptors_js_1.ScalarType.FLOAT:
|
|
74
69
|
return 0.0;
|
|
@@ -80,6 +75,10 @@ function scalarZeroValue(type, longAsString) {
|
|
|
80
75
|
return (longAsString ? "0" : proto_int64_js_1.protoInt64.zero);
|
|
81
76
|
case descriptors_js_1.ScalarType.BYTES:
|
|
82
77
|
return new Uint8Array(0);
|
|
78
|
+
default:
|
|
79
|
+
// Handles INT32, UINT32, SINT32, FIXED32, SFIXED32.
|
|
80
|
+
// We do not use individual cases to save a few bytes code size.
|
|
81
|
+
return 0;
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
/**
|
|
@@ -5,15 +5,13 @@ export declare const unsafeLocal: unique symbol;
|
|
|
5
5
|
*
|
|
6
6
|
* @private
|
|
7
7
|
*/
|
|
8
|
-
export declare function unsafeOneofCase(target: Record<string, any>,
|
|
9
|
-
oneof: DescOneof): DescField | undefined;
|
|
8
|
+
export declare function unsafeOneofCase(target: Record<string, any>, oneof: DescOneof): DescField | undefined;
|
|
10
9
|
/**
|
|
11
10
|
* Returns true if the field is set.
|
|
12
11
|
*
|
|
13
12
|
* @private
|
|
14
13
|
*/
|
|
15
|
-
export declare function unsafeIsSet(target: Record<string, any>,
|
|
16
|
-
field: DescField): boolean;
|
|
14
|
+
export declare function unsafeIsSet(target: Record<string, any>, field: DescField): boolean;
|
|
17
15
|
/**
|
|
18
16
|
* Returns true if the field is set, but only for singular fields with explicit
|
|
19
17
|
* presence (proto2).
|
|
@@ -38,5 +36,4 @@ export declare function unsafeSet(target: Record<string, unknown>, field: DescFi
|
|
|
38
36
|
*
|
|
39
37
|
* @private
|
|
40
38
|
*/
|
|
41
|
-
export declare function unsafeClear(target: Record<string, any>,
|
|
42
|
-
field: DescField): void;
|
|
39
|
+
export declare function unsafeClear(target: Record<string, any>, field: DescField): void;
|
|
@@ -29,8 +29,9 @@ exports.unsafeLocal = Symbol.for("reflect unsafe local");
|
|
|
29
29
|
*
|
|
30
30
|
* @private
|
|
31
31
|
*/
|
|
32
|
-
function unsafeOneofCase(
|
|
33
|
-
|
|
32
|
+
function unsafeOneofCase(
|
|
33
|
+
// biome-ignore lint/suspicious/noExplicitAny: `any` is the best choice for dynamic access
|
|
34
|
+
target, oneof) {
|
|
34
35
|
const c = target[oneof.localName].case;
|
|
35
36
|
if (c === undefined) {
|
|
36
37
|
return c;
|
|
@@ -42,11 +43,12 @@ oneof) {
|
|
|
42
43
|
*
|
|
43
44
|
* @private
|
|
44
45
|
*/
|
|
45
|
-
function unsafeIsSet(
|
|
46
|
-
|
|
46
|
+
function unsafeIsSet(
|
|
47
|
+
// biome-ignore lint/suspicious/noExplicitAny: `any` is the best choice for dynamic access
|
|
48
|
+
target, field) {
|
|
47
49
|
const name = field.localName;
|
|
48
50
|
if (field.oneof) {
|
|
49
|
-
return target[field.oneof.localName].case === name;
|
|
51
|
+
return target[field.oneof.localName].case === name;
|
|
50
52
|
}
|
|
51
53
|
if (field.presence != IMPLICIT) {
|
|
52
54
|
// Fields with explicit presence have properties on the prototype chain
|
|
@@ -54,12 +56,11 @@ field) {
|
|
|
54
56
|
return (target[name] !== undefined &&
|
|
55
57
|
Object.prototype.hasOwnProperty.call(target, name));
|
|
56
58
|
}
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
58
59
|
switch (field.fieldKind) {
|
|
59
60
|
case "list":
|
|
60
61
|
return target[name].length > 0;
|
|
61
62
|
case "map":
|
|
62
|
-
return Object.keys(target[name]).length > 0;
|
|
63
|
+
return Object.keys(target[name]).length > 0;
|
|
63
64
|
case "scalar":
|
|
64
65
|
return !(0, scalar_js_1.isScalarZeroValue)(field.scalar, target[name]);
|
|
65
66
|
case "enum":
|
|
@@ -113,8 +114,9 @@ function unsafeSet(target, field, value) {
|
|
|
113
114
|
*
|
|
114
115
|
* @private
|
|
115
116
|
*/
|
|
116
|
-
function unsafeClear(
|
|
117
|
-
|
|
117
|
+
function unsafeClear(
|
|
118
|
+
// biome-ignore lint/suspicious/noExplicitAny: `any` is the best choice for dynamic access
|
|
119
|
+
target, field) {
|
|
118
120
|
const name = field.localName;
|
|
119
121
|
if (field.oneof) {
|
|
120
122
|
const oneofLocalName = field.oneof.localName;
|
|
@@ -129,7 +131,6 @@ field) {
|
|
|
129
131
|
delete target[name];
|
|
130
132
|
}
|
|
131
133
|
else {
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
133
134
|
switch (field.fieldKind) {
|
|
134
135
|
case "map":
|
|
135
136
|
target[name] = {};
|