@bufbuild/protobuf 0.0.2-alpha.2 → 0.0.2-alpha.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 (41) hide show
  1. package/dist/cjs/google/protobuf/any_pb.js +13 -33
  2. package/dist/cjs/google/protobuf/api_pb.js +10 -30
  3. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +10 -45
  4. package/dist/cjs/google/protobuf/descriptor_pb.js +13 -39
  5. package/dist/cjs/google/protobuf/duration_pb.js +10 -30
  6. package/dist/cjs/google/protobuf/empty_pb.js +10 -30
  7. package/dist/cjs/google/protobuf/field_mask_pb.js +10 -30
  8. package/dist/cjs/google/protobuf/source_context_pb.js +10 -30
  9. package/dist/cjs/google/protobuf/struct_pb.js +10 -30
  10. package/dist/cjs/google/protobuf/timestamp_pb.js +10 -30
  11. package/dist/cjs/google/protobuf/type_pb.js +10 -30
  12. package/dist/cjs/google/protobuf/wrappers_pb.js +10 -39
  13. package/dist/cjs/index.js +3 -1
  14. package/dist/cjs/private/json-format-common.js +3 -3
  15. package/dist/cjs/proto-base64.js +138 -0
  16. package/dist/esm/google/protobuf/any_pb.js +13 -33
  17. package/dist/esm/google/protobuf/api_pb.js +10 -30
  18. package/dist/esm/google/protobuf/compiler/plugin_pb.js +10 -45
  19. package/dist/esm/google/protobuf/descriptor_pb.js +13 -39
  20. package/dist/esm/google/protobuf/duration_pb.js +10 -30
  21. package/dist/esm/google/protobuf/empty_pb.js +10 -30
  22. package/dist/esm/google/protobuf/field_mask_pb.js +10 -30
  23. package/dist/esm/google/protobuf/source_context_pb.js +10 -30
  24. package/dist/esm/google/protobuf/struct_pb.js +10 -30
  25. package/dist/esm/google/protobuf/timestamp_pb.js +10 -30
  26. package/dist/esm/google/protobuf/type_pb.js +10 -30
  27. package/dist/esm/google/protobuf/wrappers_pb.js +10 -39
  28. package/dist/esm/index.js +1 -0
  29. package/dist/esm/private/json-format-common.js +3 -3
  30. package/dist/esm/proto-base64.js +135 -0
  31. package/dist/types/google/protobuf/any_pb.d.ts +3 -3
  32. package/dist/types/google/protobuf/descriptor_pb.d.ts +16 -3
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/message-type.d.ts +2 -1
  35. package/dist/types/message.d.ts +3 -3
  36. package/dist/types/private/util.d.ts +2 -2
  37. package/dist/types/proto-base64.d.ts +26 -0
  38. package/package.json +1 -1
  39. package/dist/cjs/private/base64.js +0 -132
  40. package/dist/esm/private/base64.js +0 -127
  41. package/dist/types/private/base64.d.ts +0 -18
