UNPKG

rpc-typescript

Version:
117 lines (103 loc) 4.93 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["rpc-typescript"] = {})); })(this, (function (exports) { 'use strict'; var ContextDomain = /** @class */ (function () { function ContextDomain(factory) { this._ctx = {}; this._factory = factory; } ContextDomain.prototype.getContext = function (name) { if (typeof name === 'undefined') { name = 'default'; } var instance = this._ctx[name]; if (typeof instance === 'undefined') { instance = this._factory(name); this._ctx[name] = instance; } return instance; }; ContextDomain.prototype.getChannel = function (contract, contextName) { var ctx = this.getContext(contextName); return ctx.createChannel(contract); }; ContextDomain.prototype.clear = function (name) { delete this._ctx[name]; }; return ContextDomain; }()); var StubContextImpl = /** @class */ (function () { function StubContextImpl() { } StubContextImpl.prototype.createChannel = function (contract) { throw new Error("Method not implemented."); }; StubContextImpl.prototype.defineMember = function (props, target, propertyKey, descriptor) { }; StubContextImpl.prototype.defineContract = function (props, constructor) { }; return StubContextImpl; }()); var StubContext = new ContextDomain(function () { return new StubContextImpl(); }); function StubContract(config) { var props = config !== null && config !== void 0 ? config : {}; return function (constructor) { var ctx = StubContext.getContext(props.contextDomain); return ctx.defineContract(props, constructor); }; } function StubMethod(config) { var props = config !== null && config !== void 0 ? config : { transport: 'http', httpMethod: 'POST' }; return function (target, propertyKey, descriptor) { var ctx = StubContext.getContext(props.contextDomain); return ctx.defineMember(props, target, propertyKey, descriptor); }; } /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var RpcMethod = /** @class */ (function (_super) { __extends(RpcMethod, _super); function RpcMethod(methodName, message) { var _this = _super.call(this, message) || this; _this.name = typeof methodName === 'undefined' ? 'InvalidRpcMethod' : "InvalidRpcMethod(" + methodName + ")"; return _this; } return RpcMethod; }(Error)); exports.ContextDomain = ContextDomain; exports.RpcMethod = RpcMethod; exports.StubContext = StubContext; exports.StubContextImpl = StubContextImpl; exports.StubContract = StubContract; exports.StubMethod = StubMethod; Object.defineProperty(exports, '__esModule', { value: true }); }));