@bufbuild/protobuf 2.0.0-alpha.4 → 2.0.0-beta.1
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/dist/cjs/clone.d.ts +1 -1
- package/dist/cjs/clone.js +5 -16
- package/dist/cjs/codegenv1/embed.js +25 -25
- package/dist/cjs/codegenv1/enum.d.ts +2 -1
- package/dist/cjs/codegenv1/file.js +1 -1
- package/dist/cjs/codegenv1/message.d.ts +2 -1
- package/dist/cjs/codegenv1/scalar.d.ts +4 -0
- package/dist/cjs/codegenv1/scalar.js +30 -1
- package/dist/cjs/codegenv1/symbols.d.ts +10 -0
- package/dist/cjs/codegenv1/symbols.js +2 -0
- package/dist/cjs/codegenv1/types.d.ts +7 -5
- package/dist/cjs/codegenv1/types.js +2 -1
- package/dist/cjs/create.d.ts +1 -1
- package/dist/cjs/create.js +47 -20
- package/dist/cjs/equals.d.ts +1 -1
- package/dist/cjs/equals.js +8 -15
- package/dist/cjs/from-binary.d.ts +2 -2
- package/dist/cjs/from-binary.js +6 -6
- package/dist/cjs/from-json.d.ts +14 -6
- package/dist/cjs/from-json.js +35 -33
- package/dist/cjs/is-message.d.ts +1 -1
- package/dist/cjs/is-message.js +3 -3
- package/dist/cjs/reflect/reflect-types.d.ts +13 -42
- package/dist/cjs/reflect/reflect.d.ts +29 -18
- package/dist/cjs/reflect/reflect.js +169 -45
- package/dist/cjs/reflect/scalar.d.ts +1 -1
- package/dist/cjs/registry.d.ts +18 -2
- package/dist/cjs/registry.js +62 -60
- package/dist/cjs/to-binary.d.ts +1 -1
- package/dist/cjs/to-binary.js +2 -2
- package/dist/cjs/to-json.d.ts +14 -4
- package/dist/cjs/to-json.js +26 -13
- package/dist/cjs/types.d.ts +9 -0
- package/dist/cjs/wkt/any.d.ts +7 -7
- package/dist/cjs/wkt/any.js +5 -5
- package/dist/cjs/wkt/gen/google/protobuf/any_pb.d.ts +9 -3
- package/dist/cjs/wkt/gen/google/protobuf/any_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/api_pb.d.ts +88 -9
- package/dist/cjs/wkt/gen/google/protobuf/api_pb.js +8 -8
- package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +107 -11
- package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.js +11 -11
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +1005 -92
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.js +86 -86
- package/dist/cjs/wkt/gen/google/protobuf/duration_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/duration_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/empty_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/empty_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.d.ts +12 -3
- package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/struct_pb.d.ts +25 -8
- package/dist/cjs/wkt/gen/google/protobuf/struct_pb.js +9 -9
- package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/type_pb.d.ts +165 -16
- package/dist/cjs/wkt/gen/google/protobuf/type_pb.js +15 -15
- package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.d.ts +55 -19
- package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.js +20 -20
- package/dist/cjs/wkt/timestamp.js +1 -2
- package/dist/esm/clone.d.ts +1 -1
- package/dist/esm/clone.js +5 -16
- package/dist/esm/codegenv1/embed.js +26 -26
- package/dist/esm/codegenv1/enum.d.ts +2 -1
- package/dist/esm/codegenv1/file.js +2 -2
- package/dist/esm/codegenv1/message.d.ts +2 -1
- package/dist/esm/codegenv1/scalar.d.ts +4 -0
- package/dist/esm/codegenv1/scalar.js +28 -0
- package/dist/esm/codegenv1/symbols.d.ts +10 -0
- package/dist/esm/codegenv1/symbols.js +2 -0
- package/dist/esm/codegenv1/types.d.ts +7 -5
- package/dist/esm/codegenv1/types.js +2 -1
- package/dist/esm/create.d.ts +1 -1
- package/dist/esm/create.js +47 -20
- package/dist/esm/equals.d.ts +1 -1
- package/dist/esm/equals.js +8 -15
- package/dist/esm/from-binary.d.ts +2 -2
- package/dist/esm/from-binary.js +6 -6
- package/dist/esm/from-json.d.ts +14 -6
- package/dist/esm/from-json.js +33 -33
- package/dist/esm/is-message.d.ts +1 -1
- package/dist/esm/is-message.js +3 -3
- package/dist/esm/reflect/reflect-types.d.ts +13 -42
- package/dist/esm/reflect/reflect-types.js +0 -1
- package/dist/esm/reflect/reflect.d.ts +29 -18
- package/dist/esm/reflect/reflect.js +170 -46
- package/dist/esm/reflect/scalar.d.ts +1 -1
- package/dist/esm/registry.d.ts +18 -2
- package/dist/esm/registry.js +60 -59
- package/dist/esm/to-binary.d.ts +1 -1
- package/dist/esm/to-binary.js +2 -2
- package/dist/esm/to-json.d.ts +14 -4
- package/dist/esm/to-json.js +24 -12
- package/dist/esm/types.d.ts +9 -0
- package/dist/esm/wkt/any.d.ts +7 -7
- package/dist/esm/wkt/any.js +6 -6
- package/dist/esm/wkt/gen/google/protobuf/any_pb.d.ts +9 -3
- package/dist/esm/wkt/gen/google/protobuf/any_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/api_pb.d.ts +88 -9
- package/dist/esm/wkt/gen/google/protobuf/api_pb.js +9 -9
- package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +107 -11
- package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.js +11 -11
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +1005 -92
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +84 -84
- package/dist/esm/wkt/gen/google/protobuf/duration_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/duration_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/empty_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/empty_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/source_context_pb.d.ts +12 -3
- package/dist/esm/wkt/gen/google/protobuf/source_context_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/struct_pb.d.ts +25 -8
- package/dist/esm/wkt/gen/google/protobuf/struct_pb.js +8 -8
- package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/type_pb.d.ts +165 -16
- package/dist/esm/wkt/gen/google/protobuf/type_pb.js +16 -16
- package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.d.ts +55 -19
- package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.js +19 -19
- package/dist/esm/wkt/timestamp.js +2 -3
- package/package.json +2 -2
package/dist/cjs/clone.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import { type DescMessage } from "./descriptors.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Create a deep copy of a message, including extensions and unknown fields.
|
|
5
5
|
*/
|
|
6
|
-
export declare function clone<Desc extends DescMessage>(
|
|
6
|
+
export declare function clone<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>): MessageShape<Desc>;
|
package/dist/cjs/clone.js
CHANGED
|
@@ -20,9 +20,8 @@ const guard_js_1 = require("./reflect/guard.js");
|
|
|
20
20
|
/**
|
|
21
21
|
* Create a deep copy of a message, including extensions and unknown fields.
|
|
22
22
|
*/
|
|
23
|
-
function clone(
|
|
24
|
-
return cloneReflect((0, reflect_js_1.reflect)(
|
|
25
|
-
.message;
|
|
23
|
+
function clone(schema, message) {
|
|
24
|
+
return cloneReflect((0, reflect_js_1.reflect)(schema, message)).message;
|
|
26
25
|
}
|
|
27
26
|
exports.clone = clone;
|
|
28
27
|
function cloneReflect(i) {
|
|
@@ -33,31 +32,21 @@ function cloneReflect(i) {
|
|
|
33
32
|
}
|
|
34
33
|
switch (f.fieldKind) {
|
|
35
34
|
default: {
|
|
36
|
-
|
|
37
|
-
if (err) {
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
35
|
+
o.set(f, cloneSingular(f, i.get(f)));
|
|
40
36
|
break;
|
|
41
37
|
}
|
|
42
38
|
case "list":
|
|
43
39
|
// eslint-disable-next-line no-case-declarations
|
|
44
40
|
const list = o.get(f);
|
|
45
41
|
for (const item of i.get(f)) {
|
|
46
|
-
|
|
47
|
-
if (err) {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
42
|
+
list.add(cloneSingular(f, item));
|
|
50
43
|
}
|
|
51
44
|
break;
|
|
52
45
|
case "map":
|
|
53
46
|
// eslint-disable-next-line no-case-declarations
|
|
54
47
|
const map = o.get(f);
|
|
55
48
|
for (const entry of i.get(f).entries()) {
|
|
56
|
-
|
|
57
|
-
const err = map.set(entry[0], cloneSingular(f, entry[1]));
|
|
58
|
-
if (err) {
|
|
59
|
-
throw err;
|
|
60
|
-
}
|
|
49
|
+
map.set(entry[0], cloneSingular(f, entry[1]));
|
|
61
50
|
}
|
|
62
51
|
break;
|
|
63
52
|
}
|
|
@@ -30,14 +30,14 @@ function embedFileDesc(file) {
|
|
|
30
30
|
const embed = {
|
|
31
31
|
bootable: false,
|
|
32
32
|
proto() {
|
|
33
|
-
const stripped = (0, clone_js_1.clone)(descriptor_pb_js_1.
|
|
34
|
-
(0, fields_js_1.clearField)(stripped, descriptor_pb_js_1.
|
|
35
|
-
(0, fields_js_1.clearField)(stripped, descriptor_pb_js_1.
|
|
33
|
+
const stripped = (0, clone_js_1.clone)(descriptor_pb_js_1.FileDescriptorProtoSchema, file);
|
|
34
|
+
(0, fields_js_1.clearField)(stripped, descriptor_pb_js_1.FileDescriptorProtoSchema.field.dependency);
|
|
35
|
+
(0, fields_js_1.clearField)(stripped, descriptor_pb_js_1.FileDescriptorProtoSchema.field.sourceCodeInfo);
|
|
36
36
|
stripped.messageType.map(stripJsonNames);
|
|
37
37
|
return stripped;
|
|
38
38
|
},
|
|
39
39
|
base64() {
|
|
40
|
-
const bytes = (0, to_binary_js_1.toBinary)(descriptor_pb_js_1.
|
|
40
|
+
const bytes = (0, to_binary_js_1.toBinary)(descriptor_pb_js_1.FileDescriptorProtoSchema, this.proto());
|
|
41
41
|
return (0, base64_encoding_js_1.base64Encode)(bytes, "std_raw");
|
|
42
42
|
},
|
|
43
43
|
};
|
|
@@ -50,7 +50,7 @@ exports.embedFileDesc = embedFileDesc;
|
|
|
50
50
|
function stripJsonNames(d) {
|
|
51
51
|
for (const f of d.field) {
|
|
52
52
|
if (f.jsonName === (0, names_js_1.protoCamelCase)(f.name)) {
|
|
53
|
-
(0, fields_js_1.clearField)(f, descriptor_pb_js_1.
|
|
53
|
+
(0, fields_js_1.clearField)(f, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.jsonName);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
for (const n of d.nestedType) {
|
|
@@ -161,27 +161,27 @@ function createDescriptorBoot(proto) {
|
|
|
161
161
|
return b;
|
|
162
162
|
}
|
|
163
163
|
function createFieldDescriptorBoot(proto) {
|
|
164
|
-
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
165
|
-
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
166
|
-
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
167
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
168
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
164
|
+
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.name));
|
|
165
|
+
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.number));
|
|
166
|
+
assert((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.type));
|
|
167
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.oneofIndex));
|
|
168
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.jsonName) ||
|
|
169
169
|
proto.jsonName === (0, names_js_1.protoCamelCase)(proto.name));
|
|
170
170
|
const b = {
|
|
171
171
|
name: proto.name,
|
|
172
172
|
number: proto.number,
|
|
173
173
|
type: proto.type,
|
|
174
174
|
};
|
|
175
|
-
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
175
|
+
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.label)) {
|
|
176
176
|
b.label = proto.label;
|
|
177
177
|
}
|
|
178
|
-
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
178
|
+
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.typeName)) {
|
|
179
179
|
b.typeName = proto.typeName;
|
|
180
180
|
}
|
|
181
|
-
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
181
|
+
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.extendee)) {
|
|
182
182
|
b.extendee = proto.extendee;
|
|
183
183
|
}
|
|
184
|
-
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
184
|
+
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldDescriptorProtoSchema.field.defaultValue)) {
|
|
185
185
|
b.defaultValue = proto.defaultValue;
|
|
186
186
|
}
|
|
187
187
|
if (proto.options) {
|
|
@@ -191,19 +191,19 @@ function createFieldDescriptorBoot(proto) {
|
|
|
191
191
|
}
|
|
192
192
|
function createFieldOptionsBoot(proto) {
|
|
193
193
|
const b = {};
|
|
194
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
195
|
-
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
194
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.ctype));
|
|
195
|
+
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.packed)) {
|
|
196
196
|
b.packed = proto.packed;
|
|
197
197
|
}
|
|
198
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
199
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
200
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
201
|
-
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
198
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.jstype));
|
|
199
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.lazy));
|
|
200
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.unverifiedLazy));
|
|
201
|
+
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.deprecated)) {
|
|
202
202
|
b.deprecated = proto.deprecated;
|
|
203
203
|
}
|
|
204
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
205
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
206
|
-
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
204
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.weak));
|
|
205
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.debugRedact));
|
|
206
|
+
if ((0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.retention)) {
|
|
207
207
|
b.retention = proto.retention;
|
|
208
208
|
}
|
|
209
209
|
if (proto.targets.length) {
|
|
@@ -215,8 +215,8 @@ function createFieldOptionsBoot(proto) {
|
|
|
215
215
|
edition: d.edition,
|
|
216
216
|
}));
|
|
217
217
|
}
|
|
218
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
219
|
-
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.
|
|
218
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.features));
|
|
219
|
+
assert(!(0, fields_js_1.isFieldSet)(proto, descriptor_pb_js_1.FieldOptionsSchema.field.uninterpretedOption));
|
|
220
220
|
return b;
|
|
221
221
|
}
|
|
222
222
|
function createEnumDescriptorBoot(proto) {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { DescEnum, DescFile } from "../descriptors.js";
|
|
2
2
|
import type { GenDescEnum } from "./types.js";
|
|
3
|
+
import type { JsonValue } from "../json-value.js";
|
|
3
4
|
/**
|
|
4
5
|
* Hydrate an enum descriptor.
|
|
5
6
|
*
|
|
6
7
|
* @private
|
|
7
8
|
*/
|
|
8
|
-
export declare function enumDesc<Shape>(file: DescFile, path: number, ...paths: number[]): GenDescEnum<Shape>;
|
|
9
|
+
export declare function enumDesc<Shape, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]): GenDescEnum<Shape, JsonType>;
|
|
9
10
|
/**
|
|
10
11
|
* Construct a TypeScript enum object at runtime from a descriptor.
|
|
11
12
|
*/
|
|
@@ -26,7 +26,7 @@ const from_binary_js_1 = require("../from-binary.js");
|
|
|
26
26
|
*/
|
|
27
27
|
function fileDesc(b64, imports) {
|
|
28
28
|
var _a;
|
|
29
|
-
const root = (0, from_binary_js_1.fromBinary)(descriptor_pb_js_1.
|
|
29
|
+
const root = (0, from_binary_js_1.fromBinary)(descriptor_pb_js_1.FileDescriptorProtoSchema, (0, base64_encoding_js_1.base64Decode)(b64));
|
|
30
30
|
root.messageType.forEach(restore_json_names_js_1.restoreJsonNames);
|
|
31
31
|
root.dependency = (_a = imports === null || imports === void 0 ? void 0 : imports.map((f) => f.proto.name)) !== null && _a !== void 0 ? _a : [];
|
|
32
32
|
const reg = (0, registry_js_1.createFileRegistry)(root, (protoFileName) => imports === null || imports === void 0 ? void 0 : imports.find((f) => f.proto.name === protoFileName));
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
2
|
import type { DescFile } from "../descriptors.js";
|
|
3
3
|
import type { GenDescMessage } from "./types.js";
|
|
4
|
+
import type { JsonValue } from "../json-value.js";
|
|
4
5
|
/**
|
|
5
6
|
* Hydrate a message descriptor.
|
|
6
7
|
*
|
|
7
8
|
* @private
|
|
8
9
|
*/
|
|
9
|
-
export declare function messageDesc<Shape extends Message>(file: DescFile, path: number, ...paths: number[]): GenDescMessage<Shape>;
|
|
10
|
+
export declare function messageDesc<Shape extends Message, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]): GenDescMessage<Shape, JsonType>;
|
|
@@ -3,3 +3,7 @@ import { ScalarType } from "../descriptors.js";
|
|
|
3
3
|
* Return the TypeScript type (as a string) for the given scalar type.
|
|
4
4
|
*/
|
|
5
5
|
export declare function scalarTypeScriptType(scalar: ScalarType, longAsString: boolean): "string" | "boolean" | "bigint" | "bigint | string" | "Uint8Array" | "number";
|
|
6
|
+
/**
|
|
7
|
+
* Return the JSON type (as a string) for the given scalar type.
|
|
8
|
+
*/
|
|
9
|
+
export declare function scalarJsonType(scalar: ScalarType): "string" | "boolean" | "number" | `number | "NaN" | "Infinity" | "-Infinity"`;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.scalarTypeScriptType = void 0;
|
|
16
|
+
exports.scalarJsonType = exports.scalarTypeScriptType = void 0;
|
|
17
17
|
const descriptors_js_1 = require("../descriptors.js");
|
|
18
18
|
/**
|
|
19
19
|
* Return the TypeScript type (as a string) for the given scalar type.
|
|
@@ -37,3 +37,32 @@ function scalarTypeScriptType(scalar, longAsString) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.scalarTypeScriptType = scalarTypeScriptType;
|
|
40
|
+
/**
|
|
41
|
+
* Return the JSON type (as a string) for the given scalar type.
|
|
42
|
+
*/
|
|
43
|
+
function scalarJsonType(scalar) {
|
|
44
|
+
switch (scalar) {
|
|
45
|
+
case descriptors_js_1.ScalarType.DOUBLE:
|
|
46
|
+
case descriptors_js_1.ScalarType.FLOAT:
|
|
47
|
+
return `number | "NaN" | "Infinity" | "-Infinity"`;
|
|
48
|
+
case descriptors_js_1.ScalarType.UINT64:
|
|
49
|
+
case descriptors_js_1.ScalarType.SFIXED64:
|
|
50
|
+
case descriptors_js_1.ScalarType.FIXED64:
|
|
51
|
+
case descriptors_js_1.ScalarType.SINT64:
|
|
52
|
+
case descriptors_js_1.ScalarType.INT64:
|
|
53
|
+
return "string";
|
|
54
|
+
case descriptors_js_1.ScalarType.INT32:
|
|
55
|
+
case descriptors_js_1.ScalarType.FIXED32:
|
|
56
|
+
case descriptors_js_1.ScalarType.UINT32:
|
|
57
|
+
case descriptors_js_1.ScalarType.SFIXED32:
|
|
58
|
+
case descriptors_js_1.ScalarType.SINT32:
|
|
59
|
+
return "number";
|
|
60
|
+
case descriptors_js_1.ScalarType.STRING:
|
|
61
|
+
return "string";
|
|
62
|
+
case descriptors_js_1.ScalarType.BOOL:
|
|
63
|
+
return "boolean";
|
|
64
|
+
case descriptors_js_1.ScalarType.BYTES:
|
|
65
|
+
return "string";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.scalarJsonType = scalarJsonType;
|
|
@@ -60,6 +60,16 @@ export declare const symbols: {
|
|
|
60
60
|
readonly bootstrapWktFrom: "../../proto-int64.js";
|
|
61
61
|
readonly from: "@bufbuild/protobuf";
|
|
62
62
|
};
|
|
63
|
+
readonly JsonValue: {
|
|
64
|
+
readonly typeOnly: true;
|
|
65
|
+
readonly bootstrapWktFrom: "../../json-value.js";
|
|
66
|
+
readonly from: "@bufbuild/protobuf";
|
|
67
|
+
};
|
|
68
|
+
readonly JsonObject: {
|
|
69
|
+
readonly typeOnly: true;
|
|
70
|
+
readonly bootstrapWktFrom: "../../json-value.js";
|
|
71
|
+
readonly from: "@bufbuild/protobuf";
|
|
72
|
+
};
|
|
63
73
|
readonly codegen: {
|
|
64
74
|
readonly boot: {
|
|
65
75
|
readonly typeOnly: false;
|
|
@@ -50,6 +50,8 @@ exports.symbols = {
|
|
|
50
50
|
toJson: { typeOnly: false, bootstrapWktFrom: "../../to-json.js", from: exports.packageName },
|
|
51
51
|
toJsonString: { typeOnly: false, bootstrapWktFrom: "../../to-json.js", from: exports.packageName },
|
|
52
52
|
protoInt64: { typeOnly: false, bootstrapWktFrom: "../../proto-int64.js", from: exports.packageName },
|
|
53
|
+
JsonValue: { typeOnly: true, bootstrapWktFrom: "../../json-value.js", from: exports.packageName },
|
|
54
|
+
JsonObject: { typeOnly: true, bootstrapWktFrom: "../../json-value.js", from: exports.packageName },
|
|
53
55
|
codegen: {
|
|
54
56
|
boot: { typeOnly: false, bootstrapWktFrom: "../../codegenv1/boot.js", from: exports.packageName + "/codegenv1" },
|
|
55
57
|
fileDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv1/file.js", from: exports.packageName + "/codegenv1" },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
2
|
import type { DescEnum, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescService } from "../descriptors.js";
|
|
3
|
+
import type { JsonValue } from "../json-value.js";
|
|
3
4
|
/**
|
|
4
5
|
* Describes a protobuf source file.
|
|
5
6
|
*
|
|
@@ -14,9 +15,9 @@ export type GenDescFile = DescFile;
|
|
|
14
15
|
*
|
|
15
16
|
* @private
|
|
16
17
|
*/
|
|
17
|
-
export type GenDescMessage<RuntimeShape extends Message> = Omit<DescMessage, "field"> & {
|
|
18
|
+
export type GenDescMessage<RuntimeShape extends Message, JsonType = JsonValue> = Omit<DescMessage, "field"> & {
|
|
18
19
|
field: Record<MessageFieldNames<RuntimeShape>, DescField>;
|
|
19
|
-
} &
|
|
20
|
+
} & brandv1<RuntimeShape, JsonType>;
|
|
20
21
|
/**
|
|
21
22
|
* Describes an enumeration in a protobuf source file.
|
|
22
23
|
*
|
|
@@ -25,7 +26,7 @@ export type GenDescMessage<RuntimeShape extends Message> = Omit<DescMessage, "fi
|
|
|
25
26
|
*
|
|
26
27
|
* @private
|
|
27
28
|
*/
|
|
28
|
-
export type GenDescEnum<RuntimeShape> = DescEnum &
|
|
29
|
+
export type GenDescEnum<RuntimeShape, JsonType extends JsonValue = JsonValue> = DescEnum & brandv1<RuntimeShape, JsonType>;
|
|
29
30
|
/**
|
|
30
31
|
* Describes an extension in a protobuf source file.
|
|
31
32
|
*
|
|
@@ -34,7 +35,7 @@ export type GenDescEnum<RuntimeShape> = DescEnum & brand<RuntimeShape>;
|
|
|
34
35
|
*
|
|
35
36
|
* @private
|
|
36
37
|
*/
|
|
37
|
-
export type GenDescExtension<Extendee extends Message = Message, RuntimeShape = unknown> = DescExtension &
|
|
38
|
+
export type GenDescExtension<Extendee extends Message = Message, RuntimeShape = unknown> = DescExtension & brandv1<Extendee, RuntimeShape>;
|
|
38
39
|
/**
|
|
39
40
|
* Describes a service declaration in a protobuf source file.
|
|
40
41
|
*
|
|
@@ -52,7 +53,8 @@ export type GenDescService<RuntimeShape extends GenDescServiceMethods> = Omit<De
|
|
|
52
53
|
* @private
|
|
53
54
|
*/
|
|
54
55
|
export type GenDescServiceMethods = Record<string, Pick<DescMethod, "input" | "output" | "methodKind">>;
|
|
55
|
-
declare class
|
|
56
|
+
declare class brandv1<A, B = unknown> {
|
|
57
|
+
protected v: "codegenv1";
|
|
56
58
|
protected a: A | boolean;
|
|
57
59
|
protected b: B | boolean;
|
|
58
60
|
}
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
class
|
|
16
|
+
class brandv1 {
|
|
17
17
|
constructor() {
|
|
18
|
+
this.v = "codegenv1";
|
|
18
19
|
this.a = false;
|
|
19
20
|
this.b = false;
|
|
20
21
|
}
|
package/dist/cjs/create.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ import type { MessageInitShape, MessageShape } from "./types.js";
|
|
|
6
6
|
* The second argument is an optional initializer object, where all fields are
|
|
7
7
|
* optional.
|
|
8
8
|
*/
|
|
9
|
-
export declare function create<Desc extends DescMessage>(
|
|
9
|
+
export declare function create<Desc extends DescMessage>(schema: Desc, init?: MessageInitShape<Desc>): MessageShape<Desc>;
|
package/dist/cjs/create.js
CHANGED
|
@@ -22,6 +22,8 @@ const unsafe_js_1 = require("./reflect/unsafe.js");
|
|
|
22
22
|
const wrappers_js_1 = require("./wkt/wrappers.js");
|
|
23
23
|
// bootstrap-inject google.protobuf.Edition.EDITION_PROTO3: const $name: Edition.$localName = $number;
|
|
24
24
|
const EDITION_PROTO3 = 999;
|
|
25
|
+
// bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name: Edition.$localName = $number;
|
|
26
|
+
const EDITION_PROTO2 = 998;
|
|
25
27
|
// bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
|
|
26
28
|
const IMPLICIT = 2;
|
|
27
29
|
/**
|
|
@@ -30,13 +32,13 @@ const IMPLICIT = 2;
|
|
|
30
32
|
* The second argument is an optional initializer object, where all fields are
|
|
31
33
|
* optional.
|
|
32
34
|
*/
|
|
33
|
-
function create(
|
|
34
|
-
if ((0, is_message_js_1.isMessage)(init,
|
|
35
|
+
function create(schema, init) {
|
|
36
|
+
if ((0, is_message_js_1.isMessage)(init, schema)) {
|
|
35
37
|
return init;
|
|
36
38
|
}
|
|
37
|
-
const message = createZeroMessage(
|
|
39
|
+
const message = createZeroMessage(schema);
|
|
38
40
|
if (init !== undefined) {
|
|
39
|
-
initMessage(
|
|
41
|
+
initMessage(schema, message, init);
|
|
40
42
|
}
|
|
41
43
|
return message;
|
|
42
44
|
}
|
|
@@ -66,12 +68,7 @@ function initMessage(messageDesc, message, init) {
|
|
|
66
68
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- no need to convert enum
|
|
67
69
|
switch (field.fieldKind) {
|
|
68
70
|
case "message":
|
|
69
|
-
|
|
70
|
-
value = initScalar(field.message.fields[0], value);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
value = toMessage(value, field.message);
|
|
74
|
-
}
|
|
71
|
+
value = toMessage(field, value);
|
|
75
72
|
break;
|
|
76
73
|
case "scalar":
|
|
77
74
|
value = initScalar(field, value);
|
|
@@ -99,7 +96,7 @@ function initMap(field, value) {
|
|
|
99
96
|
return convertObjectValues(value, toU8Arr);
|
|
100
97
|
}
|
|
101
98
|
if (field.mapKind == "message") {
|
|
102
|
-
return convertObjectValues(value, (val) => toMessage(
|
|
99
|
+
return convertObjectValues(value, (val) => toMessage(field, val));
|
|
103
100
|
}
|
|
104
101
|
}
|
|
105
102
|
return value;
|
|
@@ -110,14 +107,29 @@ function initList(field, value) {
|
|
|
110
107
|
return value.map(toU8Arr);
|
|
111
108
|
}
|
|
112
109
|
if (field.listKind == "message") {
|
|
113
|
-
return value.map((item) => toMessage(
|
|
110
|
+
return value.map((item) => toMessage(field, item));
|
|
114
111
|
}
|
|
115
112
|
}
|
|
116
113
|
return value;
|
|
117
114
|
}
|
|
118
|
-
function toMessage(
|
|
119
|
-
if (
|
|
120
|
-
|
|
115
|
+
function toMessage(field, value) {
|
|
116
|
+
if (field.fieldKind == "message" &&
|
|
117
|
+
!field.oneof &&
|
|
118
|
+
(0, wrappers_js_1.isWrapperDesc)(field.message)) {
|
|
119
|
+
// Types from google/protobuf/wrappers.proto are unwrapped when used in
|
|
120
|
+
// a singular field that is not part of a oneof group.
|
|
121
|
+
return initScalar(field.message.fields[0], value);
|
|
122
|
+
}
|
|
123
|
+
if ((0, guard_js_1.isObject)(value)) {
|
|
124
|
+
if (field.message.typeName == "google.protobuf.Struct" &&
|
|
125
|
+
field.parent.typeName !== "google.protobuf.Value") {
|
|
126
|
+
// google.protobuf.Struct is represented with JsonObject when used in a
|
|
127
|
+
// field, except when used in google.protobuf.Value.
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
if (!(0, is_message_js_1.isMessage)(value, field.message)) {
|
|
131
|
+
return create(field.message, value);
|
|
132
|
+
}
|
|
121
133
|
}
|
|
122
134
|
return value;
|
|
123
135
|
}
|
|
@@ -139,9 +151,7 @@ const messagePrototypes = new WeakMap();
|
|
|
139
151
|
*/
|
|
140
152
|
function createZeroMessage(desc) {
|
|
141
153
|
let msg;
|
|
142
|
-
if (desc
|
|
143
|
-
// we special case proto3: since it does not have default values, we let
|
|
144
|
-
// the `optional` keyword generate an optional property.
|
|
154
|
+
if (!needsPrototypeChain(desc)) {
|
|
145
155
|
msg = {};
|
|
146
156
|
for (const member of desc.members) {
|
|
147
157
|
if (member.kind == "oneof" || member.presence == IMPLICIT) {
|
|
@@ -150,8 +160,7 @@ function createZeroMessage(desc) {
|
|
|
150
160
|
}
|
|
151
161
|
}
|
|
152
162
|
else {
|
|
153
|
-
//
|
|
154
|
-
// via the prototype chain
|
|
163
|
+
// Support default values and track presence via the prototype chain
|
|
155
164
|
const cached = messagePrototypes.get(desc);
|
|
156
165
|
let prototype;
|
|
157
166
|
let members;
|
|
@@ -203,6 +212,24 @@ function createZeroMessage(desc) {
|
|
|
203
212
|
msg.$typeName = desc.typeName;
|
|
204
213
|
return msg;
|
|
205
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Do we need the prototype chain to track field presence?
|
|
217
|
+
*/
|
|
218
|
+
function needsPrototypeChain(desc) {
|
|
219
|
+
switch (desc.file.edition) {
|
|
220
|
+
case EDITION_PROTO3:
|
|
221
|
+
// proto3 always uses implicit presence, we never need the prototype chain.
|
|
222
|
+
return false;
|
|
223
|
+
case EDITION_PROTO2:
|
|
224
|
+
// proto2 never uses implicit presence, we always need the prototype chain.
|
|
225
|
+
return true;
|
|
226
|
+
default:
|
|
227
|
+
// If a message uses scalar or enum fields with explicit presence, we need
|
|
228
|
+
// the prototype chain to track presence. This rule does not apply to fields
|
|
229
|
+
// in a oneof group - they use a different mechanism to track presence.
|
|
230
|
+
return desc.fields.some((f) => f.presence != IMPLICIT && f.fieldKind != "message" && !f.oneof);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
206
233
|
/**
|
|
207
234
|
* Returns a zero value for oneof groups, and for every field kind except
|
|
208
235
|
* messages. Scalar and enum fields can have default values.
|
package/dist/cjs/equals.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ import type { DescMessage } from "./descriptors.js";
|
|
|
6
6
|
* Note that this function disregards extensions and unknown fields, and that
|
|
7
7
|
* NaN is not equal NaN, following the IEEE standard.
|
|
8
8
|
*/
|
|
9
|
-
export declare function equals<Desc extends DescMessage>(
|
|
9
|
+
export declare function equals<Desc extends DescMessage>(schema: Desc, a: MessageShape<Desc>, b: MessageShape<Desc>): boolean;
|
package/dist/cjs/equals.js
CHANGED
|
@@ -22,15 +22,14 @@ const reflect_js_1 = require("./reflect/reflect.js");
|
|
|
22
22
|
* Note that this function disregards extensions and unknown fields, and that
|
|
23
23
|
* NaN is not equal NaN, following the IEEE standard.
|
|
24
24
|
*/
|
|
25
|
-
function equals(
|
|
26
|
-
if (a.$typeName !=
|
|
27
|
-
b.$typeName != messageDesc.typeName) {
|
|
25
|
+
function equals(schema, a, b) {
|
|
26
|
+
if (a.$typeName != schema.typeName || b.$typeName != schema.typeName) {
|
|
28
27
|
return false;
|
|
29
28
|
}
|
|
30
29
|
if (a === b) {
|
|
31
30
|
return true;
|
|
32
31
|
}
|
|
33
|
-
return reflectEquals((0, reflect_js_1.reflect)(
|
|
32
|
+
return reflectEquals((0, reflect_js_1.reflect)(schema, a), (0, reflect_js_1.reflect)(schema, b));
|
|
34
33
|
}
|
|
35
34
|
exports.equals = equals;
|
|
36
35
|
function reflectEquals(a, b) {
|
|
@@ -80,15 +79,11 @@ function fieldEquals(f, a, b) {
|
|
|
80
79
|
case "enum":
|
|
81
80
|
return false;
|
|
82
81
|
case "message":
|
|
83
|
-
// TODO fix type error
|
|
84
|
-
// @ts-expect-error TODO
|
|
85
82
|
if (!reflectEquals(va, vb)) {
|
|
86
83
|
return false;
|
|
87
84
|
}
|
|
88
85
|
break;
|
|
89
86
|
case "scalar":
|
|
90
|
-
// TODO fix type error
|
|
91
|
-
// @ts-expect-error TODO
|
|
92
87
|
if (!(0, scalar_js_1.scalarEquals)(f.scalar, va, vb)) {
|
|
93
88
|
return false;
|
|
94
89
|
}
|
|
@@ -104,23 +99,21 @@ function fieldEquals(f, a, b) {
|
|
|
104
99
|
return false;
|
|
105
100
|
}
|
|
106
101
|
for (let i = 0; i < la.size; i++) {
|
|
107
|
-
|
|
102
|
+
const va = la.get(i);
|
|
103
|
+
const vb = lb.get(i);
|
|
104
|
+
if (va === vb) {
|
|
108
105
|
continue;
|
|
109
106
|
}
|
|
110
107
|
switch (f.listKind) {
|
|
111
108
|
case "enum":
|
|
112
109
|
return false;
|
|
113
110
|
case "message":
|
|
114
|
-
|
|
115
|
-
// @ts-expect-error TODO
|
|
116
|
-
if (!reflectEquals(la.get(i), lb.get(i))) {
|
|
111
|
+
if (!reflectEquals(va, vb)) {
|
|
117
112
|
return false;
|
|
118
113
|
}
|
|
119
114
|
break;
|
|
120
115
|
case "scalar":
|
|
121
|
-
|
|
122
|
-
// @ts-expect-error TODO
|
|
123
|
-
if (!(0, scalar_js_1.scalarEquals)(f.scalar, la.get(i), lb.get(i))) {
|
|
116
|
+
if (!(0, scalar_js_1.scalarEquals)(f.scalar, va, vb)) {
|
|
124
117
|
return false;
|
|
125
118
|
}
|
|
126
119
|
break;
|
|
@@ -17,7 +17,7 @@ export interface BinaryReadOptions {
|
|
|
17
17
|
/**
|
|
18
18
|
* Parse serialized binary data.
|
|
19
19
|
*/
|
|
20
|
-
export declare function fromBinary<Desc extends DescMessage>(
|
|
20
|
+
export declare function fromBinary<Desc extends DescMessage>(schema: Desc, bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MessageShape<Desc>;
|
|
21
21
|
/**
|
|
22
22
|
* Parse from binary data, merging fields.
|
|
23
23
|
*
|
|
@@ -27,7 +27,7 @@ export declare function fromBinary<Desc extends DescMessage>(messageDesc: Desc,
|
|
|
27
27
|
* If a message field is already present, it will be merged with the
|
|
28
28
|
* new data.
|
|
29
29
|
*/
|
|
30
|
-
export declare function mergeFromBinary<Desc extends DescMessage>(
|
|
30
|
+
export declare function mergeFromBinary<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MessageShape<Desc>;
|
|
31
31
|
/**
|
|
32
32
|
* @private
|
|
33
33
|
*/
|
package/dist/cjs/from-binary.js
CHANGED
|
@@ -28,8 +28,8 @@ function makeReadOptions(options) {
|
|
|
28
28
|
/**
|
|
29
29
|
* Parse serialized binary data.
|
|
30
30
|
*/
|
|
31
|
-
function fromBinary(
|
|
32
|
-
const msg = (0, reflect_js_1.reflect)(
|
|
31
|
+
function fromBinary(schema, bytes, options) {
|
|
32
|
+
const msg = (0, reflect_js_1.reflect)(schema, undefined, false);
|
|
33
33
|
readMessage(msg, new binary_encoding_js_1.BinaryReader(bytes), makeReadOptions(options), false, bytes.byteLength);
|
|
34
34
|
return msg.message;
|
|
35
35
|
}
|
|
@@ -43,8 +43,8 @@ exports.fromBinary = fromBinary;
|
|
|
43
43
|
* If a message field is already present, it will be merged with the
|
|
44
44
|
* new data.
|
|
45
45
|
*/
|
|
46
|
-
function mergeFromBinary(
|
|
47
|
-
readMessage((0, reflect_js_1.reflect)(
|
|
46
|
+
function mergeFromBinary(schema, target, bytes, options) {
|
|
47
|
+
readMessage((0, reflect_js_1.reflect)(schema, target, false), new binary_encoding_js_1.BinaryReader(bytes), makeReadOptions(options), false, bytes.byteLength);
|
|
48
48
|
return target;
|
|
49
49
|
}
|
|
50
50
|
exports.mergeFromBinary = mergeFromBinary;
|
|
@@ -146,7 +146,7 @@ function readMapEntry(reader, map, options) {
|
|
|
146
146
|
val = field.enum.values[0].number;
|
|
147
147
|
break;
|
|
148
148
|
case "message":
|
|
149
|
-
val = (0, reflect_js_1.reflect)(field.message);
|
|
149
|
+
val = (0, reflect_js_1.reflect)(field.message, undefined, false);
|
|
150
150
|
break;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -174,7 +174,7 @@ function readListField(reader, wireType, list, options) {
|
|
|
174
174
|
}
|
|
175
175
|
function readMessageField(reader, options, field, mergeMessage) {
|
|
176
176
|
const delimited = field.delimitedEncoding;
|
|
177
|
-
const message = mergeMessage !== null && mergeMessage !== void 0 ? mergeMessage : (0, reflect_js_1.reflect)(field.message);
|
|
177
|
+
const message = mergeMessage !== null && mergeMessage !== void 0 ? mergeMessage : (0, reflect_js_1.reflect)(field.message, undefined, false);
|
|
178
178
|
readMessage(message, reader, options, delimited, delimited ? field.number : reader.uint32());
|
|
179
179
|
return message;
|
|
180
180
|
}
|
package/dist/cjs/from-json.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type DescMessage } from "./descriptors.js";
|
|
1
|
+
import { type DescEnum, type DescMessage } from "./descriptors.js";
|
|
2
2
|
import type { JsonValue } from "./json-value.js";
|
|
3
3
|
import type { Registry } from "./registry.js";
|
|
4
|
-
import type { MessageShape } from "./types.js";
|
|
4
|
+
import type { EnumJsonType, EnumShape, MessageShape } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Options for parsing JSON data.
|
|
7
7
|
*/
|
|
@@ -21,7 +21,7 @@ export interface JsonReadOptions {
|
|
|
21
21
|
/**
|
|
22
22
|
* Parse a message from a JSON string.
|
|
23
23
|
*/
|
|
24
|
-
export declare function fromJsonString<Desc extends DescMessage>(
|
|
24
|
+
export declare function fromJsonString<Desc extends DescMessage>(schema: Desc, json: string, options?: Partial<JsonReadOptions>): MessageShape<Desc>;
|
|
25
25
|
/**
|
|
26
26
|
* Parse a message from a JSON string, merging fields.
|
|
27
27
|
*
|
|
@@ -31,11 +31,11 @@ export declare function fromJsonString<Desc extends DescMessage>(messageDesc: De
|
|
|
31
31
|
* If a message field is already present, it will be merged with the
|
|
32
32
|
* new data.
|
|
33
33
|
*/
|
|
34
|
-
export declare function mergeFromJsonString<Desc extends DescMessage>(
|
|
34
|
+
export declare function mergeFromJsonString<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, json: string, options?: Partial<JsonReadOptions>): MessageShape<Desc>;
|
|
35
35
|
/**
|
|
36
36
|
* Parse a message from a JSON value.
|
|
37
37
|
*/
|
|
38
|
-
export declare function fromJson<Desc extends DescMessage>(
|
|
38
|
+
export declare function fromJson<Desc extends DescMessage>(schema: Desc, json: JsonValue, options?: Partial<JsonReadOptions>): MessageShape<Desc>;
|
|
39
39
|
/**
|
|
40
40
|
* Parse a message from a JSON value, merging fields.
|
|
41
41
|
*
|
|
@@ -45,4 +45,12 @@ export declare function fromJson<Desc extends DescMessage>(messageDesc: Desc, js
|
|
|
45
45
|
* If a message field is already present, it will be merged with the
|
|
46
46
|
* new data.
|
|
47
47
|
*/
|
|
48
|
-
export declare function mergeFromJson<Desc extends DescMessage>(
|
|
48
|
+
export declare function mergeFromJson<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, json: JsonValue, options?: Partial<JsonReadOptions>): MessageShape<Desc>;
|
|
49
|
+
/**
|
|
50
|
+
* Parses an enum value from JSON.
|
|
51
|
+
*/
|
|
52
|
+
export declare function enumFromJson<Desc extends DescEnum>(descEnum: Desc, json: EnumJsonType<Desc>): EnumShape<Desc>;
|
|
53
|
+
/**
|
|
54
|
+
* Is the given value a JSON enum value?
|
|
55
|
+
*/
|
|
56
|
+
export declare function isEnumJson<Desc extends DescEnum>(descEnum: Desc, value: unknown): value is EnumJsonType<Desc>;
|