@@ -20,7 +20,7 @@ export declare class Message<T extends Message<T> = AnyMessage> {
20
20
  /**
21
21
  * Compare with a message of the same type.
22
22
  */
23
- equals(other: T | PlainMessage<T> | undefined): boolean;
23
+ equals(other: T | PlainMessage<T> | undefined | null): boolean;
24
24
  /**
25
25
  * Create a deep copy.
26
26
  */
@@ -81,13 +81,13 @@ export declare type PlainMessage<T extends Message> = {
81
81
  export declare type PartialMessage<T extends Message> = {
82
82
  [P in keyof T as T[P] extends Function ? never : P]?: PartialField<T[P]>;
83
83
  };
84
- declare type PartialField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PartialField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PartialField<U>> : F extends OneofSelectedMessage<infer C, infer V> ? {
84
+ declare type PartialField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PartialField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PartialField<U>> : F extends Message ? PartialMessage<F> : F extends OneofSelectedMessage<infer C, infer V> ? {
85
85
  case: C;
86
86
  value: PartialMessage<V>;
87
87
  } : F extends {
88
88
  case: string | undefined;
89
89
  value?: unknown;
90
- } ? F : F extends Message ? PartialMessage<F> : F extends {
90
+ } ? F : F extends {
91
91
  [key: string | number]: Message<infer U>;
92
92
  } ? {
93
93
  [key: string | number]: PartialMessage<U>;
@@ -33,9 +33,9 @@ export interface Util {
33
33
  initPartial<T extends Message<T>>(source: PartialMessage<T> | undefined, target: T): void;
34
34
  /**
35
35
  * Compares two messages of the same type recursively.
36
- * Will also return true if both messages are `undefined`.
36
+ * Will also return true if both messages are `undefined` or `null`.
37
37
  */
38
- equals<T extends Message<T>>(type: MessageType, a: T | PlainMessage<T> | undefined, b: T | PlainMessage<T> | undefined): boolean;
38
+ equals<T extends Message<T>>(type: MessageType, a: T | PlainMessage<T> | undefined | null, b: T | PlainMessage<T> | undefined | null): boolean;
39
39
  /**
40
40
  * Create a deep copy.
41
41
  */
@@ -0,0 +1,26 @@
1
+ export declare const protoBase64: {
2
+ /**
3
+ * Decodes a base64 string to a byte array.
4
+ *
5
+ * - ignores white-space, including line breaks and tabs
6
+ * - allows inner padding (can decode concatenated base64 strings)
7
+ * - does not require padding
8
+ * - understands base64url encoding:
9
+ * "-" instead of "+",
10
+ * "_" instead of "/",
11
+ * no padding
12
+ */
13
+ readonly dec: (base64Str: string) => Uint8Array;
14
+ /**
15
+ * Decodes a base64 string to a byte array.
16
+ *
17
+ * - ignores white-space, including line breaks and tabs
18
+ * - allows inner padding (can decode concatenated base64 strings)
19
+ * - does not require padding
20
+ * - understands base64url encoding:
21
+ * "-" instead of "+",
22
+ * "_" instead of "/",
23
+ * no padding
24
+ */
25
+ readonly enc: (bytes: Uint8Array) => string;
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "0.0.2-alpha.2",
3
+ "version": "0.0.2-alpha.3",
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": {
@@ -1,132 +0,0 @@
1
- "use strict";
2
- // Copyright 2021-2022 Buf Technologies, Inc.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.base64encode = exports.base64decode = void 0;
17
- /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
18
- // lookup table from base64 character to byte
19
- let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
20
- // lookup table from base64 character *code* to byte because lookup by number is fast
21
- let decTable = [];
22
- for (let i = 0; i < encTable.length; i++)
23
- decTable[encTable[i].charCodeAt(0)] = i;
24
- // support base64url variants
25
- decTable["-".charCodeAt(0)] = encTable.indexOf("+");
26
- decTable["_".charCodeAt(0)] = encTable.indexOf("/");
27
- /**
28
- * Decodes a base64 string to a byte array.
29
- *
30
- * - ignores white-space, including line breaks and tabs
31
- * - allows inner padding (can decode concatenated base64 strings)
32
- * - does not require padding
33
- * - understands base64url encoding:
34
- * "-" instead of "+",
35
- * "_" instead of "/",
36
- * no padding
37
- */
38
- function base64decode(base64Str) {
39
- // estimate byte size, not accounting for inner padding and whitespace
40
- let es = (base64Str.length * 3) / 4;
41
- // if (es % 3 !== 0)
42
- // throw new Error("invalid base64 string");
43
- if (base64Str[base64Str.length - 2] == "=")
44
- es -= 2;
45
- else if (base64Str[base64Str.length - 1] == "=")
46
- es -= 1;
47
- let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
48
- groupPos = 0, // position in base64 group
49
- b, // current byte
50
- p = 0; // previous byte
51
- for (let i = 0; i < base64Str.length; i++) {
52
- b = decTable[base64Str.charCodeAt(i)];
53
- if (b === undefined) {
54
- switch (base64Str[i]) {
55
- // @ts-ignore TS7029: Fallthrough case in switch
56
- case "=":
57
- groupPos = 0; // reset state when padding found
58
- // @ts-ignore TS7029: Fallthrough case in switch
59
- case "\n":
60
- case "\r":
61
- case "\t":
62
- case " ":
63
- continue; // skip white-space, and padding
64
- default:
65
- throw Error("invalid base64 string.");
66
- }
67
- }
68
- switch (groupPos) {
69
- case 0:
70
- p = b;
71
- groupPos = 1;
72
- break;
73
- case 1:
74
- bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
75
- p = b;
76
- groupPos = 2;
77
- break;
78
- case 2:
79
- bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
80
- p = b;
81
- groupPos = 3;
82
- break;
83
- case 3:
84
- bytes[bytePos++] = ((p & 3) << 6) | b;
85
- groupPos = 0;
86
- break;
87
- }
88
- }
89
- if (groupPos == 1)
90
- throw Error("invalid base64 string.");
91
- return bytes.subarray(0, bytePos);
92
- }
93
- exports.base64decode = base64decode;
94
- /**
95
- * Encodes a byte array to a base64 string.
96
- * Adds padding at the end.
97
- * Does not insert newlines.
98
- */
99
- function base64encode(bytes) {
100
- let base64 = "", groupPos = 0, // position in base64 group
101
- b, // current byte
102
- p = 0; // carry over from previous byte
103
- for (let i = 0; i < bytes.length; i++) {
104
- b = bytes[i];
105
- switch (groupPos) {
106
- case 0:
107
- base64 += encTable[b >> 2];
108
- p = (b & 3) << 4;
109
- groupPos = 1;
110
- break;
111
- case 1:
112
- base64 += encTable[p | (b >> 4)];
113
- p = (b & 15) << 2;
114
- groupPos = 2;
115
- break;
116
- case 2:
117
- base64 += encTable[p | (b >> 6)];
118
- base64 += encTable[b & 63];
119
- groupPos = 0;
120
- break;
121
- }
122
- }
123
- // padding required?
124
- if (groupPos) {
125
- base64 += encTable[p];
126
- base64 += "=";
127
- if (groupPos == 1)
128
- base64 += "=";
129
- }
130
- return base64;
131
- }
132
- exports.base64encode = base64encode;
@@ -1,127 +0,0 @@
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
- /**
25
- * Decodes a base64 string to a byte array.
26
- *
27
- * - ignores white-space, including line breaks and tabs
28
- * - allows inner padding (can decode concatenated base64 strings)
29
- * - does not require padding
30
- * - understands base64url encoding:
31
- * "-" instead of "+",
32
- * "_" instead of "/",
33
- * no padding
34
- */
35
- export function base64decode(base64Str) {
36
- // estimate byte size, not accounting for inner padding and whitespace
37
- let es = (base64Str.length * 3) / 4;
38
- // if (es % 3 !== 0)
39
- // throw new Error("invalid base64 string");
40
- if (base64Str[base64Str.length - 2] == "=")
41
- es -= 2;
42
- else if (base64Str[base64Str.length - 1] == "=")
43
- es -= 1;
44
- let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
45
- groupPos = 0, // position in base64 group
46
- b, // current byte
47
- p = 0; // previous byte
48
- for (let i = 0; i < base64Str.length; i++) {
49
- b = decTable[base64Str.charCodeAt(i)];
50
- if (b === undefined) {
51
- switch (base64Str[i]) {
52
- // @ts-ignore TS7029: Fallthrough case in switch
53
- case "=":
54
- groupPos = 0; // reset state when padding found
55
- // @ts-ignore TS7029: Fallthrough case in switch
56
- case "\n":
57
- case "\r":
58
- case "\t":
59
- case " ":
60
- continue; // skip white-space, and padding
61
- default:
62
- throw Error("invalid base64 string.");
63
- }
64
- }
65
- switch (groupPos) {
66
- case 0:
67
- p = b;
68
- groupPos = 1;
69
- break;
70
- case 1:
71
- bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
72
- p = b;
73
- groupPos = 2;
74
- break;
75
- case 2:
76
- bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
77
- p = b;
78
- groupPos = 3;
79
- break;
80
- case 3:
81
- bytes[bytePos++] = ((p & 3) << 6) | b;
82
- groupPos = 0;
83
- break;
84
- }
85
- }
86
- if (groupPos == 1)
87
- throw Error("invalid base64 string.");
88
- return bytes.subarray(0, bytePos);
89
- }
90
- /**
91
- * Encodes a byte array to a base64 string.
92
- * Adds padding at the end.
93
- * Does not insert newlines.
94
- */
95
- export function base64encode(bytes) {
96
- let base64 = "", groupPos = 0, // position in base64 group
97
- b, // current byte
98
- p = 0; // carry over from previous byte
99
- for (let i = 0; i < bytes.length; i++) {
100
- b = bytes[i];
101
- switch (groupPos) {
102
- case 0:
103
- base64 += encTable[b >> 2];
104
- p = (b & 3) << 4;
105
- groupPos = 1;
106
- break;
107
- case 1:
108
- base64 += encTable[p | (b >> 4)];
109
- p = (b & 15) << 2;
110
- groupPos = 2;
111
- break;
112
- case 2:
113
- base64 += encTable[p | (b >> 6)];
114
- base64 += encTable[b & 63];
115
- groupPos = 0;
116
- break;
117
- }
118
- }
119
- // padding required?
120
- if (groupPos) {
121
- base64 += encTable[p];
122
- base64 += "=";
123
- if (groupPos == 1)
124
- base64 += "=";
125
- }
126
- return base64;
127
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Decodes a base64 string to a byte array.
3
- *
4
- * - ignores white-space, including line breaks and tabs
5
- * - allows inner padding (can decode concatenated base64 strings)
6
- * - does not require padding
7
- * - understands base64url encoding:
8
- * "-" instead of "+",
9
- * "_" instead of "/",
10
- * no padding
11
- */
12
- export declare function base64decode(base64Str: string): Uint8Array;
13
- /**
14
- * Encodes a byte array to a base64 string.
15
- * Adds padding at the end.
16
- * Does not insert newlines.
17
- */
18
- export declare function base64encode(bytes: Uint8Array): string;