rpc-typescript
Version:
An RCP library for TypeScript
148 lines (132 loc) • 5.51 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
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 ProxyContextImpl = /** @class */ (function () {
function ProxyContextImpl() {
}
ProxyContextImpl.prototype.createChannel = function (contract) {
throw new Error("Method not implemented.");
};
ProxyContextImpl.prototype.defineMember = function (props, target, propertyKey, descriptor) {
return {};
};
ProxyContextImpl.prototype.defineContract = function (props, constructor) {
};
return ProxyContextImpl;
}());
var ProxyContext = new ContextDomain(function () { return new ProxyContextImpl(); });
function ProxyMethod(config) {
var props = config !== null && config !== void 0 ? config : {
transport: 'http',
httpMethod: 'POST'
};
return function (target, propertyKey, descriptor) {
var ctx = ProxyContext.getContext(props.contextDomain);
return ctx.defineMember(props, target, propertyKey, descriptor);
};
}
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 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);
};
}
function ProxyContract(config) {
var props = config !== null && config !== void 0 ? config : {};
return function (constructor) {
var ctx = ProxyContext.getContext(props.contextDomain);
return ctx.defineContract(props, constructor);
};
}
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);
};
}
/*! *****************************************************************************
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.ProxyContext = ProxyContext;
exports.ProxyContract = ProxyContract;
exports.ProxyMethod = ProxyMethod;
exports.RpcMethod = RpcMethod;
exports.StubContext = StubContext;
exports.StubContextImpl = StubContextImpl;
exports.StubContract = StubContract;
exports.StubMethod = StubMethod;