@aptre/protobuf-es-lite 0.2.11 → 0.2.13

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.
@@ -8,15 +8,13 @@ export declare const protobufPackage = "google.protobuf";
8
8
  *
9
9
  * protobuf-go-lite:disable-text
10
10
  *
11
- *
12
11
  * @generated from message google.protobuf.DoubleValue
13
12
  */
14
13
  export type DoubleValue = Message<{
15
14
  /**
16
15
  * The double value.
17
16
  *
18
- *
19
- * @generated from field: double value = 1 [packed = false, default = , jstype = JS_NORMAL];
17
+ * @generated from field: double value = 1;
20
18
  */
21
19
  value?: number;
22
20
  }>;
@@ -28,15 +26,13 @@ export declare const DoubleValue: MessageType<DoubleValue>;
28
26
  *
29
27
  * protobuf-go-lite:disable-text
30
28
  *
31
- *
32
29
  * @generated from message google.protobuf.FloatValue
33
30
  */
34
31
  export type FloatValue = Message<{
35
32
  /**
36
33
  * The float value.
37
34
  *
38
- *
39
- * @generated from field: float value = 1 [packed = false, default = , jstype = JS_NORMAL];
35
+ * @generated from field: float value = 1;
40
36
  */
41
37
  value?: number;
42
38
  }>;
@@ -48,15 +44,13 @@ export declare const FloatValue: MessageType<FloatValue>;
48
44
  *
49
45
  * protobuf-go-lite:disable-text
50
46
  *
51
- *
52
47
  * @generated from message google.protobuf.Int64Value
53
48
  */
54
49
  export type Int64Value = Message<{
55
50
  /**
56
51
  * The int64 value.
57
52
  *
58
- *
59
- * @generated from field: int64 value = 1 [packed = false, default = , jstype = JS_NORMAL];
53
+ * @generated from field: int64 value = 1;
60
54
  */
61
55
  value?: bigint;
62
56
  }>;
@@ -68,15 +62,13 @@ export declare const Int64Value: MessageType<Int64Value>;
68
62
  *
69
63
  * protobuf-go-lite:disable-text
70
64
  *
71
- *
72
65
  * @generated from message google.protobuf.UInt64Value
73
66
  */
74
67
  export type UInt64Value = Message<{
75
68
  /**
76
69
  * The uint64 value.
77
70
  *
78
- *
79
- * @generated from field: uint64 value = 1 [packed = false, default = , jstype = JS_NORMAL];
71
+ * @generated from field: uint64 value = 1;
80
72
  */
81
73
  value?: bigint;
82
74
  }>;
@@ -88,15 +80,13 @@ export declare const UInt64Value: MessageType<UInt64Value>;
88
80
  *
89
81
  * protobuf-go-lite:disable-text
90
82
  *
91
- *
92
83
  * @generated from message google.protobuf.Int32Value
93
84
  */
94
85
  export type Int32Value = Message<{
95
86
  /**
96
87
  * The int32 value.
97
88
  *
98
- *
99
- * @generated from field: int32 value = 1 [packed = false, default = , jstype = JS_NORMAL];
89
+ * @generated from field: int32 value = 1;
100
90
  */
101
91
  value?: number;
102
92
  }>;
@@ -108,15 +98,13 @@ export declare const Int32Value: MessageType<Int32Value>;
108
98
  *
109
99
  * protobuf-go-lite:disable-text
110
100
  *
111
- *
112
101
  * @generated from message google.protobuf.UInt32Value
113
102
  */
114
103
  export type UInt32Value = Message<{
115
104
  /**
116
105
  * The uint32 value.
117
106
  *
118
- *
119
- * @generated from field: uint32 value = 1 [packed = false, default = , jstype = JS_NORMAL];
107
+ * @generated from field: uint32 value = 1;
120
108
  */
121
109
  value?: number;
122
110
  }>;
@@ -128,15 +116,13 @@ export declare const UInt32Value: MessageType<UInt32Value>;
128
116
  *
129
117
  * protobuf-go-lite:disable-text
130
118
  *
131
- *
132
119
  * @generated from message google.protobuf.BoolValue
133
120
  */
134
121
  export type BoolValue = Message<{
135
122
  /**
136
123
  * The bool value.
137
124
  *
138
- *
139
- * @generated from field: bool value = 1 [packed = false, default = , jstype = JS_NORMAL];
125
+ * @generated from field: bool value = 1;
140
126
  */
141
127
  value?: boolean;
142
128
  }>;
