@bufbuild/protobuf 0.0.2-alpha.1 → 0.0.2-alpha.2

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 (32) hide show
  1. package/dist/cjs/google/protobuf/any_pb.js +1 -1
  2. package/dist/cjs/google/protobuf/api_pb.js +1 -1
  3. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +1 -1
  4. package/dist/cjs/google/protobuf/descriptor_pb.js +1 -1
  5. package/dist/cjs/google/protobuf/duration_pb.js +1 -1
  6. package/dist/cjs/google/protobuf/empty_pb.js +1 -1
  7. package/dist/cjs/google/protobuf/field_mask_pb.js +1 -1
  8. package/dist/cjs/google/protobuf/source_context_pb.js +1 -1
  9. package/dist/cjs/google/protobuf/struct_pb.js +1 -1
  10. package/dist/cjs/google/protobuf/timestamp_pb.js +1 -1
  11. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  12. package/dist/cjs/google/protobuf/wrappers_pb.js +1 -1
  13. package/dist/cjs/private/enum.js +26 -1
  14. package/dist/cjs/private/proto-runtime.js +1 -0
  15. package/dist/esm/google/protobuf/any_pb.js +1 -1
  16. package/dist/esm/google/protobuf/api_pb.js +1 -1
  17. package/dist/esm/google/protobuf/compiler/plugin_pb.js +1 -1
  18. package/dist/esm/google/protobuf/descriptor_pb.js +1 -1
  19. package/dist/esm/google/protobuf/duration_pb.js +1 -1
  20. package/dist/esm/google/protobuf/empty_pb.js +1 -1
  21. package/dist/esm/google/protobuf/field_mask_pb.js +1 -1
  22. package/dist/esm/google/protobuf/source_context_pb.js +1 -1
  23. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  24. package/dist/esm/google/protobuf/timestamp_pb.js +1 -1
  25. package/dist/esm/google/protobuf/type_pb.js +1 -1
  26. package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
  27. package/dist/esm/private/enum.js +24 -0
  28. package/dist/esm/private/proto-runtime.js +2 -1
  29. package/dist/types/private/enum.d.ts +9 -0
  30. package/dist/types/private/message-type.d.ts +10 -0
  31. package/dist/types/private/proto-runtime.d.ts +16 -11
  32. package/package.json +2 -3
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/any.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/api.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/compiler/plugin.proto (package google.protobuf.compiler, syntax proto2)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/duration.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/empty.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/field_mask.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/source_context.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/timestamp.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
3
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
4
4
  // @generated from file google/protobuf/wrappers.proto (package google.protobuf, syntax proto3)
5
5
  //
6
6
  // Protocol Buffers - Google's data interchange format
@@ -13,7 +13,7 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.makeEnumType = exports.setEnumType = exports.getEnumType = void 0;
16
+ exports.makeEnum = exports.makeEnumType = exports.setEnumType = exports.getEnumType = void 0;
17
17
  const assert_js_1 = require("./assert.js");
18
18
  const enumTypeSymbol = Symbol("@bufbuild/protobuf/enum-type");
19
19
  /**
@@ -76,3 +76,28 @@ function makeEnumType(typeName, values
76
76
  };
77
77
  }
78
78
  exports.makeEnumType = makeEnumType;
79
+ /**
80
+ * Create a new enum object with the given values.
81
+ */
82
+ function makeEnum(typeName, values, opt) {
83
+ const enumObject = {};
84
+ for (const value of values) {
85
+ const name = makeEnumValueName(value, opt?.sharedPrefix);
86
+ enumObject[name] = value.no;
87
+ enumObject[value.no] = name;
88
+ }
89
+ setEnumType(enumObject, typeName, values);
90
+ return enumObject;
91
+ }
92
+ exports.makeEnum = makeEnum;
93
+ // Construct a local name for an enum value.
94
+ // This logic matches the Go function with the same name in private/protoplugin/names.go
95
+ function makeEnumValueName(value, sharedPrefix) {
96
+ if (sharedPrefix === undefined) {
97
+ return value.name;
98
+ }
99
+ if (!value.name.startsWith(sharedPrefix)) {
100
+ return value.name;
101
+ }
102
+ return value.name.substring(sharedPrefix.length);
103
+ }
@@ -25,6 +25,7 @@ function makeProtoRuntime(syntax, json, bin, util) {
25
25
  makeMessageType(typeName, fields, opt) {
26
26
  return (0, message_type_js_1.makeMessageType)(this, typeName, fields, opt);
27
27
  },
28
+ makeEnum: enum_js_1.makeEnum,
28
29
  makeEnumType: enum_js_1.makeEnumType,
29
30
  getEnumType: enum_js_1.getEnumType,
30
31
  };
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/any.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/api.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/compiler/plugin.proto (package google.protobuf.compiler, syntax proto2)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/duration.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/empty.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/field_mask.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/source_context.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/timestamp.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable */
2
- // @generated by protoc-gen-es v0.0.2-alpha.1 with parameter "bootstrap_wkt=true,ts_nocheck=false"
2
+ // @generated by protoc-gen-es v0.0.2-alpha.2 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
3
3
  // @generated from file google/protobuf/wrappers.proto (package google.protobuf, syntax proto3)
