@bufbuild/protobuf 0.0.1 → 0.0.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +1 -21
  2. package/dist/cjs/binary-encoding.js +21 -8
  3. package/dist/cjs/binary-format.js +13 -0
  4. package/dist/cjs/descriptor-registry.js +13 -0
  5. package/dist/cjs/descriptor-set.js +13 -0
  6. package/dist/cjs/enum.js +13 -0
  7. package/dist/cjs/field-list.js +13 -0
  8. package/dist/cjs/field.js +13 -0
  9. package/dist/cjs/google/protobuf/any_pb.js +1 -1
  10. package/dist/cjs/google/protobuf/api_pb.js +1 -1
  11. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +1 -1
  12. package/dist/cjs/google/protobuf/descriptor_pb.js +1 -1
  13. package/dist/cjs/google/protobuf/duration_pb.js +1 -1
  14. package/dist/cjs/google/protobuf/empty_pb.js +1 -1
  15. package/dist/cjs/google/protobuf/field_mask_pb.js +1 -1
  16. package/dist/cjs/google/protobuf/source_context_pb.js +1 -1
  17. package/dist/cjs/google/protobuf/struct_pb.js +1 -1
  18. package/dist/cjs/google/protobuf/timestamp_pb.js +1 -1
  19. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  20. package/dist/cjs/google/protobuf/wrappers_pb.js +1 -1
  21. package/dist/cjs/{private/goog-varint.js → google/varint.js} +0 -0
  22. package/dist/cjs/index.js +18 -1
  23. package/dist/cjs/json-format.js +13 -0
  24. package/dist/cjs/message-type.js +13 -0
  25. package/dist/cjs/message.js +18 -6
  26. package/dist/cjs/private/assert.js +13 -0
  27. package/dist/cjs/private/base64.js +14 -1
  28. package/dist/cjs/private/binary-format-common.js +13 -0
  29. package/dist/cjs/private/binary-format-proto2.js +13 -0
  30. package/dist/cjs/private/binary-format-proto3.js +13 -0
  31. package/dist/cjs/private/enum.js +13 -0
  32. package/dist/cjs/private/field-list.js +13 -0
  33. package/dist/cjs/private/field-wrapper.js +13 -0
  34. package/dist/cjs/private/field.js +13 -0
  35. package/dist/cjs/private/json-format-common.js +13 -0
  36. package/dist/cjs/private/json-format-proto2.js +13 -0
  37. package/dist/cjs/private/json-format-proto3.js +13 -0
  38. package/dist/cjs/private/message-type.js +13 -0
  39. package/dist/cjs/private/names.js +13 -0
  40. package/dist/cjs/private/options-map.js +13 -0
  41. package/dist/cjs/private/proto-runtime.js +13 -0
  42. package/dist/cjs/private/scalars.js +13 -0
  43. package/dist/cjs/private/util-common.js +16 -3
  44. package/dist/cjs/private/util.js +13 -0
  45. package/dist/cjs/proto-int64.js +19 -6
  46. package/dist/cjs/proto2.js +13 -0
  47. package/dist/cjs/proto3.js +13 -0
  48. package/dist/cjs/service-type.js +13 -0
  49. package/dist/cjs/type-registry.js +13 -0
  50. package/dist/esm/binary-encoding.js +14 -1
  51. package/dist/esm/binary-format.js +13 -0
  52. package/dist/esm/descriptor-registry.js +13 -0
  53. package/dist/esm/descriptor-set.js +13 -0
  54. package/dist/esm/enum.js +13 -0
  55. package/dist/esm/field-list.js +13 -0
  56. package/dist/esm/field.js +13 -0
  57. package/dist/esm/google/protobuf/any_pb.js +1 -1
  58. package/dist/esm/google/protobuf/api_pb.js +1 -1
  59. package/dist/esm/google/protobuf/compiler/plugin_pb.js +1 -1
  60. package/dist/esm/google/protobuf/descriptor_pb.js +1 -1
  61. package/dist/esm/google/protobuf/duration_pb.js +1 -1
  62. package/dist/esm/google/protobuf/empty_pb.js +1 -1
  63. package/dist/esm/google/protobuf/field_mask_pb.js +1 -1
  64. package/dist/esm/google/protobuf/source_context_pb.js +1 -1
  65. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  66. package/dist/esm/google/protobuf/timestamp_pb.js +1 -1
  67. package/dist/esm/google/protobuf/type_pb.js +1 -1
  68. package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
  69. package/dist/esm/{private/goog-varint.js → google/varint.js} +0 -0
  70. package/dist/esm/index.js +13 -0
  71. package/dist/esm/json-format.js +13 -0
  72. package/dist/esm/message-type.js +13 -0
  73. package/dist/esm/message.js +18 -6
  74. package/dist/esm/private/assert.js +13 -0
  75. package/dist/esm/private/base64.js +13 -0
  76. package/dist/esm/private/binary-format-common.js +13 -0
  77. package/dist/esm/private/binary-format-proto2.js +13 -0
  78. package/dist/esm/private/binary-format-proto3.js +13 -0
  79. package/dist/esm/private/enum.js +13 -0
  80. package/dist/esm/private/field-list.js +13 -0
  81. package/dist/esm/private/field-wrapper.js +13 -0
  82. package/dist/esm/private/field.js +13 -0
  83. package/dist/esm/private/json-format-common.js +13 -0
  84. package/dist/esm/private/json-format-proto2.js +13 -0
  85. package/dist/esm/private/json-format-proto3.js +13 -0
  86. package/dist/esm/private/message-type.js +13 -0
  87. package/dist/esm/private/names.js +13 -0
  88. package/dist/esm/private/options-map.js +13 -0
  89. package/dist/esm/private/proto-runtime.js +13 -0
  90. package/dist/esm/private/scalars.js +13 -0
  91. package/dist/esm/private/util-common.js +16 -3
  92. package/dist/esm/private/util.js +13 -0
  93. package/dist/esm/proto-int64.js +14 -1
  94. package/dist/esm/proto2.js +13 -0
  95. package/dist/esm/proto3.js +13 -0
  96. package/dist/esm/service-type.js +13 -0
  97. package/dist/esm/type-registry.js +13 -0
  98. package/dist/types/{private/goog-varint.d.ts → google/varint.d.ts} +0 -0
  99. package/dist/types/index.d.ts +1 -1
  100. package/dist/types/json-format.d.ts +1 -1
  101. package/dist/types/message-type.d.ts +2 -2
  102. package/dist/types/message.d.ts +13 -12
  103. package/dist/types/private/field-wrapper.d.ts +3 -3
  104. package/dist/types/private/message-type.d.ts +2 -2
  105. package/dist/types/private/proto-runtime.d.ts +2 -2
  106. package/dist/types/private/util.d.ts +3 -3
  107. package/dist/types/service-type.d.ts +7 -7
  108. package/package.json +2 -2