@@ -148,15 +134,13 @@ export declare const BoolValue: MessageType<BoolValue>;
148
134
  *
149
135
  * protobuf-go-lite:disable-text
150
136
  *
151
- *
152
137
  * @generated from message google.protobuf.StringValue
153
138
  */
154
139
  export type StringValue = Message<{
155
140
  /**
156
141
  * The string value.
157
142
  *
158
- *
159
- * @generated from field: string value = 1 [packed = false, default = "", jstype = JS_NORMAL];
143
+ * @generated from field: string value = 1;
160
144
  */
161
145
  value?: string;
162
146
  }>;
@@ -168,15 +152,13 @@ export declare const StringValue: MessageType<StringValue>;
168
152
  *
169
153
  * protobuf-go-lite:disable-text
170
154
  *
171
- *
172
155
  * @generated from message google.protobuf.BytesValue
173
156
  */
174
157
  export type BytesValue = Message<{
175
158
  /**
176
159
  * The bytes value.
177
160
  *
178
- *
179
- * @generated from field: bytes value = 1 [packed = false, default = "", jstype = JS_NORMAL];
161
+ * @generated from field: bytes value = 1;
180
162
  */
181
163
  value?: Uint8Array;
182
164
  }>;
package/dist/json.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { FieldInfo, FieldList } from "./field.js";
2
- import { IMessageTypeRegistry } from "./type-registry.js";
3
2
  /**
4
3
  * Options for parsing JSON data.
5
4
  */
@@ -10,10 +9,6 @@ export interface JsonReadOptions {
10
9
  * unrecognized enum string representations.
11
10
  */
12
11
  ignoreUnknownFields: boolean;
13
- /**
14
- * This option is required to read `google.protobuf.Any`
15
- */
16
- typeRegistry?: IMessageTypeRegistry;
17
12
  }
18
13
  /**
19
14
  * Options for serializing to JSON.
@@ -40,10 +35,6 @@ export interface JsonWriteOptions {
40
35
  * field name.
41
36
  */
42
37
  useProtoFieldName: boolean;
43
- /**
44
- * This option is required to write `google.protobuf.Any`
45
- */
46
- typeRegistry?: IMessageTypeRegistry;
47
38
  }
48
39
  /**
49
40
  * Options for serializing to JSON.
package/dist/json.js CHANGED
@@ -90,28 +90,6 @@ export function writeMessage(message, fields, options) {
90
90
  jsonValue;
91
91
  }
92
92
  }
93
- // TODO: handle extensions
94
- /*
95
- const registry = options.typeRegistry;
96
- if (registry?.findExtensionFor) {
97
- for (const uf of listUnknownFields(message)) {
98
- const ext = registry.findExtensionFor(typeName, uf.no);
99
- if (ext && hasExtension(message, ext)) {
100
- // We pass on the options as BinaryReadOptions, so that users can bring their own
101
- // binary reader factory if necessary.
102
- const value = getExtension(
103
- message,
104
- ext,
105
- options as Partial<BinaryReadOptions>,
106
- );
107
- const jsonValue = writeField(ext.field, value, options);
108
- if (jsonValue !== undefined) {
109
- json[ext.field.jsonName] = jsonValue;
110
- }
111
- }
112
- }
113
- }
114
- */
115
93
  }