4
4
  //
5
5
  // Protocol Buffers - Google's data interchange format
@@ -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
+ }
@@ -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
  };
@@ -20,3 +20,12 @@ export declare function setEnumType(enumObject: EnumObject, typeName: string, va
20
20
  * Create a new EnumType with the given values.
21
21
  */
22
22
  export declare function makeEnumType(typeName: string, values: EnumValueInfo[]): EnumType;
23
+ /**
24
+ * Create a new enum object with the given values.
25
+ */
26
+ export declare function makeEnum(typeName: string, values: EnumValueInfo[], opt?: {
27
+ /**
28
+ * MY_ENUM_ for `enum MyEnum {MY_ENUM_A=0; MY_ENUM_B=1;}`, or blank string
29
+ */
30
+ sharedPrefix?: string;
31
+ }): EnumObject;
@@ -6,5 +6,15 @@ import type { ProtoRuntime } from "./proto-runtime.js";
6
6
  * Create a new message type using the given runtime.
7
7
  */
8
8
  export declare function makeMessageType<T extends Message<T> = AnyMessage>(runtime: ProtoRuntime, typeName: string, fields: FieldListSource, opt?: {
9
+ /**
10
+ * localName is the "name" property of the constructed function.
11
+ * It is useful in stack traces, debuggers and test frameworks,
12
+ * but has no other implications.
13
+ *
14
+ * This property is optional because by default, the last part
15
+ * from the given typeName is used. Since this does not take
16
+ * reserved words into account, we provide this property so that
17
+ * an escaped name can be given.
18
+ */
9
19
  localName?: string;
10
20
  }): MessageType<T>;
@@ -1,4 +1,4 @@
1
- import type { JsonFormat, JsonValue } from "../json-format.js";
1
+ import type { JsonFormat } from "../json-format.js";
2
2
  import type { BinaryFormat } from "../binary-format.js";
3
3
  import type { AnyMessage } from "../message.js";
4
4
  import type { Message } from "../message.js";
@@ -20,22 +20,27 @@ export interface ProtoRuntime {
20
20
  */
21
21
  makeMessageType<T extends Message<T> = AnyMessage>(typeName: string, fields: FieldListSource, opt?: {
22
22
  localName?: string;
23
- options?: {
24
- readonly [extensionName: string]: JsonValue;
25
- };
26
23
  }): MessageType<T>;
24
+ /**
25
+ * Create an enum object at runtime, without generating code.
26
+ *
27
+ * The object conforms to TypeScript enums, and comes with
28
+ * mapping from name to value, and from value to name.
29
+ *
30
+ * The type name and other reflection information is accessible
31
+ * via getEnumType().
32
+ */
33
+ makeEnum(typeName: string, values: EnumValueInfo[], opt?: {}): EnumObject;
27
34
  /**
28
35
  * Create an enum type at runtime, without generating code.
36
+ * Note that this only creates the reflection information, not an
37
+ * actual enum object.
29
38
  */
30
- makeEnumType(typeName: string, values: EnumValueInfo[], opt?: {
31
- options?: {
32
- readonly [extensionName: string]: JsonValue;
33
- };
34
- }): EnumType;
39
+ makeEnumType(typeName: string, values: EnumValueInfo[], opt?: {}): EnumType;
35
40
  /**
36
- * Get reflection information from a generated enum.
41
+ * Get reflection information - the EnumType - from an enum object.
37
42
  * If this function is called on something other than a generated
38
- * enum, it raises an error.
43
+ * enum, or an enum constructed with makeEnum(), it raises an error.
39
44
  */
40
45
  getEnumType(enumObject: EnumObject): EnumType;
41
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "0.0.2-alpha.1",
3
+ "version": "0.0.2-alpha.2",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "A complete implementation of protocol buffers in TypeScript, suitable for web browsers and Node.js.",
6
6
  "repository": {
@@ -15,7 +15,6 @@
15
15
  "build:esm+types": "npx tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
16
16
  },
17
17
  "type": "module",
18
- "main": "./dist/cjs/index.js",
19
18
  "types": "./dist/types/index.d.ts",
20
19
  "exports": {
21
20
  "import": "./dist/esm/index.js",
@@ -23,7 +22,7 @@
23
22
  "default": "./dist/esm/index.js"
24
23
  },
25
24
  "devDependencies": {
26
- "typescript": "^4.5.4"
25
+ "typescript": "^4.6.3"
27
26
  },
28
27
  "files": [
29
28
  "dist/**/"