@bufbuild/protobuf 1.3.2 → 1.4.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.
Files changed (62) hide show
  1. package/dist/cjs/codegen-info.d.ts +1 -1
  2. package/dist/cjs/codegen-info.js +1 -0
  3. package/dist/cjs/create-descriptor-set.js +10 -4
  4. package/dist/cjs/create-registry-from-desc.js +7 -7
  5. package/dist/cjs/descriptor-set.d.ts +21 -1
  6. package/dist/cjs/field.d.ts +52 -1
  7. package/dist/cjs/field.js +29 -1
  8. package/dist/cjs/google/protobuf/any_pb.d.ts +2 -1
  9. package/dist/cjs/google/protobuf/any_pb.js +2 -1
  10. package/dist/cjs/google/protobuf/compiler/plugin_pb.d.ts +18 -1
  11. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +19 -0
  12. package/dist/cjs/google/protobuf/descriptor_pb.d.ts +250 -16
  13. package/dist/cjs/google/protobuf/descriptor_pb.js +241 -7
  14. package/dist/cjs/google/protobuf/duration_pb.js +1 -1
  15. package/dist/cjs/google/protobuf/struct_pb.js +1 -1
  16. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  17. package/dist/cjs/index.d.ts +1 -1
  18. package/dist/cjs/index.js +2 -1
  19. package/dist/cjs/json-format.d.ts +3 -1
  20. package/dist/cjs/private/binary-format-common.d.ts +4 -4
  21. package/dist/cjs/private/binary-format-common.js +18 -6
  22. package/dist/cjs/private/json-format-common.d.ts +1 -1
  23. package/dist/cjs/private/json-format-common.js +11 -7
  24. package/dist/cjs/private/scalars.d.ts +2 -2
  25. package/dist/cjs/private/scalars.js +6 -5
  26. package/dist/cjs/proto2.js +6 -2
  27. package/dist/cjs/proto3.js +6 -3
  28. package/dist/cjs/to-plain-message.d.ts +5 -2
  29. package/dist/cjs/to-plain-message.js +7 -1
  30. package/dist/esm/codegen-info.d.ts +1 -1
  31. package/dist/esm/codegen-info.js +1 -0
  32. package/dist/esm/create-descriptor-set.js +13 -7
  33. package/dist/esm/create-registry-from-desc.js +7 -7
  34. package/dist/esm/descriptor-set.d.ts +21 -1
  35. package/dist/esm/field.d.ts +52 -1
  36. package/dist/esm/field.js +28 -0
  37. package/dist/esm/google/protobuf/any_pb.d.ts +2 -1
  38. package/dist/esm/google/protobuf/any_pb.js +2 -1
  39. package/dist/esm/google/protobuf/compiler/plugin_pb.d.ts +18 -1
  40. package/dist/esm/google/protobuf/compiler/plugin_pb.js +19 -0
  41. package/dist/esm/google/protobuf/descriptor_pb.d.ts +250 -16
  42. package/dist/esm/google/protobuf/descriptor_pb.js +238 -6
  43. package/dist/esm/google/protobuf/duration_pb.js +1 -1
  44. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  45. package/dist/esm/google/protobuf/type_pb.js +1 -1
  46. package/dist/esm/index.d.ts +1 -1
  47. package/dist/esm/index.js +1 -1
  48. package/dist/esm/json-format.d.ts +3 -1
  49. package/dist/esm/json-format.js +1 -1
  50. package/dist/esm/private/binary-format-common.d.ts +4 -4
  51. package/dist/esm/private/binary-format-common.js +17 -6
  52. package/dist/esm/private/json-format-common.d.ts +1 -1
  53. package/dist/esm/private/json-format-common.js +12 -8
  54. package/dist/esm/private/scalars.d.ts +2 -2
  55. package/dist/esm/private/scalars.js +7 -6
  56. package/dist/esm/proto2.js +6 -2
  57. package/dist/esm/proto3.js +7 -4
  58. package/dist/esm/to-plain-message.d.ts +5 -2
  59. package/dist/esm/to-plain-message.js +7 -1
  60. package/dist/proxy/index.d.ts +1 -0
  61. package/dist/proxy/index.js +1 -0
  62. package/package.json +17 -12
