@bufbuild/protobuf 0.0.2-alpha.1 → 0.0.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.
Files changed (67) hide show
  1. package/README.md +5 -2
  2. package/dist/cjs/google/protobuf/any_pb.js +19 -39
  3. package/dist/cjs/google/protobuf/api_pb.js +28 -48
  4. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +32 -67
  5. package/dist/cjs/google/protobuf/descriptor_pb.js +161 -187
  6. package/dist/cjs/google/protobuf/duration_pb.js +21 -41
  7. package/dist/cjs/google/protobuf/empty_pb.js +16 -36
  8. package/dist/cjs/google/protobuf/field_mask_pb.js +17 -37
  9. package/dist/cjs/google/protobuf/source_context_pb.js +16 -36
  10. package/dist/cjs/google/protobuf/struct_pb.js +31 -51
  11. package/dist/cjs/google/protobuf/timestamp_pb.js +20 -40
  12. package/dist/cjs/google/protobuf/type_pb.js +43 -63
  13. package/dist/cjs/google/protobuf/wrappers_pb.js +76 -105
  14. package/dist/cjs/index-runtime.js +42 -0
  15. package/dist/cjs/index-wkt.js +42 -0
  16. package/dist/cjs/index.js +4 -38
  17. package/dist/cjs/private/enum.js +26 -1
  18. package/dist/cjs/private/json-format-common.js +3 -3
  19. package/dist/cjs/private/proto-runtime.js +1 -0
  20. package/dist/cjs/private/util-common.js +1 -1
  21. package/dist/cjs/proto-base64.js +138 -0
  22. package/dist/esm/google/protobuf/any_pb.js +14 -34
  23. package/dist/esm/google/protobuf/api_pb.js +11 -31
  24. package/dist/esm/google/protobuf/compiler/plugin_pb.js +11 -46
  25. package/dist/esm/google/protobuf/descriptor_pb.js +14 -40
  26. package/dist/esm/google/protobuf/duration_pb.js +11 -31
  27. package/dist/esm/google/protobuf/empty_pb.js +11 -31
  28. package/dist/esm/google/protobuf/field_mask_pb.js +11 -31
  29. package/dist/esm/google/protobuf/source_context_pb.js +11 -31
  30. package/dist/esm/google/protobuf/struct_pb.js +11 -31
  31. package/dist/esm/google/protobuf/timestamp_pb.js +11 -31
  32. package/dist/esm/google/protobuf/type_pb.js +11 -31
  33. package/dist/esm/google/protobuf/wrappers_pb.js +11 -40
  34. package/dist/esm/index-runtime.js +25 -0
  35. package/dist/esm/index-wkt.js +26 -0
  36. package/dist/esm/index.js +4 -24
  37. package/dist/esm/private/enum.js +24 -0
  38. package/dist/esm/private/json-format-common.js +3 -3
  39. package/dist/esm/private/proto-runtime.js +2 -1
  40. package/dist/esm/private/util-common.js +1 -1
  41. package/dist/esm/proto-base64.js +135 -0
  42. package/dist/types/google/protobuf/any_pb.d.ts +5 -5
  43. package/dist/types/google/protobuf/api_pb.d.ts +2 -2
  44. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +2 -2
  45. package/dist/types/google/protobuf/descriptor_pb.d.ts +18 -5
  46. package/dist/types/google/protobuf/duration_pb.d.ts +2 -2
  47. package/dist/types/google/protobuf/empty_pb.d.ts +2 -2
  48. package/dist/types/google/protobuf/field_mask_pb.d.ts +2 -2
  49. package/dist/types/google/protobuf/source_context_pb.d.ts +2 -2
  50. package/dist/types/google/protobuf/struct_pb.d.ts +2 -2
  51. package/dist/types/google/protobuf/timestamp_pb.d.ts +2 -2
  52. package/dist/types/google/protobuf/type_pb.d.ts +2 -2
  53. package/dist/types/google/protobuf/wrappers_pb.d.ts +2 -2
  54. package/dist/types/index-runtime.d.ts +19 -0
  55. package/dist/types/index-wkt.d.ts +12 -0
  56. package/dist/types/index.d.ts +2 -30
  57. package/dist/types/message-type.d.ts +2 -1
  58. package/dist/types/message.d.ts +4 -6
  59. package/dist/types/private/enum.d.ts +9 -0
  60. package/dist/types/private/message-type.d.ts +10 -0
  61. package/dist/types/private/proto-runtime.d.ts +16 -11
  62. package/dist/types/private/util.d.ts +2 -2
  63. package/dist/types/proto-base64.d.ts +26 -0
  64. package/package.json +2 -3
  65. package/dist/cjs/private/base64.js +0 -132
  66. package/dist/esm/private/base64.js +0 -127
  67. package/dist/types/private/base64.d.ts +0 -18
