@depup/apollo__protobufjs 1.2.7-depup.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.
- package/LICENSE +39 -0
- package/README.md +32 -0
- package/bin/pbjs +6 -0
- package/bin/pbts +6 -0
- package/changes.json +14 -0
- package/cli/LICENSE +33 -0
- package/cli/README.md +11 -0
- package/cli/bin/pbjs +6 -0
- package/cli/bin/pbts +6 -0
- package/cli/index.d.ts +3 -0
- package/cli/index.js +3 -0
- package/cli/lib/tsd-jsdoc/LICENSE +21 -0
- package/cli/lib/tsd-jsdoc/README.md +23 -0
- package/cli/lib/tsd-jsdoc/plugin.js +21 -0
- package/cli/lib/tsd-jsdoc/publish.js +693 -0
- package/cli/lib/tsd-jsdoc.json +18 -0
- package/cli/package.json +7 -0
- package/cli/package.standalone.json +32 -0
- package/cli/pbjs.d.ts +9 -0
- package/cli/pbjs.js +331 -0
- package/cli/pbts.d.ts +9 -0
- package/cli/pbts.js +198 -0
- package/cli/targets/json-module.js +38 -0
- package/cli/targets/json.js +8 -0
- package/cli/targets/proto.js +326 -0
- package/cli/targets/proto2.js +10 -0
- package/cli/targets/proto3.js +10 -0
- package/cli/targets/static-module.js +29 -0
- package/cli/targets/static.js +709 -0
- package/cli/util.js +183 -0
- package/cli/wrappers/amd.js +7 -0
- package/cli/wrappers/closure.js +7 -0
- package/cli/wrappers/commonjs.js +7 -0
- package/cli/wrappers/default.js +15 -0
- package/cli/wrappers/es6.js +5 -0
- package/dist/README.md +31 -0
- package/dist/light/README.md +31 -0
- package/dist/light/protobuf.js +7198 -0
- package/dist/light/protobuf.js.map +1 -0
- package/dist/light/protobuf.min.js +7 -0
- package/dist/light/protobuf.min.js.map +1 -0
- package/dist/minimal/README.md +31 -0
- package/dist/minimal/protobuf.js +2675 -0
- package/dist/minimal/protobuf.js.map +1 -0
- package/dist/minimal/protobuf.min.js +7 -0
- package/dist/minimal/protobuf.min.js.map +1 -0
- package/dist/protobuf.js +8775 -0
- package/dist/protobuf.js.map +1 -0
- package/dist/protobuf.min.js +7 -0
- package/dist/protobuf.min.js.map +1 -0
- package/ext/debug/README.md +4 -0
- package/ext/debug/index.js +71 -0
- package/ext/descriptor/README.md +72 -0
- package/ext/descriptor/index.d.ts +191 -0
- package/ext/descriptor/index.js +1052 -0
- package/ext/descriptor/test.js +54 -0
- package/google/LICENSE +27 -0
- package/google/README.md +1 -0
- package/google/api/annotations.json +83 -0
- package/google/api/annotations.proto +11 -0
- package/google/api/http.json +86 -0
- package/google/api/http.proto +31 -0
- package/google/protobuf/api.json +118 -0
- package/google/protobuf/api.proto +34 -0
- package/google/protobuf/descriptor.json +739 -0
- package/google/protobuf/descriptor.proto +286 -0
- package/google/protobuf/source_context.json +20 -0
- package/google/protobuf/source_context.proto +7 -0
- package/google/protobuf/type.json +202 -0
- package/google/protobuf/type.proto +89 -0
- package/index.d.ts +2628 -0
- package/index.js +4 -0
- package/light.d.ts +2 -0
- package/light.js +4 -0
- package/minimal.d.ts +2 -0
- package/minimal.js +4 -0
- package/package.json +147 -0
- package/scripts/postinstall.js +35 -0
- package/src/common.js +399 -0
- package/src/converter.js +304 -0
- package/src/decoder.js +106 -0
- package/src/encoder.js +119 -0
- package/src/enum.js +181 -0
- package/src/field.js +379 -0
- package/src/index-light.js +104 -0
- package/src/index-minimal.js +36 -0
- package/src/index.js +12 -0
- package/src/mapfield.js +126 -0
- package/src/message.js +139 -0
- package/src/method.js +151 -0
- package/src/namespace.js +433 -0
- package/src/object.js +200 -0
- package/src/oneof.js +203 -0
- package/src/parse.js +761 -0
- package/src/reader.js +405 -0
- package/src/reader_buffer.js +44 -0
- package/src/root.js +353 -0
- package/src/roots.js +18 -0
- package/src/rpc/service.js +142 -0
- package/src/rpc.js +36 -0
- package/src/service.js +167 -0
- package/src/tokenize.js +397 -0
- package/src/type.js +589 -0
- package/src/types.js +196 -0
- package/src/typescript.jsdoc +22 -0
- package/src/util/longbits.js +200 -0
- package/src/util/minimal.js +406 -0
- package/src/util.js +178 -0
- package/src/verifier.js +191 -0
- package/src/wrappers.js +83 -0
- package/src/writer.js +459 -0
- package/src/writer_buffer.js +81 -0
- package/tsconfig.json +7 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var protobuf = module.exports = require("./index-light");
|
|
3
|
+
|
|
4
|
+
protobuf.build = "full";
|
|
5
|
+
|
|
6
|
+
// Parser
|
|
7
|
+
protobuf.tokenize = require("./tokenize");
|
|
8
|
+
protobuf.parse = require("./parse");
|
|
9
|
+
protobuf.common = require("./common");
|
|
10
|
+
|
|
11
|
+
// Configure parser
|
|
12
|
+
protobuf.Root._configure(protobuf.Type, protobuf.parse, protobuf.common);
|
package/src/mapfield.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = MapField;
|
|
3
|
+
|
|
4
|
+
// extends Field
|
|
5
|
+
var Field = require("./field");
|
|
6
|
+
((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";
|
|
7
|
+
|
|
8
|
+
var types = require("./types"),
|
|
9
|
+
util = require("./util");
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a new map field instance.
|
|
13
|
+
* @classdesc Reflected map field.
|
|
14
|
+
* @extends FieldBase
|
|
15
|
+
* @constructor
|
|
16
|
+
* @param {string} name Unique name within its namespace
|
|
17
|
+
* @param {number} id Unique id within its namespace
|
|
18
|
+
* @param {string} keyType Key type
|
|
19
|
+
* @param {string} type Value type
|
|
20
|
+
* @param {Object.<string,*>} [options] Declared options
|
|
21
|
+
* @param {string} [comment] Comment associated with this field
|
|
22
|
+
*/
|
|
23
|
+
function MapField(name, id, keyType, type, options, comment) {
|
|
24
|
+
Field.call(this, name, id, type, undefined, undefined, options, comment);
|
|
25
|
+
|
|
26
|
+
/* istanbul ignore if */
|
|
27
|
+
if (!util.isString(keyType))
|
|
28
|
+
throw TypeError("keyType must be a string");
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Key type.
|
|
32
|
+
* @type {string}
|
|
33
|
+
*/
|
|
34
|
+
this.keyType = keyType; // toJSON, marker
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Resolved key type if not a basic type.
|
|
38
|
+
* @type {ReflectionObject|null}
|
|
39
|
+
*/
|
|
40
|
+
this.resolvedKeyType = null;
|
|
41
|
+
|
|
42
|
+
// Overrides Field#map
|
|
43
|
+
this.map = true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Map field descriptor.
|
|
48
|
+
* @interface IMapField
|
|
49
|
+
* @extends {IField}
|
|
50
|
+
* @property {string} keyType Key type
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Extension map field descriptor.
|
|
55
|
+
* @interface IExtensionMapField
|
|
56
|
+
* @extends IMapField
|
|
57
|
+
* @property {string} extend Extended type
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Constructs a map field from a map field descriptor.
|
|
62
|
+
* @param {string} name Field name
|
|
63
|
+
* @param {IMapField} json Map field descriptor
|
|
64
|
+
* @returns {MapField} Created map field
|
|
65
|
+
* @throws {TypeError} If arguments are invalid
|
|
66
|
+
*/
|
|
67
|
+
MapField.fromJSON = function fromJSON(name, json) {
|
|
68
|
+
return new MapField(name, json.id, json.keyType, json.type, json.options, json.comment);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Converts this map field to a map field descriptor.
|
|
73
|
+
* @param {IToJSONOptions} [toJSONOptions] JSON conversion options
|
|
74
|
+
* @returns {IMapField} Map field descriptor
|
|
75
|
+
*/
|
|
76
|
+
MapField.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
77
|
+
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
|
|
78
|
+
return util.toObject([
|
|
79
|
+
"keyType" , this.keyType,
|
|
80
|
+
"type" , this.type,
|
|
81
|
+
"id" , this.id,
|
|
82
|
+
"extend" , this.extend,
|
|
83
|
+
"options" , this.options,
|
|
84
|
+
"comment" , keepComments ? this.comment : undefined
|
|
85
|
+
]);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @override
|
|
90
|
+
*/
|
|
91
|
+
MapField.prototype.resolve = function resolve() {
|
|
92
|
+
if (this.resolved)
|
|
93
|
+
return this;
|
|
94
|
+
|
|
95
|
+
// Besides a value type, map fields have a key type that may be "any scalar type except for floating point types and bytes"
|
|
96
|
+
if (types.mapKey[this.keyType] === undefined)
|
|
97
|
+
throw Error("invalid key type: " + this.keyType);
|
|
98
|
+
|
|
99
|
+
return Field.prototype.resolve.call(this);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Map field decorator (TypeScript).
|
|
104
|
+
* @name MapField.d
|
|
105
|
+
* @function
|
|
106
|
+
* @param {number} fieldId Field id
|
|
107
|
+
* @param {"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"} fieldKeyType Field key type
|
|
108
|
+
* @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|Object|Constructor<{}>} fieldValueType Field value type
|
|
109
|
+
* @returns {FieldDecorator} Decorator function
|
|
110
|
+
* @template T extends { [key: string]: number | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }
|
|
111
|
+
*/
|
|
112
|
+
MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
|
|
113
|
+
|
|
114
|
+
// submessage value: decorate the submessage and use its name as the type
|
|
115
|
+
if (typeof fieldValueType === "function")
|
|
116
|
+
fieldValueType = util.decorateType(fieldValueType).name;
|
|
117
|
+
|
|
118
|
+
// enum reference value: create a reflected copy of the enum and keep reuseing it
|
|
119
|
+
else if (fieldValueType && typeof fieldValueType === "object")
|
|
120
|
+
fieldValueType = util.decorateEnum(fieldValueType).name;
|
|
121
|
+
|
|
122
|
+
return function mapFieldDecorator(prototype, fieldName) {
|
|
123
|
+
util.decorateType(prototype.constructor)
|
|
124
|
+
.add(new MapField(fieldName, fieldId, fieldKeyType, fieldValueType));
|
|
125
|
+
};
|
|
126
|
+
};
|
package/src/message.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = Message;
|
|
3
|
+
|
|
4
|
+
var util = require("./util/minimal");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Constructs a new message instance.
|
|
8
|
+
* @classdesc Abstract runtime message.
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {Properties<T>} [properties] Properties to set
|
|
11
|
+
* @template T extends object = object
|
|
12
|
+
*/
|
|
13
|
+
function Message(properties) {
|
|
14
|
+
// not used internally
|
|
15
|
+
if (properties)
|
|
16
|
+
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
17
|
+
this[keys[i]] = properties[keys[i]];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Reference to the reflected type.
|
|
22
|
+
* @name Message.$type
|
|
23
|
+
* @type {Type}
|
|
24
|
+
* @readonly
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Reference to the reflected type.
|
|
29
|
+
* @name Message#$type
|
|
30
|
+
* @type {Type}
|
|
31
|
+
* @readonly
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/*eslint-disable valid-jsdoc*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new message of this type using the specified properties.
|
|
38
|
+
* @param {Object.<string,*>} [properties] Properties to set
|
|
39
|
+
* @returns {Message<T>} Message instance
|
|
40
|
+
* @template T extends Message<T>
|
|
41
|
+
* @this Constructor<T>
|
|
42
|
+
*/
|
|
43
|
+
Message.create = function create(properties) {
|
|
44
|
+
return this.$type.create(properties);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Encodes a message of this type.
|
|
49
|
+
* @param {T|Object.<string,*>} message Message to encode
|
|
50
|
+
* @param {Writer} [writer] Writer to use
|
|
51
|
+
* @returns {Writer} Writer
|
|
52
|
+
* @template T extends Message<T>
|
|
53
|
+
* @this Constructor<T>
|
|
54
|
+
*/
|
|
55
|
+
Message.encode = function encode(message, writer) {
|
|
56
|
+
return this.$type.encode(message, writer);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Encodes a message of this type preceeded by its length as a varint.
|
|
61
|
+
* @param {T|Object.<string,*>} message Message to encode
|
|
62
|
+
* @param {Writer} [writer] Writer to use
|
|
63
|
+
* @returns {Writer} Writer
|
|
64
|
+
* @template T extends Message<T>
|
|
65
|
+
* @this Constructor<T>
|
|
66
|
+
*/
|
|
67
|
+
Message.encodeDelimited = function encodeDelimited(message, writer) {
|
|
68
|
+
return this.$type.encodeDelimited(message, writer);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Decodes a message of this type.
|
|
73
|
+
* @name Message.decode
|
|
74
|
+
* @function
|
|
75
|
+
* @param {Reader|Uint8Array} reader Reader or buffer to decode
|
|
76
|
+
* @returns {T} Decoded message
|
|
77
|
+
* @template T extends Message<T>
|
|
78
|
+
* @this Constructor<T>
|
|
79
|
+
*/
|
|
80
|
+
Message.decode = function decode(reader) {
|
|
81
|
+
return this.$type.decode(reader);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Decodes a message of this type preceeded by its length as a varint.
|
|
86
|
+
* @name Message.decodeDelimited
|
|
87
|
+
* @function
|
|
88
|
+
* @param {Reader|Uint8Array} reader Reader or buffer to decode
|
|
89
|
+
* @returns {T} Decoded message
|
|
90
|
+
* @template T extends Message<T>
|
|
91
|
+
* @this Constructor<T>
|
|
92
|
+
*/
|
|
93
|
+
Message.decodeDelimited = function decodeDelimited(reader) {
|
|
94
|
+
return this.$type.decodeDelimited(reader);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Verifies a message of this type.
|
|
99
|
+
* @name Message.verify
|
|
100
|
+
* @function
|
|
101
|
+
* @param {Object.<string,*>} message Plain object to verify
|
|
102
|
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
|
103
|
+
*/
|
|
104
|
+
Message.verify = function verify(message) {
|
|
105
|
+
return this.$type.verify(message);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
|
110
|
+
* @param {Object.<string,*>} object Plain object
|
|
111
|
+
* @returns {T} Message instance
|
|
112
|
+
* @template T extends Message<T>
|
|
113
|
+
* @this Constructor<T>
|
|
114
|
+
*/
|
|
115
|
+
Message.fromObject = function fromObject(object) {
|
|
116
|
+
return this.$type.fromObject(object);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Creates a plain object from a message of this type. Also converts values to other types if specified.
|
|
121
|
+
* @param {T} message Message instance
|
|
122
|
+
* @param {IConversionOptions} [options] Conversion options
|
|
123
|
+
* @returns {Object.<string,*>} Plain object
|
|
124
|
+
* @template T extends Message<T>
|
|
125
|
+
* @this Constructor<T>
|
|
126
|
+
*/
|
|
127
|
+
Message.toObject = function toObject(message, options) {
|
|
128
|
+
return this.$type.toObject(message, options);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Converts this message to JSON.
|
|
133
|
+
* @returns {Object.<string,*>} JSON object
|
|
134
|
+
*/
|
|
135
|
+
Message.prototype.toJSON = function toJSON() {
|
|
136
|
+
return this.$type.toObject(this, util.toJSONOptions);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/*eslint-enable valid-jsdoc*/
|
package/src/method.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = Method;
|
|
3
|
+
|
|
4
|
+
// extends ReflectionObject
|
|
5
|
+
var ReflectionObject = require("./object");
|
|
6
|
+
((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";
|
|
7
|
+
|
|
8
|
+
var util = require("./util");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a new service method instance.
|
|
12
|
+
* @classdesc Reflected service method.
|
|
13
|
+
* @extends ReflectionObject
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {string} name Method name
|
|
16
|
+
* @param {string|undefined} type Method type, usually `"rpc"`
|
|
17
|
+
* @param {string} requestType Request message type
|
|
18
|
+
* @param {string} responseType Response message type
|
|
19
|
+
* @param {boolean|Object.<string,*>} [requestStream] Whether the request is streamed
|
|
20
|
+
* @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
|
|
21
|
+
* @param {Object.<string,*>} [options] Declared options
|
|
22
|
+
* @param {string} [comment] The comment for this method
|
|
23
|
+
*/
|
|
24
|
+
function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment) {
|
|
25
|
+
|
|
26
|
+
/* istanbul ignore next */
|
|
27
|
+
if (util.isObject(requestStream)) {
|
|
28
|
+
options = requestStream;
|
|
29
|
+
requestStream = responseStream = undefined;
|
|
30
|
+
} else if (util.isObject(responseStream)) {
|
|
31
|
+
options = responseStream;
|
|
32
|
+
responseStream = undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* istanbul ignore if */
|
|
36
|
+
if (!(type === undefined || util.isString(type)))
|
|
37
|
+
throw TypeError("type must be a string");
|
|
38
|
+
|
|
39
|
+
/* istanbul ignore if */
|
|
40
|
+
if (!util.isString(requestType))
|
|
41
|
+
throw TypeError("requestType must be a string");
|
|
42
|
+
|
|
43
|
+
/* istanbul ignore if */
|
|
44
|
+
if (!util.isString(responseType))
|
|
45
|
+
throw TypeError("responseType must be a string");
|
|
46
|
+
|
|
47
|
+
ReflectionObject.call(this, name, options);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Method type.
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
53
|
+
this.type = type || "rpc"; // toJSON
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Request type.
|
|
57
|
+
* @type {string}
|
|
58
|
+
*/
|
|
59
|
+
this.requestType = requestType; // toJSON, marker
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether requests are streamed or not.
|
|
63
|
+
* @type {boolean|undefined}
|
|
64
|
+
*/
|
|
65
|
+
this.requestStream = requestStream ? true : undefined; // toJSON
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Response type.
|
|
69
|
+
* @type {string}
|
|
70
|
+
*/
|
|
71
|
+
this.responseType = responseType; // toJSON
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Whether responses are streamed or not.
|
|
75
|
+
* @type {boolean|undefined}
|
|
76
|
+
*/
|
|
77
|
+
this.responseStream = responseStream ? true : undefined; // toJSON
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Resolved request type.
|
|
81
|
+
* @type {Type|null}
|
|
82
|
+
*/
|
|
83
|
+
this.resolvedRequestType = null;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Resolved response type.
|
|
87
|
+
* @type {Type|null}
|
|
88
|
+
*/
|
|
89
|
+
this.resolvedResponseType = null;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Comment for this method
|
|
93
|
+
* @type {string|null}
|
|
94
|
+
*/
|
|
95
|
+
this.comment = comment;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Method descriptor.
|
|
100
|
+
* @interface IMethod
|
|
101
|
+
* @property {string} [type="rpc"] Method type
|
|
102
|
+
* @property {string} requestType Request type
|
|
103
|
+
* @property {string} responseType Response type
|
|
104
|
+
* @property {boolean} [requestStream=false] Whether requests are streamed
|
|
105
|
+
* @property {boolean} [responseStream=false] Whether responses are streamed
|
|
106
|
+
* @property {Object.<string,*>} [options] Method options
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Constructs a method from a method descriptor.
|
|
111
|
+
* @param {string} name Method name
|
|
112
|
+
* @param {IMethod} json Method descriptor
|
|
113
|
+
* @returns {Method} Created method
|
|
114
|
+
* @throws {TypeError} If arguments are invalid
|
|
115
|
+
*/
|
|
116
|
+
Method.fromJSON = function fromJSON(name, json) {
|
|
117
|
+
return new Method(name, json.type, json.requestType, json.responseType, json.requestStream, json.responseStream, json.options, json.comment);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Converts this method to a method descriptor.
|
|
122
|
+
* @param {IToJSONOptions} [toJSONOptions] JSON conversion options
|
|
123
|
+
* @returns {IMethod} Method descriptor
|
|
124
|
+
*/
|
|
125
|
+
Method.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
126
|
+
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
|
|
127
|
+
return util.toObject([
|
|
128
|
+
"type" , this.type !== "rpc" && /* istanbul ignore next */ this.type || undefined,
|
|
129
|
+
"requestType" , this.requestType,
|
|
130
|
+
"requestStream" , this.requestStream,
|
|
131
|
+
"responseType" , this.responseType,
|
|
132
|
+
"responseStream" , this.responseStream,
|
|
133
|
+
"options" , this.options,
|
|
134
|
+
"comment" , keepComments ? this.comment : undefined
|
|
135
|
+
]);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @override
|
|
140
|
+
*/
|
|
141
|
+
Method.prototype.resolve = function resolve() {
|
|
142
|
+
|
|
143
|
+
/* istanbul ignore if */
|
|
144
|
+
if (this.resolved)
|
|
145
|
+
return this;
|
|
146
|
+
|
|
147
|
+
this.resolvedRequestType = this.parent.lookupType(this.requestType);
|
|
148
|
+
this.resolvedResponseType = this.parent.lookupType(this.responseType);
|
|
149
|
+
|
|
150
|
+
return ReflectionObject.prototype.resolve.call(this);
|
|
151
|
+
};
|