mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-01 21:52:19 +00:00
0.2.0 - Mid migration
This commit is contained in:
parent
139e6a915e
commit
7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions
42
web/node_modules/worker-rpc/lib/RpcProvider.d.ts
generated
vendored
Normal file
42
web/node_modules/worker-rpc/lib/RpcProvider.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { Event } from 'microevent.ts';
|
||||
import RpcProviderInterface from './RpcProviderInterface';
|
||||
declare class RpcProvider implements RpcProviderInterface {
|
||||
private _dispatch;
|
||||
private _rpcTimeout;
|
||||
constructor(_dispatch: RpcProvider.Dispatcher, _rpcTimeout?: number);
|
||||
dispatch(payload: any): void;
|
||||
rpc<T, U>(id: string, payload?: T, transfer?: any): Promise<U>;
|
||||
signal<T>(id: string, payload?: T, transfer?: any): this;
|
||||
registerRpcHandler<T, U>(id: string, handler: RpcProviderInterface.RpcHandler<T, U>): this;
|
||||
registerSignalHandler<T>(id: string, handler: RpcProviderInterface.SignalHandler<T>): this;
|
||||
deregisterRpcHandler<T, U>(id: string, handler: RpcProviderInterface.RpcHandler<T, U>): this;
|
||||
deregisterSignalHandler<T>(id: string, handler: RpcProviderInterface.SignalHandler<T>): this;
|
||||
private _raiseError;
|
||||
private _handleSignal;
|
||||
private _handeRpc;
|
||||
private _handleInternal;
|
||||
private _transactionTimeout;
|
||||
private _clearTransaction;
|
||||
error: Event<Error>;
|
||||
private _rpcHandlers;
|
||||
private _signalHandlers;
|
||||
private _pendingTransactions;
|
||||
private _nextTransactionId;
|
||||
}
|
||||
declare module RpcProvider {
|
||||
enum MessageType {
|
||||
signal = 0,
|
||||
rpc = 1,
|
||||
internal = 2
|
||||
}
|
||||
interface Dispatcher {
|
||||
(message: Message, transfer?: Array<any>): void;
|
||||
}
|
||||
interface Message {
|
||||
type: MessageType;
|
||||
transactionId?: number;
|
||||
id: string;
|
||||
payload?: any;
|
||||
}
|
||||
}
|
||||
export default RpcProvider;
|
166
web/node_modules/worker-rpc/lib/RpcProvider.js
generated
vendored
Normal file
166
web/node_modules/worker-rpc/lib/RpcProvider.js
generated
vendored
Normal file
|
@ -0,0 +1,166 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var microevent_ts_1 = require("microevent.ts");
|
||||
var MSG_RESOLVE_TRANSACTION = "resolve_transaction", MSG_REJECT_TRANSACTION = "reject_transaction", MSG_ERROR = "error";
|
||||
var RpcProvider = /** @class */ (function () {
|
||||
function RpcProvider(_dispatch, _rpcTimeout) {
|
||||
if (_rpcTimeout === void 0) { _rpcTimeout = 0; }
|
||||
this._dispatch = _dispatch;
|
||||
this._rpcTimeout = _rpcTimeout;
|
||||
this.error = new microevent_ts_1.Event();
|
||||
this._rpcHandlers = {};
|
||||
this._signalHandlers = {};
|
||||
this._pendingTransactions = {};
|
||||
this._nextTransactionId = 0;
|
||||
}
|
||||
RpcProvider.prototype.dispatch = function (payload) {
|
||||
var message = payload;
|
||||
switch (message.type) {
|
||||
case RpcProvider.MessageType.signal:
|
||||
return this._handleSignal(message);
|
||||
case RpcProvider.MessageType.rpc:
|
||||
return this._handeRpc(message);
|
||||
case RpcProvider.MessageType.internal:
|
||||
return this._handleInternal(message);
|
||||
default:
|
||||
this._raiseError("invalid message type " + message.type);
|
||||
}
|
||||
};
|
||||
RpcProvider.prototype.rpc = function (id, payload, transfer) {
|
||||
var _this = this;
|
||||
var transactionId = this._nextTransactionId++;
|
||||
this._dispatch({
|
||||
type: RpcProvider.MessageType.rpc,
|
||||
transactionId: transactionId,
|
||||
id: id,
|
||||
payload: payload
|
||||
}, transfer ? transfer : undefined);
|
||||
return new Promise(function (resolve, reject) {
|
||||
var transaction = _this._pendingTransactions[transactionId] = {
|
||||
id: transactionId,
|
||||
resolve: resolve,
|
||||
reject: reject
|
||||
};
|
||||
if (_this._rpcTimeout > 0) {
|
||||
_this._pendingTransactions[transactionId].timeoutHandle =
|
||||
setTimeout(function () { return _this._transactionTimeout(transaction); }, _this._rpcTimeout);
|
||||
}
|
||||
});
|
||||
};
|
||||
;
|
||||
RpcProvider.prototype.signal = function (id, payload, transfer) {
|
||||
this._dispatch({
|
||||
type: RpcProvider.MessageType.signal,
|
||||
id: id,
|
||||
payload: payload,
|
||||
}, transfer ? transfer : undefined);
|
||||
return this;
|
||||
};
|
||||
RpcProvider.prototype.registerRpcHandler = function (id, handler) {
|
||||
if (this._rpcHandlers[id]) {
|
||||
throw new Error("rpc handler for " + id + " already registered");
|
||||
}
|
||||
this._rpcHandlers[id] = handler;
|
||||
return this;
|
||||
};
|
||||
;
|
||||
RpcProvider.prototype.registerSignalHandler = function (id, handler) {
|
||||
if (!this._signalHandlers[id]) {
|
||||
this._signalHandlers[id] = [];
|
||||
}
|
||||
this._signalHandlers[id].push(handler);
|
||||
return this;
|
||||
};
|
||||
RpcProvider.prototype.deregisterRpcHandler = function (id, handler) {
|
||||
if (this._rpcHandlers[id]) {
|
||||
delete this._rpcHandlers[id];
|
||||
}
|
||||
return this;
|
||||
};
|
||||
;
|
||||
RpcProvider.prototype.deregisterSignalHandler = function (id, handler) {
|
||||
if (this._signalHandlers[id]) {
|
||||
this._signalHandlers[id] = this._signalHandlers[id].filter(function (h) { return handler !== h; });
|
||||
}
|
||||
return this;
|
||||
};
|
||||
RpcProvider.prototype._raiseError = function (error) {
|
||||
this.error.dispatch(new Error(error));
|
||||
this._dispatch({
|
||||
type: RpcProvider.MessageType.internal,
|
||||
id: MSG_ERROR,
|
||||
payload: error
|
||||
});
|
||||
};
|
||||
RpcProvider.prototype._handleSignal = function (message) {
|
||||
if (!this._signalHandlers[message.id]) {
|
||||
return this._raiseError("invalid signal " + message.id);
|
||||
}
|
||||
this._signalHandlers[message.id].forEach(function (handler) { return handler(message.payload); });
|
||||
};
|
||||
RpcProvider.prototype._handeRpc = function (message) {
|
||||
var _this = this;
|
||||
if (!this._rpcHandlers[message.id]) {
|
||||
return this._raiseError("invalid rpc " + message.id);
|
||||
}
|
||||
Promise.resolve(this._rpcHandlers[message.id](message.payload))
|
||||
.then(function (result) { return _this._dispatch({
|
||||
type: RpcProvider.MessageType.internal,
|
||||
id: MSG_RESOLVE_TRANSACTION,
|
||||
transactionId: message.transactionId,
|
||||
payload: result
|
||||
}); }, function (reason) { return _this._dispatch({
|
||||
type: RpcProvider.MessageType.internal,
|
||||
id: MSG_REJECT_TRANSACTION,
|
||||
transactionId: message.transactionId,
|
||||
payload: reason
|
||||
}); });
|
||||
};
|
||||
RpcProvider.prototype._handleInternal = function (message) {
|
||||
switch (message.id) {
|
||||
case MSG_RESOLVE_TRANSACTION:
|
||||
if (!this._pendingTransactions[message.transactionId]) {
|
||||
return this._raiseError("no pending transaction with id " + message.transactionId);
|
||||
}
|
||||
this._pendingTransactions[message.transactionId].resolve(message.payload);
|
||||
this._clearTransaction(this._pendingTransactions[message.transactionId]);
|
||||
break;
|
||||
case MSG_REJECT_TRANSACTION:
|
||||
if (!this._pendingTransactions[message.transactionId]) {
|
||||
return this._raiseError("no pending transaction with id " + message.transactionId);
|
||||
}
|
||||
this._pendingTransactions[message.transactionId].reject(message.payload);
|
||||
this._clearTransaction(this._pendingTransactions[message.transactionId]);
|
||||
break;
|
||||
case MSG_ERROR:
|
||||
this.error.dispatch(new Error("remote error: " + message.payload));
|
||||
break;
|
||||
default:
|
||||
this._raiseError("unhandled internal message " + message.id);
|
||||
break;
|
||||
}
|
||||
};
|
||||
RpcProvider.prototype._transactionTimeout = function (transaction) {
|
||||
transaction.reject('transaction timed out');
|
||||
this._raiseError("transaction " + transaction.id + " timed out");
|
||||
delete this._pendingTransactions[transaction.id];
|
||||
return;
|
||||
};
|
||||
RpcProvider.prototype._clearTransaction = function (transaction) {
|
||||
if (typeof (transaction.timeoutHandle) !== 'undefined') {
|
||||
clearTimeout(transaction.timeoutHandle);
|
||||
}
|
||||
delete this._pendingTransactions[transaction.id];
|
||||
};
|
||||
return RpcProvider;
|
||||
}());
|
||||
(function (RpcProvider) {
|
||||
var MessageType;
|
||||
(function (MessageType) {
|
||||
MessageType[MessageType["signal"] = 0] = "signal";
|
||||
MessageType[MessageType["rpc"] = 1] = "rpc";
|
||||
MessageType[MessageType["internal"] = 2] = "internal";
|
||||
})(MessageType = RpcProvider.MessageType || (RpcProvider.MessageType = {}));
|
||||
;
|
||||
})(RpcProvider || (RpcProvider = {}));
|
||||
exports.default = RpcProvider;
|
20
web/node_modules/worker-rpc/lib/RpcProviderInterface.d.ts
generated
vendored
Normal file
20
web/node_modules/worker-rpc/lib/RpcProviderInterface.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { EventInterface } from 'microevent.ts';
|
||||
interface RpcProviderInterface {
|
||||
dispatch(message: any): void;
|
||||
rpc<T, U>(id: string, payload?: T, transfer?: Array<any>): Promise<U>;
|
||||
signal<T>(id: string, payload?: T, transfer?: Array<any>): this;
|
||||
registerRpcHandler<T, U>(id: string, handler: RpcProviderInterface.RpcHandler<T, U>): this;
|
||||
registerSignalHandler<T>(id: string, handler: RpcProviderInterface.SignalHandler<T>): this;
|
||||
deregisterRpcHandler<T, U>(id: string, handler: RpcProviderInterface.RpcHandler<T, U>): this;
|
||||
deregisterSignalHandler<T>(id: string, handler: RpcProviderInterface.SignalHandler<T>): this;
|
||||
error: EventInterface<Error>;
|
||||
}
|
||||
declare module RpcProviderInterface {
|
||||
interface RpcHandler<T, U> {
|
||||
(payload?: T): Promise<U> | U;
|
||||
}
|
||||
interface SignalHandler<T> {
|
||||
(payload?: T): void;
|
||||
}
|
||||
}
|
||||
export default RpcProviderInterface;
|
2
web/node_modules/worker-rpc/lib/RpcProviderInterface.js
generated
vendored
Normal file
2
web/node_modules/worker-rpc/lib/RpcProviderInterface.js
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
2
web/node_modules/worker-rpc/lib/index.d.ts
generated
vendored
Normal file
2
web/node_modules/worker-rpc/lib/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
export { default as RpcProvider } from './RpcProvider';
|
||||
export { default as RpcProviderInterface } from './RpcProviderInterface';
|
4
web/node_modules/worker-rpc/lib/index.js
generated
vendored
Normal file
4
web/node_modules/worker-rpc/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var RpcProvider_1 = require("./RpcProvider");
|
||||
exports.RpcProvider = RpcProvider_1.default;
|
Loading…
Add table
Add a link
Reference in a new issue