@@ -1,37 +1,17 @@
1
- /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
- // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
4
2
  //
5
- // Protocol Buffers - Google's data interchange format
6
- // Copyright 2008 Google Inc. All rights reserved.
7
- // https://developers.google.com/protocol-buffers/
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
8
6
  //
9
- // Redistribution and use in source and binary forms, with or without
10
- // modification, are permitted provided that the following conditions are
11
- // met:
7
+ // http://www.apache.org/licenses/LICENSE-2.0
12
8
  //
13
- // * Redistributions of source code must retain the above copyright
14
- // notice, this list of conditions and the following disclaimer.
15
- // * Redistributions in binary form must reproduce the above
16
- // copyright notice, this list of conditions and the following disclaimer
17
- // in the documentation and/or other materials provided with the
18
- // distribution.
19
- // * Neither the name of Google Inc. nor the names of its
20
- // contributors may be used to endorse or promote products derived from
21
- // this software without specific prior written permission.
22
- //
23
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- import { Message, proto3 } from "../../index.js";
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { Message, proto3 } from "../../index-runtime.js";
35
15
  /**
36
16
  * `NullValue` is a singleton enumeration to represent the null value for the
37
17
  * `Value` type union.
@@ -1,37 +1,17 @@
1
- /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
- // @generated from file google/protobuf/timestamp.proto (package google.protobuf, syntax proto3)
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
4
2
  //
5
- // Protocol Buffers - Google's data interchange format
6
- // Copyright 2008 Google Inc. All rights reserved.
7
- // https://developers.google.com/protocol-buffers/
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
8
6
  //
9
- // Redistribution and use in source and binary forms, with or without
10
- // modification, are permitted provided that the following conditions are
11
- // met:
7
+ // http://www.apache.org/licenses/LICENSE-2.0
12
8
  //
13
- // * Redistributions of source code must retain the above copyright
14
- // notice, this list of conditions and the following disclaimer.
15
- // * Redistributions in binary form must reproduce the above
16
- // copyright notice, this list of conditions and the following disclaimer
17
- // in the documentation and/or other materials provided with the
18
- // distribution.
19
- // * Neither the name of Google Inc. nor the names of its
20
- // contributors may be used to endorse or promote products derived from
21
- // this software without specific prior written permission.
22
- //
23
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- import { Message, proto3, protoInt64 } from "../../index.js";
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { Message, proto3, protoInt64 } from "../../index-runtime.js";
35
15
  /**
36
16
  * A Timestamp represents a point in time independent of any time zone or local
37
17
  * calendar, encoded as a count of seconds and fractions of seconds at
@@ -1,37 +1,17 @@
1
- /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
- // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
4
2
  //
5
- // Protocol Buffers - Google's data interchange format
6
- // Copyright 2008 Google Inc. All rights reserved.
7
- // https://developers.google.com/protocol-buffers/
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
8
6
  //
9
- // Redistribution and use in source and binary forms, with or without
10
- // modification, are permitted provided that the following conditions are
11
- // met:
7
+ // http://www.apache.org/licenses/LICENSE-2.0
12
8
  //
13
- // * Redistributions of source code must retain the above copyright
14
- // notice, this list of conditions and the following disclaimer.
15
- // * Redistributions in binary form must reproduce the above
16
- // copyright notice, this list of conditions and the following disclaimer
17
- // in the documentation and/or other materials provided with the
18
- // distribution.
19
- // * Neither the name of Google Inc. nor the names of its
20
- // contributors may be used to endorse or promote products derived from
21
- // this software without specific prior written permission.
22
- //
23
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- import { Message, proto3 } from "../../index.js";
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { Message, proto3 } from "../../index-runtime.js";
35
15
  import { SourceContext } from "./source_context_pb.js";
36
16
  import { Any } from "./any_pb.js";
37
17
  /**
@@ -1,46 +1,17 @@
1
- /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
- // @generated from file google/protobuf/wrappers.proto (package google.protobuf, syntax proto3)
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
4
2
  //
5
- // Protocol Buffers - Google's data interchange format
6
- // Copyright 2008 Google Inc. All rights reserved.
7
- // https://developers.google.com/protocol-buffers/
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
8
6
  //
9
- // Redistribution and use in source and binary forms, with or without
10
- // modification, are permitted provided that the following conditions are
11
- // met:
7
+ // http://www.apache.org/licenses/LICENSE-2.0
12
8
  //
13
- // * Redistributions of source code must retain the above copyright
14
- // notice, this list of conditions and the following disclaimer.
15
- // * Redistributions in binary form must reproduce the above
16
- // copyright notice, this list of conditions and the following disclaimer
17
- // in the documentation and/or other materials provided with the
18
- // distribution.
19
- // * Neither the name of Google Inc. nor the names of its
20
- // contributors may be used to endorse or promote products derived from
21
- // this software without specific prior written permission.
22
- //
23
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- // Wrappers for primitive (non-message) types. These types are useful
35
- // for embedding primitives in the `google.protobuf.Any` type and for places
36
- // where we need to distinguish between the absence of a primitive
37
- // typed field and its default value.
38
- //
39
- // These wrappers have no meaningful use within repeated fields as they lack
40
- // the ability to detect presence on individual elements.
41
- // These wrappers have no meaningful use within a map or a oneof since
42
- // individual entries of a map or fields of a oneof can already detect presence.
43
- import { Message, ScalarType, proto3, protoInt64 } from "../../index.js";
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { Message, ScalarType, proto3, protoInt64 } from "../../index-runtime.js";
44
15
  /**
45
16
  * Wrapper message for `double`.
46
17
  *
@@ -0,0 +1,25 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ export { proto3 } from "./proto3.js";
15
+ export { proto2 } from "./proto2.js";
16
+ export { protoInt64 } from "./proto-int64.js";
17
+ export { protoBase64 } from "./proto-base64.js";
18
+ export { Message, } from "./message.js";
19
+ export { ScalarType } from "./field.js";
20
+ export { MethodKind, MethodIdempotency } from "./service-type.js";
21
+ export { TypeRegistry } from "./type-registry.js";
22
+ export { DescriptorRegistry } from "./descriptor-registry.js";
23
+ export { DescriptorSet } from "./descriptor-set.js";
24
+ export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
25
+ export {} from "./json-format.js";
@@ -0,0 +1,26 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ // ideally, we would export these types with sub-path exports:
15
+ export * from "./google/protobuf/compiler/plugin_pb.js";
16
+ export * from "./google/protobuf/api_pb.js";
17
+ export * from "./google/protobuf/any_pb.js";
18
+ export * from "./google/protobuf/descriptor_pb.js";
19
+ export * from "./google/protobuf/duration_pb.js";
20
+ export * from "./google/protobuf/empty_pb.js";
21
+ export * from "./google/protobuf/field_mask_pb.js";
22
+ export * from "./google/protobuf/source_context_pb.js";
23
+ export * from "./google/protobuf/struct_pb.js";
24
+ export * from "./google/protobuf/timestamp_pb.js";
25
+ export * from "./google/protobuf/type_pb.js";
26
+ export * from "./google/protobuf/wrappers_pb.js";
package/dist/esm/index.js CHANGED
@@ -11,27 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- export { proto3 } from "./proto3.js";
15
- export { proto2 } from "./proto2.js";
16
- export { protoInt64 } from "./proto-int64.js";
17
- export { Message, } from "./message.js";
18
- export { ScalarType } from "./field.js";
19
- export { MethodKind, MethodIdempotency } from "./service-type.js";
20
- export { TypeRegistry } from "./type-registry.js";
21
- export { DescriptorRegistry } from "./descriptor-registry.js";
22
- export { DescriptorSet } from "./descriptor-set.js";
23
- export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
24
- export {} from "./json-format.js";
25
- // ideally, we would export these types with sub-path exports:
26
- export * from "./google/protobuf/compiler/plugin_pb.js";
27
- export * from "./google/protobuf/api_pb.js";
28
- export * from "./google/protobuf/any_pb.js";
29
- export * from "./google/protobuf/descriptor_pb.js";
30
- export * from "./google/protobuf/duration_pb.js";
31
- export * from "./google/protobuf/empty_pb.js";
32
- export * from "./google/protobuf/field_mask_pb.js";
33
- export * from "./google/protobuf/source_context_pb.js";
34
- export * from "./google/protobuf/struct_pb.js";
35
- export * from "./google/protobuf/timestamp_pb.js";
36
- export * from "./google/protobuf/type_pb.js";
37
- export * from "./google/protobuf/wrappers_pb.js";
14
+ // To avoid circular imports when the wkt import from ./index.js, we
15
+ // use a separate ./index-runtime.js
16
+ export * from "./index-runtime.js";
17
+ export * from "./index-wkt.js";
@@ -70,3 +70,27 @@ export function makeEnumType(typeName, values
70
70
  },
71
71
  };
72
72
  }
73
+ /**
74
+ * Create a new enum object with the given values.
75
+ */
76
+ export function makeEnum(typeName, values, opt) {
77
+ const enumObject = {};
78
+ for (const value of values) {
79
+ const name = makeEnumValueName(value, opt?.sharedPrefix);
80
+ enumObject[name] = value.no;
81
+ enumObject[value.no] = name;
82
+ }
83
+ setEnumType(enumObject, typeName, values);
84
+ return enumObject;
85
+ }
86
+ // Construct a local name for an enum value.
87
+ // This logic matches the Go function with the same name in private/protoplugin/names.go
88
+ function makeEnumValueName(value, sharedPrefix) {
89
+ if (sharedPrefix === undefined) {
90
+ return value.name;
91
+ }
92
+ if (!value.name.startsWith(sharedPrefix)) {
93
+ return value.name;
94
+ }
95
+ return value.name.substring(sharedPrefix.length);
96
+ }
@@ -15,7 +15,7 @@ import { unwrapField, wrapField } from "./field-wrapper.js";
15
15
  import { ScalarType } from "../field.js";