@@ -1,23 +1,35 @@
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.
1
14
  /**
2
- * Every message - generated or created at runtime - is an instance of this
3
- * class.
15
+ * Message is the base class of every message, generated, or created at
16
+ * runtime.
4
17
  *
5
- * It is unsafe to extend this class. If you want to create a message at run
6
- * time, use proto3.makeMessageType().
18
+ * It is _not_ safe to extend this class. If you want to create a message at
19
+ * run time, use proto3.makeMessageType().
7
20
  */
8
21
  export class Message {
9
- // TODO find better name to prevent field name conflicts?
10
22
  /**
11
23
  * Compare with a message of the same type.
12
24
  */
13
25
  equals(other) {
14
26
  return this.getType().runtime.util.equals(this.getType(), this, other);
15
27
  }
16
- // TODO find better name to prevent field name conflicts?
17
28
  /**
18
29
  * Create a deep copy.
19
30
  */
20
31
  clone() {
32
+ // return this.getType().runtime.util.clone(this);
21
33
  return this.getType().runtime.util.clone(this);
22
34
  }
23
35
  /**
@@ -1,3 +1,16 @@
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.
1
14
  /**
2
15
  * Assert that condition is truthy or throw error (with message)
3
16
  */
@@ -1,3 +1,16 @@
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.
1
14
  /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
2
15
  // lookup table from base64 character to byte
3
16
  let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
@@ -1,3 +1,16 @@
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.
1
14
  import { BinaryReader, BinaryWriter, WireType, } from "../binary-encoding.js";
2
15
  import { ScalarType } from "../field.js";
3
16
  import { unwrapField, wrapField } from "./field-wrapper.js";
@@ -1,3 +1,16 @@
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.
1
14
  import { ScalarType } from "../field.js";
2
15
  import { makeBinaryFormatCommon, writeMapEntry, writeMessageField, writePacked, writeScalar, } from "./binary-format-common.js";
3
16
  /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, no-case-declarations, prefer-const */
@@ -1,3 +1,16 @@
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.
1
14
  import { ScalarType } from "../field.js";
2
15
  import { makeBinaryFormatCommon, writeMapEntry, writeMessageField, writePacked, writeScalar, } from "./binary-format-common.js";
3
16
  /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, prefer-const, no-case-declarations */
@@ -1,3 +1,16 @@
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.
1
14
  import { assert } from "./assert.js";
2
15
  const enumTypeSymbol = Symbol("@bufbuild/protobuf/enum-type");
3
16
  /**
@@ -1,3 +1,16 @@
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.
1
14
  export class InternalFieldList {
2
15
  constructor(fields, normalizer) {
3
16
  this._fields = fields;
@@ -1,3 +1,16 @@
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.
1
14
  /**
2
15
  * Wrap field values whose message type has a wrapper.
3
16
  */
@@ -1,3 +1,16 @@
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.
1
14
  import { makeOneofName } from "./names.js";
2
15
  import { assert } from "./assert.js";
3
16
  export class InternalOneofInfo {
@@ -1,3 +1,16 @@
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.
1
14
  import { unwrapField, wrapField } from "./field-wrapper.js";
2
15
  import { ScalarType } from "../field.js";
3
16
  import { assert, assertFloat32, assertInt32, assertUInt32 } from "./assert.js";
@@ -1,3 +1,16 @@
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.
1
14
  import { wrapField } from "./field-wrapper.js";
2
15
  import { assert } from "./assert.js";
3
16
  import { makeJsonFormatCommon } from "./json-format-common.js";
@@ -1,3 +1,16 @@
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.
1
14
  import { wrapField } from "./field-wrapper.js";
2
15
  import { assert } from "./assert.js";
3
16
  import { makeJsonFormatCommon } from "./json-format-common.js";
@@ -1,3 +1,16 @@
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.
1
14
  import { Message, } from "../message.js";
2
15
  /**
3
16
  * Create a new message type using the given runtime.
@@ -1,3 +1,16 @@
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.
1
14
  /**
2
15
  * Returns the JSON name for a protobuf field, exactly like protoc does.
3
16
  */
@@ -1 +1,14 @@
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.
1
14
  export {};
@@ -1,3 +1,16 @@
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.
1
14
  import { getEnumType, makeEnumType } from "./enum.js";
2
15
  import { makeMessageType } from "./message-type.js";
3
16
  export function makeProtoRuntime(syntax, json, bin, util) {
@@ -1,3 +1,16 @@
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.
1
14
  import { ScalarType } from "../field.js";
2
15
  import { WireType } from "../binary-encoding.js";
3
16
  import { protoInt64 } from "../proto-int64.js";
@@ -1,3 +1,16 @@
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.
1
14
  import { setEnumType } from "./enum.js";
2
15
  import { ScalarType } from "../field.js";
3
16
  import { scalarEquals } from "./scalars.js";
@@ -142,7 +155,7 @@ export function makeUtilCommon() {
142
155
  });
143
156
  },
144
157
  clone(message) {
145
- const type = message.getType(), target = new type();
158
+ const type = message.getType(), target = new type(), any = target;
146
159
  for (const member of type.fields.byMember()) {
147
160
  const source = message[member.localName];
148
161
  let copy;
@@ -150,7 +163,7 @@ export function makeUtilCommon() {
150
163
  copy = source.map((e) => cloneSingularField(member, e));
151
164
  }
152
165
  else if (member.kind == "map") {
153
- copy = target[member.localName];
166
+ copy = any[member.localName];
154
167
  for (const [key, v] of Object.entries(source)) {
155
168
  copy[key] = cloneSingularField(member.V, v);
156
169
  }
@@ -164,7 +177,7 @@ export function makeUtilCommon() {
164
177
  else {
165
178
  copy = cloneSingularField(member, source);
166
179
  }
167
- target[member.localName] = copy;
180
+ any[member.localName] = copy;
168
181
  }
169
182
  return target;
170
183
  },
@@ -1 +1,14 @@
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.
1
14
  export {};
@@ -1,4 +1,17 @@
1
- import { int64fromString, int64toString } from "./private/goog-varint.js";
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
+ import { int64fromString, int64toString } from "./google/varint.js";
2
15
  function makeInt64Support() {
3
16
  const dv = new DataView(new ArrayBuffer(8));
4
17
  // note that Safari 14 implements BigInt, but not the DataView methods
@@ -1,3 +1,16 @@
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.
1
14
  import { makeProtoRuntime } from "./private/proto-runtime.js";
2
15
  import { makeBinaryFormatProto2 } from "./private/binary-format-proto2.js";
3
16
  import { makeUtilCommon } from "./private/util-common.js";
@@ -1,3 +1,16 @@
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.
1
14
  import { makeProtoRuntime } from "./private/proto-runtime.js";
2
15
  import { makeBinaryFormatProto3 } from "./private/binary-format-proto3.js";
3
16
  import { makeJsonFormatProto3 } from "./private/json-format-proto3.js";
@@ -1,3 +1,16 @@
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.
1
14
  /**
2
15
  * MethodKind represents the four method types that can be declared in
3
16
  * protobuf with the `stream` keyword:
@@ -1,3 +1,16 @@
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.
1
14
  /**
2
15
  * TypeRegistry is a basic type registry
3
16
  */
@@ -1,7 +1,7 @@
1
1
  export { proto3 } from "./proto3.js";
2
2
  export { proto2 } from "./proto2.js";
3
3
  export { protoInt64 } from "./proto-int64.js";
4
- export { Message, DynamicMessage, PartialMessage, PlainMessage, } from "./message.js";
4
+ export { Message, AnyMessage, PartialMessage, PlainMessage, } from "./message.js";
5
5
  export type { FieldInfo } from "./field.js";
6
6
  export type { FieldList } from "./field-list.js";
7
7
  export { ScalarType } from "./field.js";
@@ -19,7 +19,7 @@ export interface JsonFormat {
19
19
  /**
20
20
  * Parse a message from JSON.
21
21
  */
22
- readMessage<T extends Message>(type: MessageType<T>, jsonValue: JsonValue, options: JsonReadOptions, message?: T): T;
22
+ readMessage<T extends Message<T>>(type: MessageType<T>, jsonValue: JsonValue, options: JsonReadOptions, message?: T): T;
23
23
  /**
24
24
  * Serialize a message to JSON.
25
25
  */
@@ -2,7 +2,7 @@ import type { FieldList } from "./field-list.js";
2
2
  import type { ProtoRuntime } from "./private/proto-runtime.js";
3
3
  import type { JsonReadOptions, JsonValue } from "./json-format.js";
4
4
  import type { BinaryReadOptions } from "./binary-format.js";
5
- import type { DynamicMessage, Message, PartialMessage, PlainMessage } from "./message.js";
5
+ import type { AnyMessage, Message, PartialMessage, PlainMessage } from "./message.js";
6
6
  import type { FieldWrapper } from "./private/field-wrapper.js";
7
7
  /**
8
8
  * MessageType represents a protobuf message. It provides:
@@ -10,7 +10,7 @@ import type { FieldWrapper } from "./private/field-wrapper.js";
10
10
  * - metadata for reflection-based operations
11
11
  * - common functionality like serialization
12
12
  */
13
- export interface MessageType<T extends Message = DynamicMessage> {
13
+ export interface MessageType<T extends Message<T> = AnyMessage> {
14
14
  /**
15
15
  * Create a new instance of this type.
16
16
  */
@@ -2,13 +2,21 @@ import type { BinaryReadOptions, BinaryWriteOptions } from "./binary-format.js";
2
2
  import type { JsonReadOptions, JsonValue, JsonWriteOptions, JsonWriteStringOptions } from "./json-format.js";
3
3
  import type { MessageType } from "./message-type.js";
4
4
  /**
5
- * Every message - generated or created at runtime - is an instance of this
6
- * class.
5
+ * AnyMessage is an interface implemented by all messages. If you need to
6
+ * handle messages of unknown type, this interface provides a convenient
7
+ * index signature to access fields with message["fieldname"].
8
+ */
9
+ export interface AnyMessage extends Message<AnyMessage> {
10
+ [k: string]: any;
11
+ }
12
+ /**
13
+ * Message is the base class of every message, generated, or created at
14
+ * runtime.
7
15
  *
8
- * It is unsafe to extend this class. If you want to create a message at run
9
- * time, use proto3.makeMessageType().
16
+ * It is _not_ safe to extend this class. If you want to create a message at
17
+ * run time, use proto3.makeMessageType().
10
18
  */
11
- export declare class Message<T extends Message = DynamicMessage> {
19
+ export declare class Message<T extends Message<T> = AnyMessage> {
12
20
  /**
13
21
  * Compare with a message of the same type.
14
22
  */
@@ -88,11 +96,4 @@ declare type OneofSelectedMessage<K extends string, M extends Message> = {
88
96
  case: K;
89
97
  value: M;
90
98
  };
91
- /**
92
- * DynamicMessage exposes the fields of the message with an index signature,
93
- * which means that fields can be accessed with message["fieldname"].
94
- */
95
- export declare type DynamicMessage = Message & {
96
- [k: string]: any;
97
- };
98
99
  export {};
@@ -7,15 +7,15 @@ import type { MessageType } from "../message-type.js";
7
7
  * Note that this feature exists for google/protobuf/{wrappers,struct}.proto
8
8
  * and cannot be used to arbitrarily modify types in generated code.
9
9
  */
10
- export interface FieldWrapper<T extends Message = any, U = any> {
10
+ export interface FieldWrapper<T extends Message<T> = any, U = any> {
11
11
  wrapField(value: U): T;
12
12
  unwrapField(value: T): U;
13
13
  }
14
14
  /**
15
15
  * Wrap field values whose message type has a wrapper.
16
16
  */
17
- export declare function wrapField<T extends Message>(type: MessageType<T>, value: any): T;
17
+ export declare function wrapField<T extends Message<T>>(type: MessageType<T>, value: any): T;
18
18
  /**
19
19
  * Unwrap field values whose message type has a wrapper.
20
20
  */
21
- export declare function unwrapField<T extends Message>(type: MessageType<T>, value: T): any;
21
+ export declare function unwrapField<T extends Message<T>>(type: MessageType<T>, value: T): any;
@@ -1,10 +1,10 @@
1
- import { DynamicMessage, Message } from "../message.js";
1
+ import { AnyMessage, Message } from "../message.js";
2
2
  import type { FieldListSource } from "./field-list.js";
3
3
  import type { MessageType } from "../message-type.js";
4
4
  import type { ProtoRuntime } from "./proto-runtime.js";
5
5
  /**
6
6
  * Create a new message type using the given runtime.
7
7
  */
8
- export declare function makeMessageType<T extends Message = DynamicMessage>(runtime: ProtoRuntime, typeName: string, fields: FieldListSource, opt?: {
8
+ export declare function makeMessageType<T extends Message<T> = AnyMessage>(runtime: ProtoRuntime, typeName: string, fields: FieldListSource, opt?: {
9
9
  localName?: string;
10
10
  }): MessageType<T>;
@@ -1,6 +1,6 @@
1
1
  import type { JsonFormat, JsonValue } from "../json-format.js";
2
2
  import type { BinaryFormat } from "../binary-format.js";
3
- import type { DynamicMessage } from "../message.js";
3
+ import type { AnyMessage } from "../message.js";
4
4
  import type { Message } from "../message.js";
5
5
  import type { EnumType, EnumValueInfo } from "../enum.js";
6
6
  import type { MessageType } from "../message-type.js";
@@ -18,7 +18,7 @@ export interface ProtoRuntime {
18
18
  /**
19
19
  * Create a message type at runtime, without generating code.
20
20
  */
21
- makeMessageType<T extends Message = DynamicMessage>(typeName: string, fields: FieldListSource, opt?: {
21
+ makeMessageType<T extends Message<T> = AnyMessage>(typeName: string, fields: FieldListSource, opt?: {
22
22
  localName?: string;
23
23
  options?: {
24
24
  readonly [extensionName: string]: JsonValue;