@bufbuild/protobuf 0.0.4 → 0.0.5
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/package.json +1 -0
- package/dist/cjs/type-registry.js +58 -13
- package/dist/esm/type-registry.js +58 -13
- package/dist/types/type-registry.d.ts +35 -2
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.TypeRegistry = void 0;
|
|
17
17
|
/**
|
|
18
|
-
* TypeRegistry is a
|
|
18
|
+
* TypeRegistry is a simple registry for all message, enum, or service types.
|
|
19
19
|
*/
|
|
20
20
|
class TypeRegistry {
|
|
21
21
|
constructor() {
|
|
@@ -23,35 +23,80 @@ class TypeRegistry {
|
|
|
23
23
|
this.enums = {};
|
|
24
24
|
this.services = {};
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Find a message type by its protobuf type name.
|
|
28
|
+
*/
|
|
26
29
|
findMessage(typeName) {
|
|
27
30
|
return this.messages[typeName];
|
|
28
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Find an enum type by its protobuf type name.
|
|
34
|
+
*/
|
|
29
35
|
findEnum(typeName) {
|
|
30
36
|
return this.enums[typeName];
|
|
31
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Find a service type by its protobuf type name.
|
|
40
|
+
*/
|
|
32
41
|
findService(typeName) {
|
|
33
42
|
return this.services[typeName];
|
|
34
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a new TypeRegistry from the given types.
|
|
46
|
+
*/
|
|
47
|
+
static from(...types) {
|
|
48
|
+
const registry = new TypeRegistry();
|
|
49
|
+
for (const type of types) {
|
|
50
|
+
registry.add(type);
|
|
51
|
+
}
|
|
52
|
+
return registry;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated use TypeRegistry.from()
|
|
56
|
+
*/
|
|
57
|
+
static fromIterable(types) {
|
|
58
|
+
return TypeRegistry.from(...types);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated use TypeRegistry.from()
|
|
62
|
+
*/
|
|
63
|
+
static fromTypes(...types) {
|
|
64
|
+
return TypeRegistry.from(...types);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Add a type to the registry. For messages, the types used in message
|
|
68
|
+
* fields are added recursively. For services, the message types used
|
|
69
|
+
* for requests and responses are added recursively.
|
|
70
|
+
*/
|
|
35
71
|
add(type) {
|
|
36
72
|
if ("fields" in type) {
|
|
37
|
-
this.
|
|
73
|
+
if (!this.findMessage(type.typeName)) {
|
|
74
|
+
this.messages[type.typeName] = type;
|
|
75
|
+
for (const field of type.fields.list()) {
|
|
76
|
+
if (field.kind == "message") {
|
|
77
|
+
this.add(field.T);
|
|
78
|
+
}
|
|
79
|
+
else if (field.kind == "map" && field.V.kind == "message") {
|
|
80
|
+
this.add(field.V.T);
|
|
81
|
+
}
|
|
82
|
+
else if (field.kind == "enum") {
|
|
83
|
+
this.add(field.T);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
38
87
|
}
|
|
39
88
|
else if ("methods" in type) {
|
|
40
|
-
this.
|
|
89
|
+
if (!this.findService(type.typeName)) {
|
|
90
|
+
this.services[type.typeName] = type;
|
|
91
|
+
for (const method of Object.values(type.methods)) {
|
|
92
|
+
this.add(method.I);
|
|
93
|
+
this.add(method.O);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
41
96
|
}
|
|
42
97
|
else {
|
|
43
98
|
this.enums[type.typeName] = type;
|
|
44
99
|
}
|
|
45
100
|
}
|
|
46
|
-
static fromIterable(types) {
|
|
47
|
-
const r = new TypeRegistry();
|
|
48
|
-
for (const t of types) {
|
|
49
|
-
r.add(t);
|
|
50
|
-
}
|
|
51
|
-
return r;
|
|
52
|
-
}
|
|
53
|
-
static fromTypes(...types) {
|
|
54
|
-
return TypeRegistry.fromIterable(types);
|
|
55
|
-
}
|
|
56
101
|
}
|
|
57
102
|
exports.TypeRegistry = TypeRegistry;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
/**
|
|
15
|
-
* TypeRegistry is a
|
|
15
|
+
* TypeRegistry is a simple registry for all message, enum, or service types.
|
|
16
16
|
*/
|
|
17
17
|
export class TypeRegistry {
|
|
18
18
|
constructor() {
|
|
@@ -20,34 +20,79 @@ export class TypeRegistry {
|
|
|
20
20
|
this.enums = {};
|
|
21
21
|
this.services = {};
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Find a message type by its protobuf type name.
|
|
25
|
+
*/
|
|
23
26
|
findMessage(typeName) {
|
|
24
27
|
return this.messages[typeName];
|
|
25
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Find an enum type by its protobuf type name.
|
|
31
|
+
*/
|
|
26
32
|
findEnum(typeName) {
|
|
27
33
|
return this.enums[typeName];
|
|
28
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Find a service type by its protobuf type name.
|
|
37
|
+
*/
|
|
29
38
|
findService(typeName) {
|
|
30
39
|
return this.services[typeName];
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a new TypeRegistry from the given types.
|
|
43
|
+
*/
|
|
44
|
+
static from(...types) {
|
|
45
|
+
const registry = new TypeRegistry();
|
|
46
|
+
for (const type of types) {
|
|
47
|
+
registry.add(type);
|
|
48
|
+
}
|
|
49
|
+
return registry;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated use TypeRegistry.from()
|
|
53
|
+
*/
|
|
54
|
+
static fromIterable(types) {
|
|
55
|
+
return TypeRegistry.from(...types);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated use TypeRegistry.from()
|
|
59
|
+
*/
|
|
60
|
+
static fromTypes(...types) {
|
|
61
|
+
return TypeRegistry.from(...types);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Add a type to the registry. For messages, the types used in message
|
|
65
|
+
* fields are added recursively. For services, the message types used
|
|
66
|
+
* for requests and responses are added recursively.
|
|
67
|
+
*/
|
|
32
68
|
add(type) {
|
|
33
69
|
if ("fields" in type) {
|
|
34
|
-
this.
|
|
70
|
+
if (!this.findMessage(type.typeName)) {
|
|
71
|
+
this.messages[type.typeName] = type;
|
|
72
|
+
for (const field of type.fields.list()) {
|
|
73
|
+
if (field.kind == "message") {
|
|
74
|
+
this.add(field.T);
|
|
75
|
+
}
|
|
76
|
+
else if (field.kind == "map" && field.V.kind == "message") {
|
|
77
|
+
this.add(field.V.T);
|
|
78
|
+
}
|
|
79
|
+
else if (field.kind == "enum") {
|
|
80
|
+
this.add(field.T);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
35
84
|
}
|
|
36
85
|
else if ("methods" in type) {
|
|
37
|
-
this.
|
|
86
|
+
if (!this.findService(type.typeName)) {
|
|
87
|
+
this.services[type.typeName] = type;
|
|
88
|
+
for (const method of Object.values(type.methods)) {
|
|
89
|
+
this.add(method.I);
|
|
90
|
+
this.add(method.O);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
38
93
|
}
|
|
39
94
|
else {
|
|
40
95
|
this.enums[type.typeName] = type;
|
|
41
96
|
}
|
|
42
97
|
}
|
|
43
|
-
static fromIterable(types) {
|
|
44
|
-
const r = new TypeRegistry();
|
|
45
|
-
for (const t of types) {
|
|
46
|
-
r.add(t);
|
|
47
|
-
}
|
|
48
|
-
return r;
|
|
49
|
-
}
|
|
50
|
-
static fromTypes(...types) {
|
|
51
|
-
return TypeRegistry.fromIterable(types);
|
|
52
|
-
}
|
|
53
98
|
}
|
|
@@ -5,31 +5,64 @@ import type { ServiceType } from "./service-type.js";
|
|
|
5
5
|
* IMessageTypeRegistry provides look-up for message types.
|
|
6
6
|
*/
|
|
7
7
|
export interface IMessageTypeRegistry {
|
|
8
|
+
/**
|
|
9
|
+
* Find a message type by its protobuf type name.
|
|
10
|
+
*/
|
|
8
11
|
findMessage(typeName: string): MessageType | undefined;
|
|
9
12
|
}
|
|
10
13
|
/**
|
|
11
14
|
* IEnumTypeRegistry provides look-up for enum types.
|
|
12
15
|
*/
|
|
13
16
|
export interface IEnumTypeRegistry {
|
|
17
|
+
/**
|
|
18
|
+
* Find an enum type by its protobuf type name.
|
|
19
|
+
*/
|
|
14
20
|
findEnum(typeName: string): EnumType | undefined;
|
|
15
21
|
}
|
|
16
22
|
/**
|
|
17
23
|
* IServiceTypeRegistry provides look-up for service types.
|
|
18
24
|
*/
|
|
19
25
|
export interface IServiceTypeRegistry {
|
|
26
|
+
/**
|
|
27
|
+
* Find a service type by its protobuf type name.
|
|
28
|
+
*/
|
|
20
29
|
findService(typeName: string): ServiceType | undefined;
|
|
21
30
|
}
|
|
22
31
|
/**
|
|
23
|
-
* TypeRegistry is a
|
|
32
|
+
* TypeRegistry is a simple registry for all message, enum, or service types.
|
|
24
33
|
*/
|
|
25
34
|
export declare class TypeRegistry implements IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry {
|
|
26
35
|
private readonly messages;
|
|
27
36
|
private readonly enums;
|
|
28
37
|
private readonly services;
|
|
38
|
+
/**
|
|
39
|
+
* Find a message type by its protobuf type name.
|
|
40
|
+
*/
|
|
29
41
|
findMessage(typeName: string): MessageType | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Find an enum type by its protobuf type name.
|
|
44
|
+
*/
|
|
30
45
|
findEnum(typeName: string): EnumType | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Find a service type by its protobuf type name.
|
|
48
|
+
*/
|
|
31
49
|
findService(typeName: string): ServiceType | undefined;
|
|
32
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Create a new TypeRegistry from the given types.
|
|
52
|
+
*/
|
|
53
|
+
static from(...types: Array<MessageType | EnumType | ServiceType>): TypeRegistry;
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated use TypeRegistry.from()
|
|
56
|
+
*/
|
|
33
57
|
static fromIterable(types: Iterable<MessageType>): TypeRegistry;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated use TypeRegistry.from()
|
|
60
|
+
*/
|
|
34
61
|
static fromTypes(...types: MessageType[]): TypeRegistry;
|
|
62
|
+
/**
|
|
63
|
+
* Add a type to the registry. For messages, the types used in message
|
|
64
|
+
* fields are added recursively. For services, the message types used
|
|
65
|
+
* for requests and responses are added recursively.
|
|
66
|
+
*/
|
|
67
|
+
add(type: MessageType | EnumType | ServiceType): void;
|
|
35
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protobuf",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*",
|
|
14
14
|
"build": "npm run build:cjs && npm run build:esm+types",
|
|
15
|
-
"build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs",
|
|
15
|
+
"build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
16
16
|
"build:esm+types": "npx tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"default": "./dist/esm/index.js"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"typescript": "^4.
|
|
26
|
+
"typescript": "^4.7.3"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"dist/**/"
|