16
16
  import { assert, assertFloat32, assertInt32, assertUInt32 } from "./assert.js";
17
17
  import { protoInt64 } from "../proto-int64.js";
18
- import { base64decode, base64encode } from "./base64.js";
18
+ import { protoBase64 } from "../proto-base64.js";
19
19
  /* eslint-disable no-case-declarations, @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
20
20
  // Default options for parsing JSON.
21
21
  const jsonReadDefaults = {
@@ -363,7 +363,7 @@ function readScalar(type, json) {
363
363
  return new Uint8Array(0);
364
364
  if (typeof json !== "string")
365
365
  break;
366
- return base64decode(json);
366
+ return protoBase64.dec(json);
367
367
  }
368
368
  throw new Error();
369
369
  }
@@ -459,7 +459,7 @@ function writeScalar(type, value, emitIntrinsicDefault) {
459
459
  case ScalarType.BYTES:
460
460
  assert(value instanceof Uint8Array);
461
461
  return emitIntrinsicDefault || value.byteLength > 0
462
- ? base64encode(value)
462
+ ? protoBase64.enc(value)
463
463
  : undefined;
464
464
  }
465
465
  }
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- import { getEnumType, makeEnumType } from "./enum.js";
14
+ import { getEnumType, makeEnum, makeEnumType } from "./enum.js";
15
15
  import { makeMessageType } from "./message-type.js";
16
16
  export function makeProtoRuntime(syntax, json, bin, util) {
17
17
  return {
@@ -22,6 +22,7 @@ export function makeProtoRuntime(syntax, json, bin, util) {
22
22
  makeMessageType(typeName, fields, opt) {
23
23
  return makeMessageType(this, typeName, fields, opt);
24
24
  },
25
+ makeEnum,
25
26
  makeEnumType,
26
27
  getEnumType,
27
28
  };
@@ -78,7 +78,7 @@ export function makeUtilCommon() {
78
78
  t[localName] = val;
79
79
  }
80
80
  else {
81
- t[localName] = val instanceof mt ? mt : new mt(val);
81
+ t[localName] = val instanceof mt ? val : new mt(val);
82
82
  }
83
83
  }
84
84
  break;
@@ -0,0 +1,135 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
15
+ // lookup table from base64 character to byte
16
+ let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
17
+ // lookup table from base64 character *code* to byte because lookup by number is fast
18
+ let decTable = [];
19
+ for (let i = 0; i < encTable.length; i++)
20
+ decTable[encTable[i].charCodeAt(0)] = i;
21
+ // support base64url variants
22
+ decTable["-".charCodeAt(0)] = encTable.indexOf("+");
23
+ decTable["_".charCodeAt(0)] = encTable.indexOf("/");
24
+ export const protoBase64 = {
25
+ /**
26
+ * Decodes a base64 string to a byte array.
27
+ *
28
+ * - ignores white-space, including line breaks and tabs
29
+ * - allows inner padding (can decode concatenated base64 strings)
30
+ * - does not require padding
31
+ * - understands base64url encoding:
32
+ * "-" instead of "+",
33
+ * "_" instead of "/",
34
+ * no padding
35
+ */
36
+ dec(base64Str) {
37
+ // estimate byte size, not accounting for inner padding and whitespace
38
+ let es = (base64Str.length * 3) / 4;
39
+ // if (es % 3 !== 0)
40
+ // throw new Error("invalid base64 string");
41
+ if (base64Str[base64Str.length - 2] == "=")
42
+ es -= 2;
43
+ else if (base64Str[base64Str.length - 1] == "=")
44
+ es -= 1;
45
+ let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
46
+ groupPos = 0, // position in base64 group
47
+ b, // current byte
48
+ p = 0; // previous byte
49
+ for (let i = 0; i < base64Str.length; i++) {
50
+ b = decTable[base64Str.charCodeAt(i)];
51
+ if (b === undefined) {
52
+ switch (base64Str[i]) {
53
+ // @ts-ignore TS7029: Fallthrough case in switch
54
+ case "=":
55
+ groupPos = 0; // reset state when padding found
56
+ // @ts-ignore TS7029: Fallthrough case in switch
57
+ case "\n":
58
+ case "\r":
59
+ case "\t":
60
+ case " ":
61
+ continue; // skip white-space, and padding
62
+ default:
63
+ throw Error("invalid base64 string.");
64
+ }
65
+ }
66
+ switch (groupPos) {
67
+ case 0:
68
+ p = b;
69
+ groupPos = 1;
70
+ break;
71
+ case 1:
72
+ bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
73
+ p = b;
74
+ groupPos = 2;
75
+ break;
76
+ case 2:
77
+ bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
78
+ p = b;
79
+ groupPos = 3;
80
+ break;
81
+ case 3:
82
+ bytes[bytePos++] = ((p & 3) << 6) | b;
83
+ groupPos = 0;
84
+ break;
85
+ }
86
+ }
87
+ if (groupPos == 1)
88
+ throw Error("invalid base64 string.");
89
+ return bytes.subarray(0, bytePos);
90
+ },
91
+ /**
92
+ * Decodes a base64 string to a byte array.
93
+ *
94
+ * - ignores white-space, including line breaks and tabs
95
+ * - allows inner padding (can decode concatenated base64 strings)
96
+ * - does not require padding
97
+ * - understands base64url encoding:
98
+ * "-" instead of "+",
99
+ * "_" instead of "/",
100
+ * no padding
101
+ */
102
+ enc(bytes) {
103
+ let base64 = "", groupPos = 0, // position in base64 group
104
+ b, // current byte
105
+ p = 0; // carry over from previous byte
106
+ for (let i = 0; i < bytes.length; i++) {
107
+ b = bytes[i];
108
+ switch (groupPos) {
109
+ case 0:
110
+ base64 += encTable[b >> 2];
111
+ p = (b & 3) << 4;
112
+ groupPos = 1;
113
+ break;
114
+ case 1:
115
+ base64 += encTable[p | (b >> 4)];
116
+ p = (b & 15) << 2;
117
+ groupPos = 2;
118
+ break;
119
+ case 2:
120
+ base64 += encTable[p | (b >> 6)];
121
+ base64 += encTable[b & 63];
122
+ groupPos = 0;
123
+ break;
124
+ }
125
+ }
126
+ // padding required?
127
+ if (groupPos) {
128
+ base64 += encTable[p];
129
+ base64 += "=";
130
+ if (groupPos == 1)
131
+ base64 += "=";
132
+ }
133
+ return base64;
134
+ },
135
+ };
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, MessageType, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, MessageType, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * `Any` contains an arbitrary serialized protocol buffer message along with a
5
5
  * URL that describes the type of the serialized message.
