@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.
- package/README.md +5 -2
- package/dist/cjs/google/protobuf/any_pb.js +19 -39
- package/dist/cjs/google/protobuf/api_pb.js +28 -48
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +32 -67
- package/dist/cjs/google/protobuf/descriptor_pb.js +161 -187
- package/dist/cjs/google/protobuf/duration_pb.js +21 -41
- package/dist/cjs/google/protobuf/empty_pb.js +16 -36
- package/dist/cjs/google/protobuf/field_mask_pb.js +17 -37
- package/dist/cjs/google/protobuf/source_context_pb.js +16 -36
- package/dist/cjs/google/protobuf/struct_pb.js +31 -51
- package/dist/cjs/google/protobuf/timestamp_pb.js +20 -40
- package/dist/cjs/google/protobuf/type_pb.js +43 -63
- package/dist/cjs/google/protobuf/wrappers_pb.js +76 -105
- package/dist/cjs/index-runtime.js +42 -0
- package/dist/cjs/index-wkt.js +42 -0
- package/dist/cjs/index.js +4 -38
- package/dist/cjs/private/enum.js +26 -1
- package/dist/cjs/private/json-format-common.js +3 -3
- package/dist/cjs/private/proto-runtime.js +1 -0
- package/dist/cjs/private/util-common.js +1 -1
- package/dist/cjs/proto-base64.js +138 -0
- package/dist/esm/google/protobuf/any_pb.js +14 -34
- package/dist/esm/google/protobuf/api_pb.js +11 -31
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +11 -46
- package/dist/esm/google/protobuf/descriptor_pb.js +14 -40
- package/dist/esm/google/protobuf/duration_pb.js +11 -31
- package/dist/esm/google/protobuf/empty_pb.js +11 -31
- package/dist/esm/google/protobuf/field_mask_pb.js +11 -31
- package/dist/esm/google/protobuf/source_context_pb.js +11 -31
- package/dist/esm/google/protobuf/struct_pb.js +11 -31
- package/dist/esm/google/protobuf/timestamp_pb.js +11 -31
- package/dist/esm/google/protobuf/type_pb.js +11 -31
- package/dist/esm/google/protobuf/wrappers_pb.js +11 -40
- package/dist/esm/index-runtime.js +25 -0
- package/dist/esm/index-wkt.js +26 -0
- package/dist/esm/index.js +4 -24
- package/dist/esm/private/enum.js +24 -0
- package/dist/esm/private/json-format-common.js +3 -3
- package/dist/esm/private/proto-runtime.js +2 -1
- package/dist/esm/private/util-common.js +1 -1
- package/dist/esm/proto-base64.js +135 -0
- package/dist/types/google/protobuf/any_pb.d.ts +5 -5
- package/dist/types/google/protobuf/api_pb.d.ts +2 -2
- package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +2 -2
- package/dist/types/google/protobuf/descriptor_pb.d.ts +18 -5
- package/dist/types/google/protobuf/duration_pb.d.ts +2 -2
- package/dist/types/google/protobuf/empty_pb.d.ts +2 -2
- package/dist/types/google/protobuf/field_mask_pb.d.ts +2 -2
- package/dist/types/google/protobuf/source_context_pb.d.ts +2 -2
- package/dist/types/google/protobuf/struct_pb.d.ts +2 -2
- package/dist/types/google/protobuf/timestamp_pb.d.ts +2 -2
- package/dist/types/google/protobuf/type_pb.d.ts +2 -2
- package/dist/types/google/protobuf/wrappers_pb.d.ts +2 -2
- package/dist/types/index-runtime.d.ts +19 -0
- package/dist/types/index-wkt.d.ts +12 -0
- package/dist/types/index.d.ts +2 -30
- package/dist/types/message-type.d.ts +2 -1
- package/dist/types/message.d.ts +4 -6
- package/dist/types/private/enum.d.ts +9 -0
- package/dist/types/private/message-type.d.ts +10 -0
- package/dist/types/private/proto-runtime.d.ts +16 -11
- package/dist/types/private/util.d.ts +2 -2
- package/dist/types/proto-base64.d.ts +26 -0
- package/package.json +2 -3
- package/dist/cjs/private/base64.js +0 -132
- package/dist/esm/private/base64.js +0 -127
- package/dist/types/private/base64.d.ts +0 -18
|
@@ -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
|
* A generic empty message that you can re-use to avoid defining duplicated
|
|
5
5
|
* empty messages in your APIs. A typical example is to use it as the request
|
|
@@ -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
|
* `FieldMask` represents a set of symbolic field paths, for example:
|
|
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
|
/**
|
|
4
4
|
* `SourceContext` represents information about the source of a
|
|
5
5
|
* protobuf element, like the file in which it is defined.
|
|
@@ -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
|
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
5
5
|
* `Value` type union.
|
|
@@ -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 Timestamp represents a point in time independent of any time zone or local
|
|
5
5
|
* calendar, encoded as a count of seconds and fractions of seconds at
|
|
@@ -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 { SourceContext } from "./source_context_pb.js";
|
|
4
4
|
import { Any } from "./any_pb.js";
|
|
5
5
|
/**
|
|
@@ -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
|
* Wrapper message for `double`.
|
|
5
5
|
*
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { proto3 } from "./proto3.js";
|
|
2
|
+
export { proto2 } from "./proto2.js";
|
|
3
|
+
export { protoInt64 } from "./proto-int64.js";
|
|
4
|
+
export { protoBase64 } from "./proto-base64.js";
|
|
5
|
+
export { Message, AnyMessage, PartialMessage, PlainMessage, } from "./message.js";
|
|
6
|
+
export type { FieldInfo } from "./field.js";
|
|
7
|
+
export type { FieldList } from "./field-list.js";
|
|
8
|
+
export { ScalarType } from "./field.js";
|
|
9
|
+
export type { MessageType } from "./message-type.js";
|
|
10
|
+
export type { EnumType, EnumValueInfo } from "./enum.js";
|
|
11
|
+
export type { ServiceType, MethodInfo, MethodInfoUnary, MethodInfoServerStreaming, MethodInfoClientStreaming, MethodInfoBiDiStreaming, } from "./service-type.js";
|
|
12
|
+
export { MethodKind, MethodIdempotency } from "./service-type.js";
|
|
13
|
+
export { TypeRegistry, IMessageTypeRegistry } from "./type-registry.js";
|
|
14
|
+
export { DescriptorRegistry } from "./descriptor-registry.js";
|
|
15
|
+
export { DescriptorSet } from "./descriptor-set.js";
|
|
16
|
+
export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
|
|
17
|
+
export type { IBinaryReader, IBinaryWriter } from "./binary-encoding.js";
|
|
18
|
+
export type { BinaryFormat, BinaryWriteOptions, BinaryReadOptions, } from "./binary-format.js";
|
|
19
|
+
export { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptions, JsonWriteStringOptions, } from "./json-format.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./google/protobuf/compiler/plugin_pb.js";
|
|
2
|
+
export * from "./google/protobuf/api_pb.js";
|
|
3
|
+
export * from "./google/protobuf/any_pb.js";
|
|
4
|
+
export * from "./google/protobuf/descriptor_pb.js";
|
|
5
|
+
export * from "./google/protobuf/duration_pb.js";
|
|
6
|
+
export * from "./google/protobuf/empty_pb.js";
|
|
7
|
+
export * from "./google/protobuf/field_mask_pb.js";
|
|
8
|
+
export * from "./google/protobuf/source_context_pb.js";
|
|
9
|
+
export * from "./google/protobuf/struct_pb.js";
|
|
10
|
+
export * from "./google/protobuf/timestamp_pb.js";
|
|
11
|
+
export * from "./google/protobuf/type_pb.js";
|
|
12
|
+
export * from "./google/protobuf/wrappers_pb.js";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export { protoInt64 } from "./proto-int64.js";
|
|
4
|
-
export { Message, AnyMessage, PartialMessage, PlainMessage, } from "./message.js";
|
|
5
|
-
export type { FieldInfo } from "./field.js";
|
|
6
|
-
export type { FieldList } from "./field-list.js";
|
|
7
|
-
export { ScalarType } from "./field.js";
|
|
8
|
-
export type { MessageType } from "./message-type.js";
|
|
9
|
-
export type { EnumType, EnumValueInfo } from "./enum.js";
|
|
10
|
-
export type { ServiceType, MethodInfo, MethodInfoUnary, MethodInfoServerStreaming, MethodInfoClientStreaming, MethodInfoBiDiStreaming, } from "./service-type.js";
|
|
11
|
-
export { MethodKind, MethodIdempotency } from "./service-type.js";
|
|
12
|
-
export { TypeRegistry, IMessageTypeRegistry } from "./type-registry.js";
|
|
13
|
-
export { DescriptorRegistry } from "./descriptor-registry.js";
|
|
14
|
-
export { DescriptorSet } from "./descriptor-set.js";
|
|
15
|
-
export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
|
|
16
|
-
export type { IBinaryReader, IBinaryWriter } from "./binary-encoding.js";
|
|
17
|
-
export type { BinaryFormat, BinaryWriteOptions, BinaryReadOptions, } from "./binary-format.js";
|
|
18
|
-
export { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptions, JsonWriteStringOptions, } from "./json-format.js";
|
|
19
|
-
export * from "./google/protobuf/compiler/plugin_pb.js";
|
|
20
|
-
export * from "./google/protobuf/api_pb.js";
|
|
21
|
-
export * from "./google/protobuf/any_pb.js";
|
|
22
|
-
export * from "./google/protobuf/descriptor_pb.js";
|
|
23
|
-
export * from "./google/protobuf/duration_pb.js";
|
|
24
|
-
export * from "./google/protobuf/empty_pb.js";
|
|
25
|
-
export * from "./google/protobuf/field_mask_pb.js";
|
|
26
|
-
export * from "./google/protobuf/source_context_pb.js";
|
|
27
|
-
export * from "./google/protobuf/struct_pb.js";
|
|
28
|
-
export * from "./google/protobuf/timestamp_pb.js";
|
|
29
|
-
export * from "./google/protobuf/type_pb.js";
|
|
30
|
-
export * from "./google/protobuf/wrappers_pb.js";
|
|
1
|
+
export * from "./index-runtime.js";
|
|
2
|
+
export * from "./index-wkt.js";
|
|
@@ -45,6 +45,7 @@ export interface MessageType<T extends Message<T> = AnyMessage> {
|
|
|
45
45
|
fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): T;
|
|
46
46
|
/**
|
|
47
47
|
* Returns true if the given arguments have equal field values, recursively.
|
|
48
|
+
* Will also return true if both messages are `undefined` or `null`.
|
|
48
49
|
*/
|
|
49
|
-
equals(a: T | PlainMessage<T> | undefined, b: T | PlainMessage<T> | undefined): boolean;
|
|
50
|
+
equals(a: T | PlainMessage<T> | undefined | null, b: T | PlainMessage<T> | undefined | null): boolean;
|
|
50
51
|
}
|
package/dist/types/message.d.ts
CHANGED
|
@@ -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
|
*/
|
|
@@ -67,9 +67,7 @@ export declare class Message<T extends Message<T> = AnyMessage> {
|
|
|
67
67
|
* PlainMessage<T> strips all methods from a message, leaving only fields
|
|
68
68
|
* and oneof groups.
|
|
69
69
|
*/
|
|
70
|
-
export declare type PlainMessage<T extends Message> =
|
|
71
|
-
[P in keyof T as T[P] extends Function ? never : P]: T[P];
|
|
72
|
-
};
|
|
70
|
+
export declare type PlainMessage<T extends Message> = Omit<T, keyof Message>;
|
|
73
71
|
/**
|
|
74
72
|
* PartialMessage<T> constructs a type from a message. The resulting type
|
|
75
73
|
* only contains the protobuf field members of the message, and all of them
|
|
@@ -81,13 +79,13 @@ export declare type PlainMessage<T extends Message> = {
|
|
|
81
79
|
export declare type PartialMessage<T extends Message> = {
|
|
82
80
|
[P in keyof T as T[P] extends Function ? never : P]?: PartialField<T[P]>;
|
|
83
81
|
};
|
|
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> ? {
|
|
82
|
+
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
83
|
case: C;
|
|
86
84
|
value: PartialMessage<V>;
|
|
87
85
|
} : F extends {
|
|
88
86
|
case: string | undefined;
|
|
89
87
|
value?: unknown;
|
|
90
|
-
} ? F : F extends
|
|
88
|
+
} ? F : F extends {
|
|
91
89
|
[key: string | number]: Message<infer U>;
|
|
92
90
|
} ? {
|
|
93
91
|
[key: string | number]: PartialMessage<U>;
|
|
@@ -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
|
|
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
|
|
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
|
}
|
|
@@ -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.
|
|
3
|
+
"version": "0.0.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": {
|
|
@@ -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.
|
|
25
|
+
"typescript": "^4.6.4"
|
|
27
26
|
},
|
|
28
27
|
"files": [
|
|
29
28
|
"dist/**/"
|
|
@@ -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;
|