@@ -18,6 +18,7 @@ import { InternalFieldList } from "./private/field-list.js";
18
18
  import { InternalOneofInfo } from "./private/field.js";
19
19
  import { localFieldName, fieldJsonName } from "./private/names.js";
20
20
  import { makeJsonFormatProto2 } from "./private/json-format-proto2.js";
21
+ import { LongType } from "./field.js";
21
22
  /**
22
23
  * Provides functionality for messages defined with the proto2 syntax.
23
24
  */
@@ -53,7 +54,7 @@ export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBin
53
54
  } }));
54
55
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
55
56
  function normalizeFieldInfosProto2(fieldInfos) {
56
- var _a, _b, _c;
57
+ var _a, _b, _c, _d;
57
58
  const r = [];
58
59
  let o;
59
60
  for (const field of typeof fieldInfos == "function"
@@ -63,8 +64,11 @@ function normalizeFieldInfosProto2(fieldInfos) {
63
64
  f.localName = localFieldName(field.name, field.oneof !== undefined);
64
65
  f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : fieldJsonName(field.name);
65
66
  f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
67
+ if (field.kind == "scalar") {
68
+ f.L = (_c = field.L) !== null && _c !== void 0 ? _c : LongType.BIGINT;
69
+ }
66
70
  // In contrast to proto3, repeated fields are unpacked except when explicitly specified.
67
- f.packed = (_c = field.packed) !== null && _c !== void 0 ? _c : false;
71
+ f.packed = (_d = field.packed) !== null && _d !== void 0 ? _d : false;
68
72
  // We do not surface options at this time
69
73
  // f.options = field.options ?? emptyReadonlyObject;
70
74
  if (field.oneof !== undefined) {
@@ -17,7 +17,7 @@ import { makeJsonFormatProto3 } from "./private/json-format-proto3.js";
17
17
  import { makeUtilCommon } from "./private/util-common.js";
18
18
  import { InternalFieldList } from "./private/field-list.js";
19
19
  import { scalarDefaultValue } from "./private/scalars.js";
20
- import { ScalarType } from "./field.js";
20
+ import { LongType, ScalarType } from "./field.js";
21
21
  import { InternalOneofInfo } from "./private/field.js";
22
22
  import { localFieldName, fieldJsonName } from "./private/names.js";
23
23
  /**
@@ -47,7 +47,7 @@ export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBin
47
47
  t[name] = {};
48
48
  break;
49
49
  case "scalar":
50
- t[name] = scalarDefaultValue(member.T); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
50
+ t[name] = scalarDefaultValue(member.T, member.L); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
51
51
  break;
52
52
  case "message":
53
53
  // message fields are always optional in proto3
@@ -57,7 +57,7 @@ export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBin
57
57
  } }));
58
58
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
59
59
  function normalizeFieldInfosProto3(fieldInfos) {
60
- var _a, _b, _c;
60
+ var _a, _b, _c, _d;
61
61
  const r = [];
62
62
  let o;
63
63
  for (const field of typeof fieldInfos == "function"
@@ -67,13 +67,16 @@ function normalizeFieldInfosProto3(fieldInfos) {
67
67
  f.localName = localFieldName(field.name, field.oneof !== undefined);
68
68
  f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : fieldJsonName(field.name);
69
69
  f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
70
+ if (field.kind == "scalar") {
71
+ f.L = (_c = field.L) !== null && _c !== void 0 ? _c : LongType.BIGINT;
72
+ }
70
73
  // From the proto3 language guide:
71
74
  // > In proto3, repeated fields of scalar numeric types are packed by default.
72
75
  // This information is incomplete - according to the conformance tests, BOOL
73
76
  // and ENUM are packed by default as well. This means only STRING and BYTES
74
77
  // are not packed by default, which makes sense because they are length-delimited.
75
78
  f.packed =
76
- (_c = field.packed) !== null && _c !== void 0 ? _c : (field.kind == "enum" ||
79
+ (_d = field.packed) !== null && _d !== void 0 ? _d : (field.kind == "enum" ||
77
80
  (field.kind == "scalar" &&
78
81
  field.T != ScalarType.BYTES &&
79
82
  field.T != ScalarType.STRING));
@@ -1,9 +1,12 @@
1
1
  import { Message } from "./message.js";
2
2
  import type { PlainMessage } from "./message.js";
3
3
  /**
4
- * toPlainMessage returns a new object by striping
4
+ * toPlainMessage returns a new object by stripping
5
5
  * all methods from a message, leaving only fields and
6
6
  * oneof groups. It is recursive, meaning it applies this
7
7
  * same logic to all nested message fields as well.
8
+ *
9
+ * If the argument is already a plain message, it is
10
+ * returned as-is.
8
11
  */
9
- export declare function toPlainMessage<T extends Message<T>>(message: T): PlainMessage<T>;
12
+ export declare function toPlainMessage<T extends Message<T>>(message: T | PlainMessage<T>): PlainMessage<T>;
@@ -14,12 +14,18 @@
14
14
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-argument,no-case-declarations */
15
15
  import { Message } from "./message.js";
16
16
  /**
17
- * toPlainMessage returns a new object by striping
17
+ * toPlainMessage returns a new object by stripping
18
18
  * all methods from a message, leaving only fields and
19
19
  * oneof groups. It is recursive, meaning it applies this
20
20
  * same logic to all nested message fields as well.
21
+ *
22
+ * If the argument is already a plain message, it is
23
+ * returned as-is.
21
24
  */
22
25
  export function toPlainMessage(message) {
26
+ if (!(message instanceof Message)) {
27
+ return message;
28
+ }
23
29
  const type = message.getType();
24
30
  const target = {};
25
31
  for (const member of type.fields.byMember()) {
@@ -0,0 +1 @@
1
+ export * from "../cjs/index.js";
@@ -0,0 +1 @@
1
+ export * from "../cjs/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
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": {
@@ -8,26 +8,31 @@
8
8
  "url": "https://github.com/bufbuild/protobuf-es.git",
9
9
  "directory": "packages/protobuf"
10
10
  },
11
- "sideEffects": false,
12
11
  "scripts": {
13
- "clean": "rm -rf ./dist/cjs/* ./dist/esm/*",
14
- "build": "npm run build:cjs && npm run build:esm",
12
+ "clean": "rm -rf ./dist/*",
13
+ "build": "npm run build:cjs && npm run build:esm && npm run build:proxy",
15
14
  "build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
16
15
  "build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
16
+ "build:proxy": "node ../../scripts/gen-esm-proxy.mjs .",
17
+ "prebootstrap": "rm -rf .tmp && mkdir -p .tmp/google/protobuf && cp -rp src/google/protobuf/* .tmp/google/protobuf",
18
+ "bootstrap": "protoc --es_out=src --es_opt=bootstrap_wkt=true,ts_nocheck=false,target=ts --proto_path $(upstream-include wkt) $(upstream-files wkt)",
19
+ "postbootstrap": "license-header src/google/protobuf",
20
+ "bootstrap-diff": "diff >/dev/null -r .tmp/google/protobuf src/google/protobuf && cp -rp .tmp/google/protobuf/* src/google/protobuf",
17
21
  "attw": "attw --pack"
18
22
  },
19
- "main": "./dist/cjs/index.js",
20
23
  "type": "module",
24
+ "sideEffects": false,
25
+ "main": "./dist/cjs/index.js",
21
26
  "exports": {
22
- "import": {
23
- "types": "./dist/esm/index.d.ts",
24
- "default": "./dist/esm/index.js"
25
- },
26
- "require": {
27
- "types": "./dist/cjs/index.d.ts",
28
- "default": "./dist/cjs/index.js"
27
+ ".": {
28
+ "module": "./dist/esm/index.js",
29
+ "require": "./dist/cjs/index.js",
30
+ "import": "./dist/proxy/index.js"
29
31
  }
30
32
  },
33
+ "devDependencies": {
34
+ "upstream-protobuf": "*"
35
+ },
31
36
  "files": [
32
37
  "dist/**"
33
38
  ]