@@ -26,7 +26,7 @@ import { Message } from "../../index.js";
26
26
  * foo = any.unpack(Foo.class);
27
27
  * }
28
28
  *
29
- * Example 3: Pack and unpack a message in Python.
29
+ * Example 3: Pack and unpack a message in Python.
30
30
  *
31
31
  * foo = Foo(...)
32
32
  * any = Any()
@@ -36,7 +36,7 @@ import { Message } from "../../index.js";
36
36
  * any.Unpack(foo)
37
37
  * ...
38
38
  *
39
- * Example 4: Pack and unpack a message in Go
39
+ * Example 4: Pack and unpack a message in Go
40
40
  *
41
41
  * foo := &pb.Foo{...}
42
42
  * any, err := anypb.New(foo)
@@ -57,7 +57,7 @@ import { Message } from "../../index.js";
57
57
  *
58
58
  *
59
59
  * JSON
60
- * ====
60
+ *
61
61
  * The JSON representation of an `Any` value uses the regular
62
62
  * representation of the deserialized, embedded message, with an
63
63
  * additional field `@type` which contains the type URL. Example:
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  import { Option, Syntax } from "./type_pb.js";
4
4
  import { SourceContext } from "./source_context_pb.js";
5
5
  /**
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../../index.js";
2
- import { Message } from "../../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../../index-runtime.js";
2
+ import { Message } from "../../../index-runtime.js";
3
3
  import { FileDescriptorProto, GeneratedCodeInfo } from "../descriptor_pb.js";
4
4
  /**
5
5
  * The version number of protocol compiler.
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * The protocol compiler can output a FileDescriptorSet containing the .proto
5
5
  * files it parses.
@@ -286,7 +286,6 @@ export declare class FieldDescriptorProto extends Message<FieldDescriptorProto>
286
286
  * For booleans, "true" or "false".
287
287
  * For strings, contains the default text contents (not escaped in any way).
288
288
  * For bytes, contains the C escaped value. All bytes >= 128 are escaped.
289
- * TODO(kenton): Base-64 encode?
290
289
  *
291
290
  * @generated from field: optional string default_value = 7;
292
291
  */
