summaryrefslogtreecommitdiff
path: root/frontend-old/node_modules/protobufjs/src/service.js
diff options
context:
space:
mode:
authoraltaf-creator <dev@altafcreator.com>2025-11-09 11:15:19 +0800
committeraltaf-creator <dev@altafcreator.com>2025-11-09 11:15:19 +0800
commit8eff962cab608341a6f2fedc640a0e32d96f26e2 (patch)
tree05534d1a720ddc3691d346c69b4972555820a061 /frontend-old/node_modules/protobufjs/src/service.js
pain
Diffstat (limited to 'frontend-old/node_modules/protobufjs/src/service.js')
-rw-r--r--frontend-old/node_modules/protobufjs/src/service.js189
1 files changed, 189 insertions, 0 deletions
diff --git a/frontend-old/node_modules/protobufjs/src/service.js b/frontend-old/node_modules/protobufjs/src/service.js
new file mode 100644
index 0000000..5046743
--- /dev/null
+++ b/frontend-old/node_modules/protobufjs/src/service.js
@@ -0,0 +1,189 @@
+"use strict";
+module.exports = Service;
+
+// extends Namespace
+var Namespace = require("./namespace");
+((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
+
+var Method = require("./method"),
+ util = require("./util"),
+ rpc = require("./rpc");
+
+/**
+ * Constructs a new service instance.
+ * @classdesc Reflected service.
+ * @extends NamespaceBase
+ * @constructor
+ * @param {string} name Service name
+ * @param {Object.<string,*>} [options] Service options
+ * @throws {TypeError} If arguments are invalid
+ */
+function Service(name, options) {
+ Namespace.call(this, name, options);
+
+ /**
+ * Service methods.
+ * @type {Object.<string,Method>}
+ */
+ this.methods = {}; // toJSON, marker
+
+ /**
+ * Cached methods as an array.
+ * @type {Method[]|null}
+ * @private
+ */
+ this._methodsArray = null;
+}
+
+/**
+ * Service descriptor.
+ * @interface IService
+ * @extends INamespace
+ * @property {Object.<string,IMethod>} methods Method descriptors
+ */
+
+/**
+ * Constructs a service from a service descriptor.
+ * @param {string} name Service name
+ * @param {IService} json Service descriptor
+ * @returns {Service} Created service
+ * @throws {TypeError} If arguments are invalid
+ */
+Service.fromJSON = function fromJSON(name, json) {
+ var service = new Service(name, json.options);
+ /* istanbul ignore else */
+ if (json.methods)
+ for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
+ service.add(Method.fromJSON(names[i], json.methods[names[i]]));
+ if (json.nested)
+ service.addJSON(json.nested);
+ if (json.edition)
+ service._edition = json.edition;
+ service.comment = json.comment;
+ service._defaultEdition = "proto3"; // For backwards-compatibility.
+ return service;
+};
+
+/**
+ * Converts this service to a service descriptor.
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
+ * @returns {IService} Service descriptor
+ */
+Service.prototype.toJSON = function toJSON(toJSONOptions) {
+ var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
+ return util.toObject([
+ "edition" , this._editionToJSON(),
+ "options" , inherited && inherited.options || undefined,
+ "methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
+ "nested" , inherited && inherited.nested || undefined,
+ "comment" , keepComments ? this.comment : undefined
+ ]);
+};
+
+/**
+ * Methods of this service as an array for iteration.
+ * @name Service#methodsArray
+ * @type {Method[]}
+ * @readonly
+ */
+Object.defineProperty(Service.prototype, "methodsArray", {
+ get: function() {
+ return this._methodsArray || (this._methodsArray = util.toArray(this.methods));
+ }
+});
+
+function clearCache(service) {
+ service._methodsArray = null;
+ return service;
+}
+
+/**
+ * @override
+ */
+Service.prototype.get = function get(name) {
+ return this.methods[name]
+ || Namespace.prototype.get.call(this, name);
+};
+
+/**
+ * @override
+ */
+Service.prototype.resolveAll = function resolveAll() {
+ if (!this._needsRecursiveResolve) return this;
+
+ Namespace.prototype.resolve.call(this);
+ var methods = this.methodsArray;
+ for (var i = 0; i < methods.length; ++i)
+ methods[i].resolve();
+ return this;
+};
+
+/**
+ * @override
+ */
+Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
+ if (!this._needsRecursiveFeatureResolution) return this;
+
+ edition = this._edition || edition;
+
+ Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
+ this.methodsArray.forEach(method => {
+ method._resolveFeaturesRecursive(edition);
+ });
+ return this;
+};
+
+/**
+ * @override
+ */
+Service.prototype.add = function add(object) {
+
+ /* istanbul ignore if */
+ if (this.get(object.name))
+ throw Error("duplicate name '" + object.name + "' in " + this);
+
+ if (object instanceof Method) {
+ this.methods[object.name] = object;
+ object.parent = this;
+ return clearCache(this);
+ }
+ return Namespace.prototype.add.call(this, object);
+};
+
+/**
+ * @override
+ */
+Service.prototype.remove = function remove(object) {
+ if (object instanceof Method) {
+
+ /* istanbul ignore if */
+ if (this.methods[object.name] !== object)
+ throw Error(object + " is not a member of " + this);
+
+ delete this.methods[object.name];
+ object.parent = null;
+ return clearCache(this);
+ }
+ return Namespace.prototype.remove.call(this, object);
+};
+
+/**
+ * Creates a runtime service using the specified rpc implementation.
+ * @param {RPCImpl} rpcImpl RPC implementation
+ * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
+ * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
+ * @returns {rpc.Service} RPC service. Useful where requests and/or responses are streamed.
+ */
+Service.prototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
+ var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
+ for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
+ var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
+ rpcService[methodName] = util.codegen(["r","c"], util.isReserved(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
+ m: method,
+ q: method.resolvedRequestType.ctor,
+ s: method.resolvedResponseType.ctor
+ });
+ }
+ return rpcService;
+};