@aptre/protobuf-es-lite 0.3.0 → 0.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.
@@ -27,7 +27,7 @@
27
27
  // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
28
  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
29
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
- import { createMessageType, jsonDebugValue, protoInt64, ScalarType } from "../../index.js";
30
+ import { createMessageType, jsonDebugValue, protoInt64, ScalarType, } from "../../index.js";
31
31
  export const protobufPackage = "google.protobuf";
32
32
  // Duration_Wkt contains the well-known-type overrides for Duration.
33
33
  const Duration_Wkt = {
@@ -27,7 +27,7 @@
27
27
  // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
28
  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
29
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
- import { createEnumType, createMessageType, jsonDebugValue, ScalarType } from "../../index.js";
30
+ import { createEnumType, createMessageType, jsonDebugValue, ScalarType, } from "../../index.js";
31
31
  export const protobufPackage = "google.protobuf";
32
32
  /**
33
33
  * `NullValue` is a singleton enumeration to represent the null value for the
@@ -53,7 +53,7 @@ export const NullValue_Enum = createEnumType("google.protobuf.NullValue", [
53
53
  // ListValue_Wkt contains the well-known-type overrides for ListValue.
54
54
  const ListValue_Wkt = {
55
55
  toJson(msg, options) {
56
- return msg.values?.map(v => Value.toJson(v, options)) ?? [];
56
+ return msg.values?.map((v) => Value.toJson(v, options)) ?? [];
57
57
  },
58
58
  fromJson(json, options) {
59
59
  if (json == null) {
@@ -62,7 +62,7 @@ const ListValue_Wkt = {
62
62
  if (!Array.isArray(json)) {
63
63
  throw new Error(`cannot decode google.protobuf.ListValue from JSON ${jsonDebugValue(json)}`);
64
64
  }
65
- const values = json.map(v => Value.fromJson(v, options));
65
+ const values = json.map((v) => Value.fromJson(v, options));
66
66
  return { values: values };
67
67
  },
68
68
  };
@@ -70,7 +70,13 @@ const ListValue_Wkt = {
70
70
  export const ListValue = createMessageType({
71
71
  typeName: "google.protobuf.ListValue",
72
72
  fields: [
73
- { no: 1, name: "values", kind: "message", T: () => Value, repeated: true },
73
+ {
74
+ no: 1,
75
+ name: "values",
76
+ kind: "message",
77
+ T: () => Value,
78
+ repeated: true,
79
+ },
74
80
  ],
75
81
  packedByDefault: true,
76
82
  }, ListValue_Wkt);
@@ -90,9 +96,15 @@ const Value_Wkt = {
90
96
  case "stringValue":
91
97
  return msg.kind.value;
92
98
  case "structValue":
93
- return Struct.toJson(msg.kind.value, { ...options, emitDefaultValues: true });
99
+ return Struct.toJson(msg.kind.value, {
100
+ ...options,
101
+ emitDefaultValues: true,
102
+ });
94
103
  case "listValue":
95
- return ListValue.toJson(msg.kind.value, { ...options, emitDefaultValues: true });
104
+ return ListValue.toJson(msg.kind.value, {
105
+ ...options,
106
+ emitDefaultValues: true,
107
+ });
96
108
  case null:
97
109
  case undefined:
98
110
  default:
@@ -132,12 +144,48 @@ const Value_Wkt = {
132
144
  export const Value = createMessageType({
133
145
  typeName: "google.protobuf.Value",
134
146
  fields: [
135
- { no: 1, name: "null_value", kind: "enum", T: NullValue_Enum, oneof: "kind" },
136
- { no: 2, name: "number_value", kind: "scalar", T: ScalarType.DOUBLE, oneof: "kind" },
137
- { no: 3, name: "string_value", kind: "scalar", T: ScalarType.STRING, oneof: "kind" },
138
- { no: 4, name: "bool_value", kind: "scalar", T: ScalarType.BOOL, oneof: "kind" },
139
- { no: 5, name: "struct_value", kind: "message", T: () => Struct, oneof: "kind" },
140
- { no: 6, name: "list_value", kind: "message", T: () => ListValue, oneof: "kind" },
147
+ {
148
+ no: 1,
149
+ name: "null_value",
150
+ kind: "enum",
151
+ T: NullValue_Enum,
152
+ oneof: "kind",
153
+ },
154
+ {
155
+ no: 2,
156
+ name: "number_value",
157
+ kind: "scalar",
158
+ T: ScalarType.DOUBLE,
159
+ oneof: "kind",
160
+ },
161
+ {
162
+ no: 3,
163
+ name: "string_value",
164
+ kind: "scalar",
165
+ T: ScalarType.STRING,
166
+ oneof: "kind",
167
+ },
168
+ {
169
+ no: 4,
170
+ name: "bool_value",
171
+ kind: "scalar",
172
+ T: ScalarType.BOOL,
173
+ oneof: "kind",
174
+ },
175
+ {
176
+ no: 5,
177
+ name: "struct_value",
178
+ kind: "message",
179
+ T: () => Struct,
180
+ oneof: "kind",
181
+ },
182
+ {
183
+ no: 6,
184
+ name: "list_value",
185
+ kind: "message",
186
+ T: () => ListValue,
187
+ oneof: "kind",
188
+ },
141
189
  ],
142
190
  packedByDefault: true,
143
191
  }, Value_Wkt);
@@ -168,7 +216,13 @@ const Struct_Wkt = {
168
216
  export const Struct = createMessageType({
169
217
  typeName: "google.protobuf.Struct",
170
218
  fields: [
171
- { no: 1, name: "fields", kind: "map", K: ScalarType.STRING, V: { kind: "message", T: () => Value } },
219
+ {
220
+ no: 1,
221
+ name: "fields",
222
+ kind: "map",
223
+ K: ScalarType.STRING,
224
+ V: { kind: "message", T: () => Value },
225
+ },
172
226
  ],
173
227
  packedByDefault: true,
174
228
  }, Struct_Wkt);
@@ -27,7 +27,7 @@
27
27
  // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
28
  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
29
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
- import { createMessageType, protoInt64, ScalarType } from "../../index.js";
30
+ import { createMessageType, protoInt64, ScalarType, } from "../../index.js";
31
31
  export const protobufPackage = "google.protobuf";
32
32
  // Timestamp_Wkt contains the well-known-type overrides for Timestamp.
33
33
  const Timestamp_Wkt = {
@@ -39,21 +39,35 @@ const Timestamp_Wkt = {
39
39
  if (!matches) {
40
40
  throw new Error(`cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string`);
41
41
  }
42
- const ms = Date.parse(matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z"));
42
+ const ms = Date.parse(matches[1] +
43
+ "-" +
44
+ matches[2] +
45
+ "-" +
46
+ matches[3] +
47
+ "T" +
48
+ matches[4] +
49
+ ":" +
50
+ matches[5] +
51
+ ":" +
52
+ matches[6] +
53
+ (matches[8] ? matches[8] : "Z"));
43
54
  if (Number.isNaN(ms)) {
44
55
  throw new Error(`cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string`);
45
56
  }
46
- if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z")) {
57
+ if (ms < Date.parse("0001-01-01T00:00:00Z") ||
58
+ ms > Date.parse("9999-12-31T23:59:59Z")) {
47
59
  throw new Error(`cannot decode message google.protobuf.Timestamp from JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);
48
60
  }
49
61
  return {
50
62
  seconds: protoInt64.parse(ms / 1000),
51
- nanos: !matches[7] ? 0 : (parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) - 1000000000),
63
+ nanos: !matches[7] ? 0 : (parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) -
64
+ 1000000000),
52
65
  };
53
66
  },
54
67
  toJson(msg) {
55
68
  const ms = Number(msg.seconds) * 1000;
56
- if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z")) {
69
+ if (ms < Date.parse("0001-01-01T00:00:00Z") ||
70
+ ms > Date.parse("9999-12-31T23:59:59Z")) {
57
71
  throw new Error(`cannot encode google.protobuf.Timestamp to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);
58
72
  }
59
73
  if (msg.nanos != null && msg.nanos < 0) {
@@ -27,7 +27,7 @@
27
27
  // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
28
  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
29
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
- import { createEnumType, createMessageType, ScalarType } from "../../index.js";
30
+ import { createEnumType, createMessageType, ScalarType, } from "../../index.js";
31
31
  import { Any } from "./any.pb.js";
32
32
  import { SourceContext } from "./source_context.pb.js";
33
33
  export const protobufPackage = "google.protobuf";
@@ -266,7 +266,13 @@ export const Field = createMessageType({
266
266
  { no: 6, name: "type_url", kind: "scalar", T: ScalarType.STRING },
267
267
  { no: 7, name: "oneof_index", kind: "scalar", T: ScalarType.INT32 },
268
268
  { no: 8, name: "packed", kind: "scalar", T: ScalarType.BOOL },
269
- { no: 9, name: "options", kind: "message", T: () => Option, repeated: true },
269
+ {
270
+ no: 9,
271
+ name: "options",
272
+ kind: "message",
273
+ T: () => Option,
274
+ repeated: true,
275
+ },
270
276
  { no: 10, name: "json_name", kind: "scalar", T: ScalarType.STRING },
271
277
  { no: 11, name: "default_value", kind: "scalar", T: ScalarType.STRING },
272
278
  ],
@@ -278,8 +284,20 @@ export const Type = createMessageType({
278
284
  fields: [
279
285
  { no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
280
286
  { no: 2, name: "fields", kind: "message", T: () => Field, repeated: true },
281
- { no: 3, name: "oneofs", kind: "scalar", T: ScalarType.STRING, repeated: true },
282
- { no: 4, name: "options", kind: "message", T: () => Option, repeated: true },
287
+ {
288
+ no: 3,
289
+ name: "oneofs",
290
+ kind: "scalar",
291
+ T: ScalarType.STRING,
292
+ repeated: true,
293
+ },
294
+ {
295
+ no: 4,
296
+ name: "options",
297
+ kind: "message",
298
+ T: () => Option,
299
+ repeated: true,
300
+ },
283
301
  { no: 5, name: "source_context", kind: "message", T: () => SourceContext },
284
302
  { no: 6, name: "syntax", kind: "enum", T: Syntax_Enum },
285
303
  { no: 7, name: "edition", kind: "scalar", T: ScalarType.STRING },
@@ -292,7 +310,13 @@ export const EnumValue = createMessageType({
292
310
  fields: [
293
311
  { no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
294
312
  { no: 2, name: "number", kind: "scalar", T: ScalarType.INT32 },
295
- { no: 3, name: "options", kind: "message", T: () => Option, repeated: true },
313
+ {
314
+ no: 3,
315
+ name: "options",
316
+ kind: "message",
317
+ T: () => Option,
318
+ repeated: true,
319
+ },
296
320
  ],
297
321
  packedByDefault: true,
298
322
  });
@@ -301,8 +325,20 @@ export const Enum = createMessageType({
301
325
  typeName: "google.protobuf.Enum",
302
326
  fields: [
303
327
  { no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
304
- { no: 2, name: "enumvalue", kind: "message", T: () => EnumValue, repeated: true },
305
- { no: 3, name: "options", kind: "message", T: () => Option, repeated: true },
328
+ {
329
+ no: 2,
330
+ name: "enumvalue",
331
+ kind: "message",
332
+ T: () => EnumValue,
333
+ repeated: true,
334
+ },
335
+ {
336
+ no: 3,
337
+ name: "options",
338
+ kind: "message",
339
+ T: () => Option,
340
+ repeated: true,
341
+ },
306
342
  { no: 4, name: "source_context", kind: "message", T: () => SourceContext },
307
343
  { no: 5, name: "syntax", kind: "enum", T: Syntax_Enum },
308
344
  { no: 6, name: "edition", kind: "scalar", T: ScalarType.STRING },
@@ -37,7 +37,7 @@
37
37
  // the ability to detect presence on individual elements.
38
38
  // These wrappers have no meaningful use within a map or a oneof since
39
39
  // individual entries of a map or fields of a oneof can already detect presence.
40
- import { createMessageType, jsonReadScalar, jsonWriteScalar, LongType, ScalarType } from "../../index.js";
40
+ import { createMessageType, jsonReadScalar, jsonWriteScalar, LongType, ScalarType, } from "../../index.js";
41
41
  export const protobufPackage = "google.protobuf";
42
42
  // DoubleValue_Wkt contains the well-known-type overrides for DoubleValue.
43
43
  const DoubleValue_Wkt = {
@@ -46,7 +46,9 @@ const DoubleValue_Wkt = {
46
46
  },
47
47
  fromJson(json, _options) {
48
48
  try {
49
- return { value: jsonReadScalar(ScalarType.DOUBLE, json, LongType.BIGINT) };
49
+ return {
50
+ value: jsonReadScalar(ScalarType.DOUBLE, json, LongType.BIGINT),
51
+ };
50
52
  }
51
53
  catch (e) {
52
54
  let m = `cannot decode message google.protobuf.DoubleValue from JSON"`;
@@ -64,6 +66,14 @@ export const DoubleValue = createMessageType({
64
66
  { no: 1, name: "value", kind: "scalar", T: ScalarType.DOUBLE },
65
67
  ],
66
68
  packedByDefault: true,
69
+ fieldWrapper: {
70
+ wrapField(value) {
71
+ return DoubleValue.createComplete({ value: value ?? undefined });
72
+ },
73
+ unwrapField(msg) {
74
+ return msg.value;
75
+ },
76
+ },
67
77
  }, DoubleValue_Wkt);
68
78
  // FloatValue_Wkt contains the well-known-type overrides for FloatValue.
69
79
  const FloatValue_Wkt = {
@@ -72,7 +82,9 @@ const FloatValue_Wkt = {
72
82
  },
73
83
  fromJson(json, _options) {
74
84
  try {
75
- return { value: jsonReadScalar(ScalarType.FLOAT, json, LongType.BIGINT) };
85
+ return {
86
+ value: jsonReadScalar(ScalarType.FLOAT, json, LongType.BIGINT),
87
+ };
76
88
  }
77
89
  catch (e) {
78
90
  let m = `cannot decode message google.protobuf.FloatValue from JSON"`;
@@ -90,6 +102,14 @@ export const FloatValue = createMessageType({
90
102
  { no: 1, name: "value", kind: "scalar", T: ScalarType.FLOAT },
91
103
  ],
92
104
  packedByDefault: true,
105
+ fieldWrapper: {
106
+ wrapField(value) {
107
+ return FloatValue.createComplete({ value: value ?? undefined });
108
+ },
109
+ unwrapField(msg) {
110
+ return msg.value;
111
+ },
112
+ },
93
113
  }, FloatValue_Wkt);
94
114
  // Int64Value_Wkt contains the well-known-type overrides for Int64Value.
95
115
  const Int64Value_Wkt = {
@@ -98,7 +118,9 @@ const Int64Value_Wkt = {
98
118
  },
99
119
  fromJson(json, _options) {
100
120
  try {
101
- return { value: jsonReadScalar(ScalarType.INT64, json, LongType.BIGINT) };
121
+ return {
122
+ value: jsonReadScalar(ScalarType.INT64, json, LongType.BIGINT),
123
+ };
102
124
  }
103
125
  catch (e) {
104
126
  let m = `cannot decode message google.protobuf.Int64Value from JSON"`;
@@ -116,6 +138,14 @@ export const Int64Value = createMessageType({
116
138
  { no: 1, name: "value", kind: "scalar", T: ScalarType.INT64 },
117
139
  ],
118
140
  packedByDefault: true,
141
+ fieldWrapper: {
142
+ wrapField(value) {
143
+ return Int64Value.createComplete({ value: value ?? undefined });
144
+ },
145
+ unwrapField(msg) {
146
+ return msg.value;
147
+ },
148
+ },
119
149
  }, Int64Value_Wkt);
120
150
  // UInt64Value_Wkt contains the well-known-type overrides for UInt64Value.
121
151
  const UInt64Value_Wkt = {
@@ -124,7 +154,9 @@ const UInt64Value_Wkt = {
124
154
  },
125
155
  fromJson(json, _options) {
126
156
  try {
127
- return { value: jsonReadScalar(ScalarType.UINT64, json, LongType.BIGINT) };
157
+ return {
158
+ value: jsonReadScalar(ScalarType.UINT64, json, LongType.BIGINT),
159
+ };
128
160
  }
129
161
  catch (e) {
130
162
  let m = `cannot decode message google.protobuf.UInt64Value from JSON"`;
@@ -142,6 +174,14 @@ export const UInt64Value = createMessageType({
142
174
  { no: 1, name: "value", kind: "scalar", T: ScalarType.UINT64 },
143
175
  ],
144
176
  packedByDefault: true,
177
+ fieldWrapper: {
178
+ wrapField(value) {
179
+ return UInt64Value.createComplete({ value: value ?? undefined });
180
+ },
181
+ unwrapField(msg) {
182
+ return msg.value;
183
+ },
184
+ },
145
185
  }, UInt64Value_Wkt);
146
186
  // Int32Value_Wkt contains the well-known-type overrides for Int32Value.
147
187
  const Int32Value_Wkt = {
@@ -150,7 +190,9 @@ const Int32Value_Wkt = {
150
190
  },
151
191
  fromJson(json, _options) {
152
192
  try {
153
- return { value: jsonReadScalar(ScalarType.INT32, json, LongType.BIGINT) };
193
+ return {
194
+ value: jsonReadScalar(ScalarType.INT32, json, LongType.BIGINT),
195
+ };
154
196
  }
155
197
  catch (e) {
156
198
  let m = `cannot decode message google.protobuf.Int32Value from JSON"`;
@@ -168,6 +210,14 @@ export const Int32Value = createMessageType({
168
210
  { no: 1, name: "value", kind: "scalar", T: ScalarType.INT32 },
169
211
  ],
170
212
  packedByDefault: true,
213
+ fieldWrapper: {
214
+ wrapField(value) {
215
+ return Int32Value.createComplete({ value: value ?? undefined });
216
+ },
217
+ unwrapField(msg) {
218
+ return msg.value;
219
+ },
220
+ },
171
221
  }, Int32Value_Wkt);
172
222
  // UInt32Value_Wkt contains the well-known-type overrides for UInt32Value.
173
223
  const UInt32Value_Wkt = {
@@ -176,7 +226,9 @@ const UInt32Value_Wkt = {
176
226
  },
177
227
  fromJson(json, _options) {
178
228
  try {
179
- return { value: jsonReadScalar(ScalarType.UINT32, json, LongType.BIGINT) };
229
+ return {
230
+ value: jsonReadScalar(ScalarType.UINT32, json, LongType.BIGINT),
231
+ };
180
232
  }
181
233
  catch (e) {
182
234
  let m = `cannot decode message google.protobuf.UInt32Value from JSON"`;
@@ -194,6 +246,14 @@ export const UInt32Value = createMessageType({
194
246
  { no: 1, name: "value", kind: "scalar", T: ScalarType.UINT32 },
195
247
  ],
196
248
  packedByDefault: true,
249
+ fieldWrapper: {
250
+ wrapField(value) {
251
+ return UInt32Value.createComplete({ value: value ?? undefined });
252
+ },
253
+ unwrapField(msg) {
254
+ return msg.value;
255
+ },
256
+ },
197
257
  }, UInt32Value_Wkt);
198
258
  // BoolValue_Wkt contains the well-known-type overrides for BoolValue.
199
259
  const BoolValue_Wkt = {
@@ -202,7 +262,9 @@ const BoolValue_Wkt = {
202
262
  },
203
263
  fromJson(json, _options) {
204
264
  try {
205
- return { value: jsonReadScalar(ScalarType.BOOL, json, LongType.BIGINT) };
265
+ return {
266
+ value: jsonReadScalar(ScalarType.BOOL, json, LongType.BIGINT),
267
+ };
206
268
  }
207
269
  catch (e) {
208
270
  let m = `cannot decode message google.protobuf.BoolValue from JSON"`;
@@ -220,6 +282,14 @@ export const BoolValue = createMessageType({
220
282
  { no: 1, name: "value", kind: "scalar", T: ScalarType.BOOL },
221
283
  ],
222
284
  packedByDefault: true,
285
+ fieldWrapper: {
286
+ wrapField(value) {
287
+ return BoolValue.createComplete({ value: value ?? undefined });
288
+ },
289
+ unwrapField(msg) {
290
+ return msg.value;
291
+ },
292
+ },
223
293
  }, BoolValue_Wkt);
224
294
  // StringValue_Wkt contains the well-known-type overrides for StringValue.
225
295
  const StringValue_Wkt = {
@@ -228,7 +298,9 @@ const StringValue_Wkt = {
228
298
  },
229
299
  fromJson(json, _options) {
230
300
  try {
231
- return { value: jsonReadScalar(ScalarType.STRING, json, LongType.BIGINT) };
301
+ return {
302
+ value: jsonReadScalar(ScalarType.STRING, json, LongType.BIGINT),
303
+ };
232
304
  }
233
305
  catch (e) {
234
306
  let m = `cannot decode message google.protobuf.StringValue from JSON"`;
@@ -246,6 +318,14 @@ export const StringValue = createMessageType({
246
318
  { no: 1, name: "value", kind: "scalar", T: ScalarType.STRING },
247
319
  ],
248
320
  packedByDefault: true,
321
+ fieldWrapper: {
322
+ wrapField(value) {
323
+ return StringValue.createComplete({ value: value ?? undefined });
324
+ },
325
+ unwrapField(msg) {
326
+ return msg.value;
327
+ },
328
+ },
249
329
  }, StringValue_Wkt);
250
330
  // BytesValue_Wkt contains the well-known-type overrides for BytesValue.
251
331
  const BytesValue_Wkt = {
@@ -254,7 +334,9 @@ const BytesValue_Wkt = {
254
334
  },
255
335
  fromJson(json, _options) {
256
336
  try {
257
- return { value: jsonReadScalar(ScalarType.BYTES, json, LongType.BIGINT) };
337
+ return {
338
+ value: jsonReadScalar(ScalarType.BYTES, json, LongType.BIGINT),
339
+ };
258
340
  }
259
341
  catch (e) {
260
342
  let m = `cannot decode message google.protobuf.BytesValue from JSON"`;
@@ -272,4 +354,12 @@ export const BytesValue = createMessageType({
272
354
  { no: 1, name: "value", kind: "scalar", T: ScalarType.BYTES },
273
355
  ],
274
356
  packedByDefault: true,
357
+ fieldWrapper: {
358
+ wrapField(value) {
359
+ return BytesValue.createComplete({ value: value ?? undefined });
360
+ },
361
+ unwrapField(msg) {
362
+ return msg.value;
363
+ },
364
+ },
275
365
  }, BytesValue_Wkt);
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export { Message, CompleteMessage, AnyMessage, MessageType, Field, compareMessages, createMessageType, } from "./message.js";
2
2
  export { ServiceType, MethodInfo, MethodInfoUnary, MethodInfoServerStreaming, MethodInfoClientStreaming, MethodInfoBiDiStreaming, MethodKind, MethodIdempotency, } from "./service-type.js";
3
3
  export { isCompleteMessage, isCompleteField } from "./is-message.js";
4
- export { newFieldList, FieldList, PartialFieldInfo, FieldInfo, OneofInfo, fieldJsonName, } from "./field.js";
4
+ export { FieldList, PartialFieldInfo, FieldInfo, ScalarFieldInfo, EnumFieldInfo, MessageFieldInfo, MapFieldInfo, OneofInfo, newFieldList, fieldJsonName, } from "./field.js";
5
5
  export { applyPartialMessage } from "./partial.js";
6
6
  export { scalarEquals, scalarZeroValue, isScalarZeroValue, ScalarType, ScalarValue, LongType, } from "./scalar.js";
7
- export { createEnumType, normalizeEnumValue } from "./enum.js";
7
+ export { EnumType, EnumValueInfo, createEnumType, enumInfoZeroValue, enumZeroValue, enumDescZeroValue, normalizeEnumValue, } from "./enum.js";
8
8
  export { localName, localFieldName, localOneofName, findEnumSharedPrefix, camelToSnakeCase, protoCamelCase, safeObjectProperty, safeIdentifier, } from "./names.js";
9
9
  export { int64FromString, int64ToString, uInt64ToString } from "./varint.js";
10
10
  export { protoInt64 } from "./proto-int64.js";
@@ -15,3 +15,4 @@ export { DescComments, AnyDesc, DescEnum, DescEnumValue, DescExtension, DescFiel
15
15
  export { jsonReadEnum, jsonReadField, jsonReadMapKey, jsonReadScalar, jsonReadMessage, jsonWriteEnum, jsonWriteField, jsonWriteScalar, jsonWriteMessage, jsonDebugValue, JsonValue, JsonObject, JsonReadOptions, jsonMakeReadOptions, JsonWriteOptions, JsonWriteStringOptions, jsonMakeWriteOptions, } from "./json.js";
16
16
  export { binaryReadField, binaryReadMapEntry, binaryReadScalar, binaryReadScalarLTString, binaryReadMessage, binaryWriteField, binaryWriteScalar, binaryWritePacked, binaryWriteMapEntry, binaryWriteMessage, binaryMakeReadOptions, binaryMakeWriteOptions, BinaryReadOptions, BinaryWriteOptions, } from "./binary.js";
17
17
  export type { IMessageTypeRegistry, IServiceTypeRegistry, IEnumTypeRegistry, } from "./type-registry.js";
18
+ export { compareFieldZeroValue, isMessageZeroValue, getFieldZeroValue, } from "./zero-value.js";
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  export { compareMessages, createMessageType, } from "./message.js";
2
2
  export { MethodKind, MethodIdempotency, } from "./service-type.js";
3
3
  export { isCompleteMessage, isCompleteField } from "./is-message.js";
4
- export { newFieldList, FieldList, fieldJsonName, } from "./field.js";
4
+ export { FieldList, newFieldList, fieldJsonName, } from "./field.js";
5
5
  export { applyPartialMessage } from "./partial.js";
6
6
  export { scalarEquals, scalarZeroValue, isScalarZeroValue, ScalarType, LongType, } from "./scalar.js";
7
- export { createEnumType, normalizeEnumValue } from "./enum.js";
7
+ export { createEnumType, enumInfoZeroValue, enumZeroValue, enumDescZeroValue, normalizeEnumValue, } from "./enum.js";
8
8
  export { localName, localFieldName, localOneofName, findEnumSharedPrefix, camelToSnakeCase, protoCamelCase, safeObjectProperty, safeIdentifier, } from "./names.js";
9
9
  export { int64FromString, int64ToString, uInt64ToString } from "./varint.js";
10
10
  export { protoInt64 } from "./proto-int64.js";
@@ -13,3 +13,4 @@ export { protoDouble } from "./proto-double.js";
13
13
  export { Timestamp, Duration, Any, Empty, DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value, BoolValue, StringValue, BytesValue, Value, NullValue, ListValue, Struct, } from "./google/index.js";
14
14
  export { jsonReadEnum, jsonReadField, jsonReadMapKey, jsonReadScalar, jsonReadMessage, jsonWriteEnum, jsonWriteField, jsonWriteScalar, jsonWriteMessage, jsonDebugValue, jsonMakeReadOptions, jsonMakeWriteOptions, } from "./json.js";
15
15
  export { binaryReadField, binaryReadMapEntry, binaryReadScalar, binaryReadScalarLTString, binaryReadMessage, binaryWriteField, binaryWriteScalar, binaryWritePacked, binaryWriteMapEntry, binaryWriteMessage, binaryMakeReadOptions, binaryMakeWriteOptions, } from "./binary.js";
16
+ export { compareFieldZeroValue, isMessageZeroValue, getFieldZeroValue, } from "./zero-value.js";
package/dist/message.d.ts CHANGED
@@ -38,10 +38,14 @@ export interface MessageType<T extends Message<T> = AnyMessage> {
38
38
  * When used as a field, unwrap this message to a simple value.
39
39
  */
40
40
  readonly fieldWrapper?: FieldWrapper<T>;
41
+ /**
42
+ * Create a new empty instance of this message applying the partial message.
43
+ */
44
+ create(partial?: Message<T>): Message<T>;
41
45
  /**
42
46
  * Create a new instance of this message with zero values for fields.
43
47
  */
44
- create(partial?: Message<T>): CompleteMessage<T>;
48
+ createComplete(partial?: Message<T>): CompleteMessage<T>;
45
49
  /**
46
50
  * Create a deep copy.
47
51
  */
@@ -109,6 +113,6 @@ export declare function createMessageType<T extends Message<T>, E extends Record
109
113
  export declare function compareMessages<T extends Message<T>>(fields: FieldList, a: T | undefined | null, b: T | undefined | null): boolean;
110
114
  export declare function cloneMessage<T extends Message<T>>(message: T, fields: FieldList): T;
111
115
  /**
112
- * createMessage recursively builds a message filled with zero values based on the given FieldList.
116
+ * createCompleteMessage recursively builds a message filled with zero values based on the given FieldList.
113
117
  */
114
- export declare function createMessage<T extends Message<T>>(fields: FieldList): CompleteMessage<T>;
118
+ export declare function createCompleteMessage<T extends Message<T>>(fields: FieldList): CompleteMessage<T>;
package/dist/message.js CHANGED
@@ -30,7 +30,12 @@ export function createMessageType(params, exts) {
30
30
  fields,
31
31
  fieldWrapper,
32
32
  create(partial) {
33
- const message = createMessage(fields);
33
+ const message = Object.create(null);
34
+ applyPartialMessage(partial, message, fields);
35
+ return message;
36
+ },
37
+ createComplete(partial) {
38
+ const message = createCompleteMessage(fields);
34
39
  applyPartialMessage(partial, message, fields);
35
40
  return message;
36
41
  },
@@ -218,9 +223,9 @@ export function cloneMessage(message, fields) {
218
223
  return clone;
219
224
  }
220
225
  /**
221
- * createMessage recursively builds a message filled with zero values based on the given FieldList.
226
+ * createCompleteMessage recursively builds a message filled with zero values based on the given FieldList.
222
227
  */
223
- export function createMessage(fields) {
228
+ export function createCompleteMessage(fields) {
224
229
  const message = {};
225
230
  for (const field of fields.list()) {
226
231
  const fieldKind = field.kind;
@@ -278,7 +283,7 @@ export function createMessage(fields) {
278
283
  message[field.localName] = [];
279
284
  }
280
285
  else {
281
- message[field.localName] = createMessage(messageType.fields);
286
+ message[field.localName] = createCompleteMessage(messageType.fields);
282
287
  }
283
288
  break;
284
289
  case "map":
package/dist/names.d.ts CHANGED
@@ -41,3 +41,5 @@ export declare const safeObjectProperty: (name: string) => string;
41
41
  * Names that can be used for identifiers or class properties
42
42
  */
43
43
  export declare const safeIdentifier: (name: string) => string;
44
+ export declare function checkSanitizeKey(key: string): boolean;
45
+ export declare function throwSanitizeKey(key: string): void;
package/dist/names.js CHANGED
@@ -32,12 +32,7 @@ export function localName(desc) {
32
32
  const pkg = desc.file.proto.package;
33
33
  const offset = pkg === undefined ? 0 : pkg.length + 1;
34
34
  const name = desc.typeName.substring(offset).replace(/\./g, "_");
35
- // For services, we only care about safe identifiers, not safe object properties,
36
- // but we have shipped v1 with a bug that respected object properties, and we
37
- // do not want to introduce a breaking change, so we continue to escape for
38
- // safe object properties.
39
- // See https://github.com/bufbuild/protobuf-es/pull/391
40
- return safeObjectProperty(safeIdentifier(name));
35
+ return safeIdentifier(name);
41
36
  }
42
37
  case "enum_value": {
43
38
  let name = desc.name;
@@ -219,20 +214,7 @@ const reservedObjectProperties = new Set([
219
214
  * Names that cannot be used for object properties because they are reserved
220
215
  * by the runtime.
221
216
  */
222
- const reservedMessageProperties = new Set([
223
- // names reserved by the runtime
224
- "getType",
225
- "clone",
226
- "equals",
227
- "fromBinary",
228
- "fromJson",
229
- "fromJsonString",
230
- "toBinary",
231
- "toJson",
232
- "toJsonString",
233
- // names reserved by the runtime for the future
234
- "toObject",
235
- ]);
217
+ const reservedMessageProperties = new Set(["__proto__"]);
236
218
  const fallback = (name) => `${name}$`;
237
219
  /**
238
220
  * Will wrap names that are Object prototype properties or names reserved
@@ -263,3 +245,14 @@ export const safeIdentifier = (name) => {
263
245
  }
264
246
  return name;
265
247
  };
248
+ export function checkSanitizeKey(key) {
249
+ return typeof key === "string" && key !== "__proto__";
250
+ }
251
+ export function throwSanitizeKey(key) {
252
+ if (typeof key !== "string") {
253
+ throw new Error("illegal non-string object key: " + typeof key);
254
+ }
255
+ if (!checkSanitizeKey(key)) {
256
+ throw new Error("illegal object key: " + key);
257
+ }
258
+ }
package/dist/partial.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { FieldList } from "./field.js";
1
+ import { FieldList, MapValueInfo } from "./field.js";
2
2
  import { Message } from "./message.js";
3
3
  export declare function applyPartialMessage<T extends Message<T>>(source: Message<T> | undefined, target: Message<T>, fields: FieldList): void;
4
+ export declare function applyPartialMap(sourceMap: Record<string, any> | undefined, targetMap: Record<string, any>, value: MapValueInfo): void;