116
94
  catch (e) {
117
95
  const m = field ?
package/dist/message.d.ts CHANGED
@@ -25,7 +25,7 @@ export type AnyMessage = {
25
25
  * - metadata for reflection-based operations
26
26
  * - common functionality like serialization
27
27
  */
28
- export interface MessageType<T extends Message<T>> {
28
+ export interface MessageType<T extends Message<T> = AnyMessage> {
29
29
  /**
30
30
  * The fully qualified name of the message.
31
31
  */
@@ -45,7 +45,7 @@ export interface MessageType<T extends Message<T>> {
45
45
  /**
46
46
  * Create a deep copy.
47
47
  */
48
- clone(a: T | undefined | null): T | undefined | null;
48
+ clone(a: Message<T> | undefined | null): Message<T> | undefined | null;
49
49
  /**
50
50
  * Parse from binary data, merging fields.
51
51
  *
@@ -55,33 +55,33 @@ export interface MessageType<T extends Message<T>> {
55
55
  * If a message field is already present, it will be merged with the
56
56
  * new data.
57
57
  */
58
- fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): CompleteMessage<T>;
58
+ fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Message<T>;
59
59
  /**
60
60
  * Parse a message from a JSON value.
61
61
  */
62
- fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): CompleteMessage<T>;
62
+ fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Message<T>;
63
63
  /**
64
64
  * Parse a message from a JSON string.
65
65
  */
66
- fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): CompleteMessage<T>;
66
+ fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Message<T>;
67
67
  /**
68
68
  * Returns true if the given arguments have equal field values, recursively.
69
69
  * Will also return true if both messages are `undefined` or `null`.
70
70
  */
71
- equals(a: T | undefined | null, b: T | undefined | null): boolean;
71
+ equals(a: Message<T> | undefined | null, b: Message<T> | undefined | null): boolean;
72
72
  /**
73
73
  * Serialize the message to binary data.
74
74
  */
75
- toBinary(a: T, options?: Partial<BinaryWriteOptions>): Uint8Array;
75
+ toBinary(a: Message<T>, options?: Partial<BinaryWriteOptions>): Uint8Array;
76
76
  /**
77
77
  * Serialize the message to a JSON value, a JavaScript value that can be
78
78
  * passed to JSON.stringify().
79
79
  */
80
- toJson(a: T, options?: Partial<JsonWriteOptions>): JsonValue;
80
+ toJson(a: Message<T>, options?: Partial<JsonWriteOptions>): JsonValue;
81
81
  /**
82
82
  * Serialize the message to a JSON string.
83
83
  */
84
- toJsonString(a: T, options?: Partial<JsonWriteStringOptions>): string;
84
+ toJsonString(a: Message<T>, options?: Partial<JsonWriteStringOptions>): string;
85
85
  }
86
86
  export interface MessageTypeParams<T extends Message<T>> extends Pick<MessageType<T>, "typeName" | "fieldWrapper"> {
87
87
  /**
package/dist/message.js CHANGED
@@ -172,13 +172,13 @@ export function createMessageType(params) {
172
172
  return cloneMessage(a, fields);
173
173
  },
174
174
  fromBinary(bytes, options) {
175
- const message = this.create();
175
+ const message = {};
176
176
  const opt = makeBinaryReadOptions(options);
177
177
  readBinaryMessage(message, fields, opt.readerFactory(bytes), bytes.byteLength, opt, delimitedMessageEncoding);
178
178
  return message;
179
179
  },
180
180
  fromJson(jsonValue, options) {
181
- const message = this.create();
181
+ const message = {};
182
182
  const opts = makeJsonReadOptions(options);
183
183
  readJsonMessage(fields, typeName, jsonValue, opts, message);
184
184
  return message;
package/dist/partial.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { resolveMessageType } from "./field.js";
2
- import { isCompleteMessage } from "./is-message.js";
3
2
  import { ScalarType } from "./scalar.js";
4
3
  // applyPartialMessage applies a partial message to a message.
5
4
  export function applyPartialMessage(source, target, fields) {
@@ -9,7 +8,6 @@ export function applyPartialMessage(source, target, fields) {
9
8
  for (const member of fields.byMember()) {
10
9
  const localName = member.localName, t = target, s = source;
11
10
  if (s[localName] === undefined) {
12
- // TODO if source is a Message instance, we should use isFieldSet() here to support future field presence
13
11
  continue;
14
12
  }
15
13
  switch (member.kind) {
@@ -21,9 +19,8 @@ export function applyPartialMessage(source, target, fields) {
21
19
  const sourceField = member.findField(sk);
22
20
  let val = s[localName].value;
23
21
  if (sourceField?.kind == "message") {
24
- const messageType = resolveMessageType(sourceField.T);
25
- if (!isCompleteMessage(val, messageType.fields.list())) {
26
- val = messageType.create(val);
22
+ if (val === undefined) {
23
+ val = {};
27
24
  }
28
25
  }
29
26
  else if (sourceField &&
@@ -62,9 +59,9 @@ export function applyPartialMessage(source, target, fields) {
62
59
  for (const k of Object.keys(s[localName])) {
63
60
  let val = s[localName][k];
64
61
  if (!messageType.fieldWrapper) {
65
- // We only take partial input for messages that are not a wrapper type.
66
- // For those messages, we recursively normalize the partial input.
67
- val = messageType.create(val);
62
+ if (val === undefined) {
63
+ val = {};
64
+ }
68
65
  }
69
66
  t[localName][k] = val;
70
67
  }
@@ -74,7 +71,7 @@ export function applyPartialMessage(source, target, fields) {
74
71
  case "message":
75
72
  const mt = resolveMessageType(member.T);
76
73
  if (member.repeated) {
77
- t[localName] = s[localName].map((val) => isCompleteMessage(val, mt.fields.list()) ? val : mt.create(val));
74
+ t[localName] = s[localName].map((val) => val ?? {});
78
75
  }
79
76
  else {
80
77
  const val = s[localName];
@@ -89,9 +86,7 @@ export function applyPartialMessage(source, target, fields) {
89
86
  }
90
87
  }
91
88
  else {
92
- const messageType = mt;
93
- t[localName] =
94
- isCompleteMessage(val, messageType.fields.list()) ? val : (messageType.create(val));
89
+ t[localName] = val ?? {};
95
90
  }
96
91
  }
97
92
  break;
@@ -14,7 +14,7 @@
14
14
  import { createSchema } from "./ecmascript/schema.js";
15
15
  import { transpile } from "./ecmascript/transpile.js";
16
16
  import { parseParameter } from "./ecmascript/parameter.js";
17
- import { CodeGeneratorResponse, CodeGeneratorResponse_Feature, } from "../google/protobuf/compiler/plugin.pb.js";
17
+ import { CodeGeneratorResponse_Feature, } from "../google/protobuf/compiler/plugin.pb.js";
18
18
  import { protoInt64 } from "../proto-int64.js";
19
19
  /**
20
20
  * Create a new code generator plugin for ECMAScript.
@@ -103,7 +103,7 @@ function toResponse(files, supportsEditions) {
103
103
  supportedFeatures =
104
104
  supportedFeatures | CodeGeneratorResponse_Feature.SUPPORTS_EDITIONS;
105
105
  }
106
- return CodeGeneratorResponse.create({
106
+ return {
107
107
  supportedFeatures: protoInt64.parse(supportedFeatures),
108
108
  file: files.map((f) => {
109
109
  if (f.preamble !== undefined) {
@@ -111,5 +111,5 @@ function toResponse(files, supportsEditions) {
111
111
  }
112
112
  return f;
113
113
  }),
114
- });
114
+ };
115
115
  }
@@ -12,12 +12,12 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  export class PluginOptionError extends Error {
15
+ name = "PluginOptionError";
15
16
  constructor(option, reason) {
16
17
  const detail = reason !== undefined ? reasonToString(reason) : "";
17
18
  super(detail.length > 0 ?
18
19
  `invalid option "${option}": ${detail}`
19
20
  : `invalid option "${option}"`);
20
- this.name = "PluginOptionError";
21
21
  }
22
22
  }
23
23
  export function reasonToString(reason) {
@@ -1,11 +1,7 @@
1
- //
2
-
3
1
  // @generated by protoc-gen-es-lite unknown with parameter "target=ts,ts_nocheck=false"
4
2
  // @generated from file example/example.proto (package example, syntax proto3)
5
3
  /* eslint-disable */
6
4
 
7
- //
8
-
9
5
  import type { MessageType, PartialFieldInfo } from "@aptre/protobuf-es-lite";
10
6
  import { createEnumType, createMessageType, Message, Timestamp } from "@aptre/protobuf-es-lite";
11
7
 
@@ -14,7 +10,6 @@ export const protobufPackage = "example";
14
10
  /**
15
11
  * ExampleEnum is an example enumeration.
16
12
  *
17
- *
18
13
  * @generated from enum example.ExampleEnum
19
14
  */
20
15
  export enum ExampleEnum {
@@ -44,30 +39,41 @@ export const ExampleEnum_Enum = createEnumType("example.ExampleEnum", [
44
39
  /**
45
40
  * EchoMsg is the message body for Echo.
46
41
  *
47
- *
48
42
  * @generated from message example.EchoMsg
49
43
  */
50
44
  export type EchoMsg = Message<{
51
45
  /**
52
- * @generated from field: string body = 1 [packed = false, default = "", jstype = JS_NORMAL];
46
+ * @generated from field: string body = 1;
53
47
  */
54
48
  body?: string;
55
49
  /**
56
- * @generated from field: google.protobuf.Timestamp ts = 2 [packed = false, default = , jstype = JS_NORMAL];
50
+ * @generated from field: google.protobuf.Timestamp ts = 2;
57
51
  */
58
52
  ts?: Timestamp;
59
53
  /**
60
- * @generated from field: example.ExampleEnum example_enum = 3 [packed = false, default = , jstype = JS_NORMAL];
54
+ * @generated from field: repeated google.protobuf.Timestamp timestamps = 5;
61
55
  */
62
- exampleEnum?: ExampleEnum;
63
- /**
64
- * @generated from field: string example_string = 4 [packed = false, default = "", jstype = JS_NORMAL];
65
- */
66
- exampleString?: string;
56
+ timestamps?: Timestamp[];
57
+
67
58
  /**
68
- * @generated from field: repeated google.protobuf.Timestamp timestamps = 5 [packed = false, default = , jstype = JS_NORMAL];
59
+ * @generated from oneof example.EchoMsg.demo
69
60
  */
70
- timestamps?: Timestamp[];
61
+ demo?: {
62
+ value?: undefined,
63
+ case: undefined
64
+ } | {
65
+ /**
66
+ * @generated from field: example.ExampleEnum example_enum = 3;
67
+ */
68
+ value: ExampleEnum;
69
+ case: "exampleEnum";
70
+ } | {
71
+ /**
72
+ * @generated from field: string example_string = 4;
73
+ */
74
+ value: string;
75
+ case: "exampleString";
76
+ };
71
77
 
72
78
  }>;
73
79
 
@@ -77,8 +83,8 @@ export const EchoMsg: MessageType<EchoMsg> = createMessageType(
77
83
  fields: [
78
84
  { no: 1, name: "body", kind: "scalar", T: 9 /* ScalarType.STRING */ },
79
85
  { no: 2, name: "ts", kind: "message", T: () => Timestamp },
80
- { no: 3, name: "example_enum", kind: "enum", T: ExampleEnum_Enum },
81
- { no: 4, name: "example_string", kind: "scalar", T: 9 /* ScalarType.STRING */ },
86
+ { no: 3, name: "example_enum", kind: "enum", T: ExampleEnum_Enum, oneof: "demo" },
87
+ { no: 4, name: "example_string", kind: "scalar", T: 9 /* ScalarType.STRING */, oneof: "demo" },
82
88
  { no: 5, name: "timestamps", kind: "message", T: () => Timestamp, repeated: true },
83
89
  ] as readonly PartialFieldInfo[],
84
90
  packedByDefault: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aptre/protobuf-es-lite",
3
3
  "description": "Lightweight Protobuf codegen for TypeScript and JavaScript.",
4
- "version": "0.2.11",
4
+ "version": "0.2.13",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "url": "git+ssh://git@github.com/aperturerobotics/protobuf-es-lite.git"
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2020",
4
- "module": "ES2020",
5
- "moduleResolution": "node",
3
+ "target": "es2022",
4
+ "module": "Node16",
5
+ "moduleResolution": "Node16",
6
6
  "esModuleInterop": false,
7
7
  "forceConsistentCasingInFileNames": true,
8
8
  "strict": true,
@@ -1,43 +0,0 @@
1
- import type { AnyMessage, Message, MessageType } from "./message.js";
2
- import type { EnumType } from "./enum.js";
3
- import type { ServiceType } from "./service-type.js";
4
- /**
5
- * IMessageTypeRegistry provides look-up for message types.
6
- *
7
- * You can conveniently create a registry using the createRegistry()
8
- * function:
9
- *
10
- * ```ts
11
- * import { createRegistry } from "@bufbuild/protobuf";
12
- * import { MyMessage, MyOtherMessage } from "./gen/my_message.pb.js";
13
- *
14
- * const reg: IMessageTypeRegistry = createRegistry(
15
- * MyMessage,
16
- * MyOtherMessage,
17
- * );
18
- * ```
19
- */
20
- export interface IMessageTypeRegistry {
21
- /**
22
- * Find a message type by its protobuf type name.
23
- */
24
- findMessage<T extends Message<T> = AnyMessage>(typeName: string): MessageType<T> | undefined;
25
- }
26
- /**
27
- * IEnumTypeRegistry provides look-up for enum types.
28
- */
29
- export interface IEnumTypeRegistry {
30
- /**
31
- * Find an enum type by its protobuf type name.
32
- */
33
- findEnum(typeName: string): EnumType | undefined;
34
- }
35
- /**
36
- * IServiceTypeRegistry provides look-up for service types.
37
- */
38
- export interface IServiceTypeRegistry {
39
- /**
40
- * Find a service type by its protobuf type name.
41
- */
42
- findService(typeName: string): ServiceType | undefined;
43
- }
@@ -1,14 +0,0 @@
1
- // Copyright 2021-2024 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
- export {};