@@ -1020,9 +1019,23 @@ export declare class FieldOptions extends Message<FieldOptions> {
1020
1019
  * check its required fields, regardless of whether or not the message has
1021
1020
  * been parsed.
1022
1021
  *
1022
+ * As of 2021, lazy does no correctness checks on the byte stream during
1023
+ * parsing. This may lead to crashes if and when an invalid byte stream is
1024
+ * finally parsed upon access.
1025
+ *
1026
+ * TODO(b/211906113): Enable validation on lazy fields.
1027
+ *
1023
1028
  * @generated from field: optional bool lazy = 5 [default = false];
1024
1029
  */
1025
1030
  lazy?: boolean;
1031
+ /**
1032
+ * unverified_lazy does no correctness checks on the byte stream. This should
1033
+ * only be used where lazy with verification is prohibitive for performance
1034
+ * reasons.
1035
+ *
1036
+ * @generated from field: optional bool unverified_lazy = 15 [default = false];
1037
+ */
1038
+ unverifiedLazy?: boolean;
1026
1039
  /**
1027
1040
  * Is this field deprecated?
1028
1041
  * Depending on the target platform, this can emit Deprecated annotations
@@ -1413,8 +1426,8 @@ export declare class SourceCodeInfo_Location extends Message<SourceCodeInfo_Loca
1413
1426
  * location.
1414
1427
  *
1415
1428
  * Each element is a field number or an index. They form a path from
1416
- * the root FileDescriptorProto to the place where the definition. For
1417
- * example, this path:
1429
+ * the root FileDescriptorProto to the place where the definition occurs.
1430
+ * For example, this path:
1418
1431
  * [ 4, 3, 2, 7, 1 ]
1419
1432
  * refers to:
1420
1433
  * file.message_type(3) // 4, 3
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * A Duration represents a signed, fixed-length span of time represented
5
5
  * as a count of seconds and fractions of seconds at nanosecond