buildbot-data
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "buildbot-data", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"homepage": "https://github.com/tothandras/buildbot-data", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -22,2 +22,4 @@ (function() { | ||
function LoggingInterceptor($httpProvider) { | ||
/* @ngInject */ | ||
$httpProvider.interceptors.push(function($log, API) { | ||
@@ -164,99 +166,2 @@ return { | ||
(function() { | ||
describe('Base class', function() { | ||
var $q, Base, dataService, injected, socketService; | ||
beforeEach(module('bbData')); | ||
Base = dataService = socketService = $q = null; | ||
injected = function($injector) { | ||
Base = $injector.get('Base'); | ||
dataService = $injector.get('dataService'); | ||
socketService = $injector.get('socketService'); | ||
return $q = $injector.get('$q'); | ||
}; | ||
beforeEach(inject(injected)); | ||
it('should be defined', function() { | ||
return expect(Base).toBeDefined(); | ||
}); | ||
it('should merge the passed in object with the instance', function() { | ||
var base, object; | ||
object = { | ||
a: 1, | ||
b: 2 | ||
}; | ||
base = new Base(object, 'ab'); | ||
expect(base.a).toEqual(object.a); | ||
return expect(base.b).toEqual(object.b); | ||
}); | ||
it('should have loadXxx function for child endpoints', function() { | ||
var E, base, children, e, i, len, results; | ||
children = ['a', 'bcd', 'ccc']; | ||
base = new Base({}, 'ab', children); | ||
results = []; | ||
for (i = 0, len = children.length; i < len; i++) { | ||
e = children[i]; | ||
E = e[0].toUpperCase() + e.slice(1).toLowerCase(); | ||
results.push(expect(angular.isFunction(base["load" + E])).toBeTruthy()); | ||
} | ||
return results; | ||
}); | ||
it('should subscribe a listener to socket service events', function() { | ||
var base; | ||
expect(socketService.eventStream.listeners.length).toBe(0); | ||
base = new Base({}, 'ab'); | ||
return expect(socketService.eventStream.listeners.length).toBe(1); | ||
}); | ||
it('should remove the listener on unsubscribe', function() { | ||
var base; | ||
expect(socketService.eventStream.listeners.length).toBe(0); | ||
base = new Base({}, 'ab'); | ||
expect(socketService.eventStream.listeners.length).toBe(1); | ||
base.unsubscribe(); | ||
return expect(socketService.eventStream.listeners.length).toBe(0); | ||
}); | ||
it('should update the instance when the event key matches', function() { | ||
var base, object; | ||
object = { | ||
buildid: 1, | ||
a: 2, | ||
b: 3 | ||
}; | ||
base = new Base(object, 'builds'); | ||
expect(base.a).toEqual(object.a); | ||
socketService.eventStream.push({ | ||
k: 'builds/2/update', | ||
m: { | ||
a: 3 | ||
} | ||
}); | ||
expect(base.a).toEqual(object.a); | ||
socketService.eventStream.push({ | ||
k: 'builds/1/update', | ||
m: { | ||
a: 3, | ||
c: 4 | ||
} | ||
}); | ||
expect(base.a).toEqual(3); | ||
return expect(base.c).toEqual(4); | ||
}); | ||
return it('should remove the listeners of child endpoints on unsubscribe', function() { | ||
var base, child, p, response; | ||
base = new Base({}, '', ['ccc']); | ||
child = new Base({}, ''); | ||
response = [child]; | ||
p = $q.resolve(response); | ||
p.getArray = function() { | ||
return response; | ||
}; | ||
spyOn(dataService, 'get').and.returnValue(p); | ||
base.loadCcc(); | ||
expect(base.ccc).toEqual(response); | ||
expect(socketService.eventStream.listeners.length).toBe(2); | ||
base.unsubscribe(); | ||
return expect(socketService.eventStream.listeners.length).toBe(0); | ||
}); | ||
}); | ||
}).call(this); | ||
(function() { | ||
var Build, | ||
@@ -762,2 +667,6 @@ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
DataService.prototype.getSpecification = function() { | ||
return restService.get('application.spec'); | ||
}; | ||
DataService.prototype.getNextId = function() { | ||
@@ -847,3 +756,3 @@ if (this.jsonrpc == null) { | ||
angular.module('bbData').provider('dataProvider', [Data]); | ||
angular.module('bbData').provider('dataService', [Data]); | ||
@@ -853,247 +762,58 @@ }).call(this); | ||
(function() { | ||
describe('Data service', function() { | ||
var $httpBackend, $q, $rootScope, ENDPOINTS, dataService, injected, restService, socketService; | ||
beforeEach(module('bbData')); | ||
dataService = restService = socketService = ENDPOINTS = $rootScope = $q = $httpBackend = null; | ||
injected = function($injector) { | ||
dataService = $injector.get('dataService'); | ||
restService = $injector.get('restService'); | ||
socketService = $injector.get('socketService'); | ||
ENDPOINTS = $injector.get('ENDPOINTS'); | ||
$rootScope = $injector.get('$rootScope'); | ||
$q = $injector.get('$q'); | ||
return $httpBackend = $injector.get('$httpBackend'); | ||
}; | ||
beforeEach(inject(injected)); | ||
it('should be defined', function() { | ||
return expect(dataService).toBeDefined(); | ||
}); | ||
it('should have getXxx functions for endpoints', function() { | ||
var E, e, i, len, results; | ||
results = []; | ||
for (i = 0, len = ENDPOINTS.length; i < len; i++) { | ||
e = ENDPOINTS[i]; | ||
E = e[0].toUpperCase() + e.slice(1).toLowerCase(); | ||
expect(dataService["get" + E]).toBeDefined(); | ||
results.push(expect(angular.isFunction(dataService["get" + E])).toBeTruthy()); | ||
} | ||
return results; | ||
}); | ||
describe('get()', function() { | ||
it('should return a promise', function() { | ||
var p; | ||
p = dataService.getBuilds(); | ||
expect(angular.isFunction(p.then)).toBeTruthy(); | ||
return expect(angular.isFunction(p.getArray)).toBeTruthy(); | ||
}); | ||
it('should call get for the rest api endpoint', function() { | ||
var d; | ||
d = $q.defer(); | ||
spyOn(restService, 'get').and.returnValue(d.promise); | ||
expect(restService.get).not.toHaveBeenCalled(); | ||
$rootScope.$apply(function() { | ||
return dataService.get('asd', { | ||
subscribe: false | ||
}); | ||
}); | ||
return expect(restService.get).toHaveBeenCalledWith('asd', {}); | ||
}); | ||
it('should send startConsuming with the socket path', function() { | ||
var d; | ||
d = $q.defer(); | ||
spyOn(socketService, 'send').and.returnValue(d.promise); | ||
expect(socketService.send).not.toHaveBeenCalled(); | ||
$rootScope.$apply(function() { | ||
return dataService.get('asd'); | ||
}); | ||
expect(socketService.send).toHaveBeenCalledWith({ | ||
cmd: 'startConsuming', | ||
path: 'asd/*/*' | ||
}); | ||
$rootScope.$apply(function() { | ||
return dataService.get('asd', 1); | ||
}); | ||
return expect(socketService.send).toHaveBeenCalledWith({ | ||
cmd: 'startConsuming', | ||
path: 'asd/1/*' | ||
}); | ||
}); | ||
it('should not call startConsuming when {subscribe: false} is passed in', function() { | ||
var d; | ||
d = $q.defer(); | ||
spyOn(restService, 'get').and.returnValue(d.promise); | ||
spyOn(dataService, 'startConsuming'); | ||
expect(dataService.startConsuming).not.toHaveBeenCalled(); | ||
$rootScope.$apply(function() { | ||
return dataService.getBuilds({ | ||
subscribe: false | ||
}); | ||
}); | ||
return expect(dataService.startConsuming).not.toHaveBeenCalled(); | ||
}); | ||
return it('should add the new instance on /new WebSocket message', function() { | ||
var builds; | ||
spyOn(restService, 'get').and.returnValue($q.resolve({ | ||
builds: [] | ||
})); | ||
builds = null; | ||
$rootScope.$apply(function() { | ||
return builds = dataService.getBuilds({ | ||
subscribe: false | ||
}).getArray(); | ||
}); | ||
socketService.eventStream.push({ | ||
k: 'builds/111/new', | ||
m: { | ||
asd: 111 | ||
} | ||
}); | ||
return expect(builds.pop().asd).toBe(111); | ||
}); | ||
}); | ||
describe('control(method, params)', function() { | ||
return it('should send a jsonrpc message using POST', function() { | ||
var method, params; | ||
spyOn(restService, 'post'); | ||
expect(restService.post).not.toHaveBeenCalled(); | ||
method = 'force'; | ||
params = { | ||
a: 1 | ||
}; | ||
dataService.control(method, params); | ||
return expect(restService.post).toHaveBeenCalledWith({ | ||
id: 1, | ||
jsonrpc: '2.0', | ||
method: method, | ||
params: params | ||
}); | ||
}); | ||
}); | ||
return describe('open()', function() { | ||
var opened; | ||
opened = null; | ||
beforeEach(function() { | ||
return opened = dataService.open(); | ||
}); | ||
it('should return a new accessor', function() { | ||
return expect(opened).toEqual(jasmine.any(Object)); | ||
}); | ||
it('should have getXxx functions for endpoints', function() { | ||
var E, e, i, len, results; | ||
results = []; | ||
for (i = 0, len = ENDPOINTS.length; i < len; i++) { | ||
e = ENDPOINTS[i]; | ||
E = e[0].toUpperCase() + e.slice(1).toLowerCase(); | ||
expect(opened["get" + E]).toBeDefined(); | ||
results.push(expect(angular.isFunction(opened["get" + E])).toBeTruthy()); | ||
} | ||
return results; | ||
}); | ||
it('should call unsubscribe on each root class on close', function() { | ||
var b, builds, i, j, k, len, len1, len2, p, results; | ||
p = $q.resolve({ | ||
builds: [{}, {}, {}] | ||
}); | ||
spyOn(restService, 'get').and.returnValue(p); | ||
builds = null; | ||
$rootScope.$apply(function() { | ||
return builds = opened.getBuilds({ | ||
subscribe: false | ||
}).getArray(); | ||
}); | ||
expect(builds.length).toBe(3); | ||
for (i = 0, len = builds.length; i < len; i++) { | ||
b = builds[i]; | ||
spyOn(b, 'unsubscribe'); | ||
} | ||
for (j = 0, len1 = builds.length; j < len1; j++) { | ||
b = builds[j]; | ||
expect(b.unsubscribe).not.toHaveBeenCalled(); | ||
} | ||
opened.close(); | ||
results = []; | ||
for (k = 0, len2 = builds.length; k < len2; k++) { | ||
b = builds[k]; | ||
results.push(expect(b.unsubscribe).toHaveBeenCalled()); | ||
} | ||
return results; | ||
}); | ||
return it('should call close when the $scope is destroyed', function() { | ||
var scope; | ||
spyOn(opened, 'close'); | ||
scope = $rootScope.$new(); | ||
opened.closeOnDestroy(scope); | ||
expect(opened.close).not.toHaveBeenCalled(); | ||
scope.$destroy(); | ||
return expect(opened.close).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
}).call(this); | ||
(function() { | ||
var DataUtils; | ||
DataUtils = (function() { | ||
function DataUtils() { | ||
return new (DataUtils = (function() { | ||
function DataUtils() {} | ||
function DataUtils() {} | ||
DataUtils.prototype.capitalize = function(w) { | ||
return w[0].toUpperCase() + w.slice(1).toLowerCase(); | ||
}; | ||
DataUtils.prototype.capitalize = function(w) { | ||
return w[0].toUpperCase() + w.slice(1).toLowerCase(); | ||
}; | ||
DataUtils.prototype.type = function(e) { | ||
var name, parsed, splitted; | ||
splitted = e.split('/'); | ||
while (true) { | ||
name = splitted.pop(); | ||
parsed = parseInt(name); | ||
if (splitted.length === 0 || !(angular.isNumber(parsed) && !isNaN(parsed))) { | ||
break; | ||
} | ||
} | ||
return name; | ||
}; | ||
DataUtils.prototype.type = function(e) { | ||
var name, parsed, splitted; | ||
splitted = e.split('/'); | ||
while (true) { | ||
name = splitted.pop(); | ||
parsed = parseInt(name); | ||
if (splitted.length === 0 || !(angular.isNumber(parsed) && !isNaN(parsed))) { | ||
break; | ||
} | ||
} | ||
return name; | ||
}; | ||
DataUtils.prototype.singularType = function(e) { | ||
return this.type(e).replace(/s$/, ''); | ||
}; | ||
DataUtils.prototype.singularType = function(e) { | ||
return this.type(e).replace(/s$/, ''); | ||
}; | ||
DataUtils.prototype.classId = function(e) { | ||
return this.singularType(e) + 'id'; | ||
}; | ||
DataUtils.prototype.classId = function(e) { | ||
return this.singularType(e) + 'id'; | ||
}; | ||
DataUtils.prototype.className = function(e) { | ||
return this.capitalize(this.singularType(e)); | ||
}; | ||
DataUtils.prototype.className = function(e) { | ||
return this.capitalize(this.singularType(e)); | ||
}; | ||
DataUtils.prototype.socketPath = function(args) { | ||
var stars; | ||
stars = ['*']; | ||
if (args.length % 2 === 1) { | ||
stars.push('*'); | ||
} | ||
return args.concat(stars).join('/'); | ||
}; | ||
DataUtils.prototype.socketPath = function(args) { | ||
var stars; | ||
stars = ['*']; | ||
if (args.length % 2 === 1) { | ||
stars.push('*'); | ||
} | ||
return args.concat(stars).join('/'); | ||
}; | ||
DataUtils.prototype.restPath = function(args) { | ||
return args.slice().join('/'); | ||
}; | ||
DataUtils.prototype.restPath = function(args) { | ||
return args.slice().join('/'); | ||
}; | ||
DataUtils.prototype.endpointPath = function(args) { | ||
var argsCopy; | ||
argsCopy = args.slice(); | ||
if (argsCopy.length % 2 === 0) { | ||
argsCopy.pop(); | ||
} | ||
return argsCopy.join('/'); | ||
}; | ||
DataUtils.prototype.endpointPath = function(args) { | ||
var argsCopy; | ||
argsCopy = args.slice(); | ||
if (argsCopy.length % 2 === 0) { | ||
argsCopy.pop(); | ||
} | ||
return argsCopy.join('/'); | ||
}; | ||
return DataUtils; | ||
})()); | ||
} | ||
return DataUtils; | ||
@@ -1108,78 +828,2 @@ | ||
(function() { | ||
describe('Helper service', function() { | ||
var dataUtilsService, injected; | ||
beforeEach(module('bbData')); | ||
dataUtilsService = null; | ||
injected = function($injector) { | ||
return dataUtilsService = $injector.get('dataUtilsService'); | ||
}; | ||
beforeEach(inject(injected)); | ||
it('should be defined', function() { | ||
return expect(dataUtilsService).toBeDefined(); | ||
}); | ||
it('should capitalize the first word', function() { | ||
expect(dataUtilsService.capitalize('abc')).toBe('Abc'); | ||
return expect(dataUtilsService.capitalize('abc cba')).toBe('Abc cba'); | ||
}); | ||
it('should return the endpoint name for rest endpoints', function() { | ||
var k, results, tests, v; | ||
tests = { | ||
'builders/100/forceschedulers': 'forcescheduler', | ||
'builders/1/builds': 'build', | ||
'builders/2/builds/1': 'build' | ||
}; | ||
results = []; | ||
for (k in tests) { | ||
v = tests[k]; | ||
results.push(expect(dataUtilsService.singularType(k)).toBe(v)); | ||
} | ||
return results; | ||
}); | ||
it('should return the class name for rest endpoints', function() { | ||
var k, results, tests, v; | ||
tests = { | ||
'builders/100/forceschedulers': 'Forcescheduler', | ||
'builders/1/builds': 'Build', | ||
'builders/2/builds/1': 'Build' | ||
}; | ||
results = []; | ||
for (k in tests) { | ||
v = tests[k]; | ||
results.push(expect(dataUtilsService.className(k)).toBe(v)); | ||
} | ||
return results; | ||
}); | ||
it('should return the WebSocket path for an endpoint', function() { | ||
var k, results, tests, v; | ||
tests = { | ||
'builders/100/forceschedulers/*/*': ['builders', 100, 'forceschedulers'], | ||
'builders/1/builds/*/*': ['builders', 1, 'builds'], | ||
'builders/2/builds/1/*': ['builders', 2, 'builds', 1] | ||
}; | ||
results = []; | ||
for (k in tests) { | ||
v = tests[k]; | ||
results.push(expect(dataUtilsService.socketPath(v)).toBe(k)); | ||
} | ||
return results; | ||
}); | ||
return it('should return the path for an endpoint', function() { | ||
var k, results, tests, v; | ||
tests = { | ||
'builders/100/forceschedulers': ['builders', 100, 'forceschedulers'], | ||
'builders/1/builds': ['builders', 1, 'builds'], | ||
'builders/2/builds': ['builders', 2, 'builds', 1] | ||
}; | ||
results = []; | ||
for (k in tests) { | ||
v = tests[k]; | ||
results.push(expect(dataUtilsService.endpointPath(v)).toBe(k)); | ||
} | ||
return results; | ||
}); | ||
}); | ||
}).call(this); | ||
(function() { | ||
var Rest, | ||
@@ -1265,95 +909,2 @@ slice = [].slice; | ||
(function() { | ||
describe('Rest service', function() { | ||
var $httpBackend, injected, restService; | ||
beforeEach(module('bbData')); | ||
beforeEach(function() { | ||
return module(function($provide) { | ||
return $provide.constant('API', '/api/'); | ||
}); | ||
}); | ||
restService = $httpBackend = null; | ||
injected = function($injector) { | ||
restService = $injector.get('restService'); | ||
return $httpBackend = $injector.get('$httpBackend'); | ||
}; | ||
beforeEach(inject(injected)); | ||
afterEach(function() { | ||
$httpBackend.verifyNoOutstandingExpectation(); | ||
return $httpBackend.verifyNoOutstandingRequest(); | ||
}); | ||
it('should be defined', function() { | ||
return expect(restService).toBeDefined(); | ||
}); | ||
it('should make an ajax GET call to /api/endpoint', function() { | ||
var gotResponse, response; | ||
response = { | ||
a: 'A' | ||
}; | ||
$httpBackend.whenGET('/api/endpoint').respond(response); | ||
gotResponse = null; | ||
restService.get('endpoint').then(function(r) { | ||
return gotResponse = r; | ||
}); | ||
expect(gotResponse).toBeNull(); | ||
$httpBackend.flush(); | ||
return expect(gotResponse).toEqual(response); | ||
}); | ||
it('should make an ajax GET call to /api/endpoint with parameters', function() { | ||
var params; | ||
params = { | ||
key: 'value' | ||
}; | ||
$httpBackend.whenGET('/api/endpoint?key=value').respond(200); | ||
restService.get('endpoint', params); | ||
return $httpBackend.flush(); | ||
}); | ||
it('should reject the promise on error', function() { | ||
var error, gotResponse; | ||
error = 'Internal server error'; | ||
$httpBackend.expectGET('/api/endpoint').respond(500, error); | ||
gotResponse = null; | ||
restService.get('endpoint').then(function(response) { | ||
return gotResponse = response; | ||
}, function(reason) { | ||
return gotResponse = reason; | ||
}); | ||
$httpBackend.flush(); | ||
return expect(gotResponse).toBe(error); | ||
}); | ||
it('should make an ajax POST call to /api/endpoint', function() { | ||
var data, gotResponse, response; | ||
response = {}; | ||
data = { | ||
b: 'B' | ||
}; | ||
$httpBackend.expectPOST('/api/endpoint', data).respond(response); | ||
gotResponse = null; | ||
restService.post('endpoint', data).then(function(r) { | ||
return gotResponse = r; | ||
}); | ||
$httpBackend.flush(); | ||
return expect(gotResponse).toEqual(response); | ||
}); | ||
return it('should reject the promise when the response is not valid JSON', function() { | ||
var data, gotResponse, response; | ||
response = 'aaa'; | ||
data = { | ||
b: 'B' | ||
}; | ||
$httpBackend.expectPOST('/api/endpoint', data).respond(response); | ||
gotResponse = null; | ||
restService.post('endpoint', data).then(function(response) { | ||
return gotResponse = response; | ||
}, function(reason) { | ||
return gotResponse = reason; | ||
}); | ||
$httpBackend.flush(); | ||
expect(gotResponse).not.toBeNull(); | ||
return expect(gotResponse).not.toEqual(response); | ||
}); | ||
}); | ||
}).call(this); | ||
(function() { | ||
var Socket; | ||
@@ -1475,156 +1026,2 @@ | ||
(function() { | ||
describe('Socket service', function() { | ||
var $rootScope, WebSocketBackend, injected, socket, socketService, webSocketBackend; | ||
WebSocketBackend = (function() { | ||
var MockWebSocket, self; | ||
WebSocketBackend.prototype.sendQueue = []; | ||
WebSocketBackend.prototype.receiveQueue = []; | ||
self = null; | ||
function WebSocketBackend() { | ||
self = this; | ||
this.webSocket = new MockWebSocket(); | ||
} | ||
WebSocketBackend.prototype.send = function(message) { | ||
var data; | ||
data = { | ||
data: message | ||
}; | ||
return this.sendQueue.push(data); | ||
}; | ||
WebSocketBackend.prototype.flush = function() { | ||
var message, results; | ||
results = []; | ||
while (message = this.sendQueue.shift()) { | ||
results.push(this.webSocket.onmessage(message)); | ||
} | ||
return results; | ||
}; | ||
WebSocketBackend.prototype.getWebSocket = function() { | ||
return this.webSocket; | ||
}; | ||
MockWebSocket = (function() { | ||
function MockWebSocket() {} | ||
MockWebSocket.prototype.OPEN = 1; | ||
MockWebSocket.prototype.send = function(message) { | ||
return self.receiveQueue.push(message); | ||
}; | ||
return MockWebSocket; | ||
})(); | ||
return WebSocketBackend; | ||
})(); | ||
webSocketBackend = new WebSocketBackend(); | ||
beforeEach(function() { | ||
module('bbData'); | ||
return module(function($provide) { | ||
return $provide.constant('webSocketService', webSocketBackend); | ||
}); | ||
}); | ||
$rootScope = socketService = socket = null; | ||
injected = function($injector) { | ||
$rootScope = $injector.get('$rootScope'); | ||
socketService = $injector.get('socketService'); | ||
socket = socketService.socket; | ||
spyOn(socket, 'send').and.callThrough(); | ||
return spyOn(socket, 'onmessage').and.callThrough(); | ||
}; | ||
beforeEach(inject(injected)); | ||
it('should be defined', function() { | ||
return expect(socketService).toBeDefined(); | ||
}); | ||
it('should send the data, when the WebSocket is open', function() { | ||
var msg1, msg2, msg3; | ||
socket.readyState = 0; | ||
msg1 = { | ||
a: 1 | ||
}; | ||
msg2 = { | ||
b: 2 | ||
}; | ||
msg3 = { | ||
c: 3 | ||
}; | ||
socketService.send(msg1); | ||
socketService.send(msg2); | ||
expect(socket.send).not.toHaveBeenCalled(); | ||
socket.onopen(); | ||
expect(socket.send).toHaveBeenCalled(); | ||
expect(webSocketBackend.receiveQueue).toContain(angular.toJson(msg1)); | ||
expect(webSocketBackend.receiveQueue).toContain(angular.toJson(msg2)); | ||
return expect(webSocketBackend.receiveQueue).not.toContain(angular.toJson(msg3)); | ||
}); | ||
it('should add an _id to each message', function() { | ||
var argument; | ||
socket.readyState = 1; | ||
expect(socket.send).not.toHaveBeenCalled(); | ||
socketService.send({}); | ||
expect(socket.send).toHaveBeenCalledWith(jasmine.any(String)); | ||
argument = socket.send.calls.argsFor(0)[0]; | ||
return expect(angular.fromJson(argument)._id).toBeDefined(); | ||
}); | ||
it('should resolve the promise when a response message is received with code 200', function() { | ||
var argument, handler, id, msg, promise, response; | ||
socket.readyState = 1; | ||
msg = { | ||
cmd: 'command' | ||
}; | ||
promise = socketService.send(msg); | ||
handler = jasmine.createSpy('handler'); | ||
promise.then(handler); | ||
expect(handler).not.toHaveBeenCalled(); | ||
argument = socket.send.calls.argsFor(0)[0]; | ||
id = angular.fromJson(argument)._id; | ||
response = angular.toJson({ | ||
_id: id, | ||
code: 200 | ||
}); | ||
webSocketBackend.send(response); | ||
$rootScope.$apply(function() { | ||
return webSocketBackend.flush(); | ||
}); | ||
return expect(handler).toHaveBeenCalled(); | ||
}); | ||
return it('should reject the promise when a response message is received, but the code is not 200', function() { | ||
var argument, errorHandler, handler, id, msg, promise, response; | ||
socket.readyState = 1; | ||
msg = { | ||
cmd: 'command' | ||
}; | ||
promise = socketService.send(msg); | ||
handler = jasmine.createSpy('handler'); | ||
errorHandler = jasmine.createSpy('errorHandler'); | ||
promise.then(handler, errorHandler); | ||
expect(handler).not.toHaveBeenCalled(); | ||
expect(errorHandler).not.toHaveBeenCalled(); | ||
argument = socket.send.calls.argsFor(0)[0]; | ||
id = angular.fromJson(argument)._id; | ||
response = angular.toJson({ | ||
_id: id, | ||
code: 500 | ||
}); | ||
webSocketBackend.send(response); | ||
$rootScope.$apply(function() { | ||
return webSocketBackend.flush(); | ||
}); | ||
expect(handler).not.toHaveBeenCalled(); | ||
return expect(errorHandler).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}).call(this); | ||
(function() { | ||
var WebSocket; | ||
@@ -1734,98 +1131,1 @@ | ||
}).call(this); | ||
(function() { | ||
describe('Stream service', function() { | ||
var Stream, injected, stream; | ||
beforeEach(module('bbData')); | ||
Stream = stream = null; | ||
injected = function($injector) { | ||
Stream = $injector.get('Stream'); | ||
return stream = new Stream(); | ||
}; | ||
beforeEach(inject(injected)); | ||
it('should be defined', function() { | ||
expect(Stream).toBeDefined(); | ||
return expect(stream).toBeDefined(); | ||
}); | ||
it('should add the listener to listeners on subscribe call', function() { | ||
var listeners; | ||
listeners = stream.listeners; | ||
expect(listeners.length).toBe(0); | ||
stream.subscribe(function() {}); | ||
return expect(listeners.length).toBe(1); | ||
}); | ||
it('should add a unique id to each listener passed in to subscribe', function() { | ||
var listener1, listener2, listeners; | ||
listeners = stream.listeners; | ||
listener1 = function() {}; | ||
listener2 = function() {}; | ||
stream.subscribe(listener1); | ||
stream.subscribe(listener2); | ||
expect(listener1.id).toBeDefined(); | ||
expect(listener2.id).toBeDefined(); | ||
return expect(listener1.id).not.toBe(listener2.id); | ||
}); | ||
it('should return the unsubscribe function on subscribe call', function() { | ||
var listener, listeners, otherListener, unsubscribe; | ||
listeners = stream.listeners; | ||
listener = function() {}; | ||
otherListener = function() {}; | ||
unsubscribe = stream.subscribe(listener); | ||
stream.subscribe(otherListener); | ||
expect(listeners).toContain(listener); | ||
unsubscribe(); | ||
expect(listeners).not.toContain(listener); | ||
return expect(listeners).toContain(otherListener); | ||
}); | ||
it('should call all listeners on push call', function() { | ||
var data, listeners; | ||
data = { | ||
a: 'A', | ||
b: 'B' | ||
}; | ||
listeners = { | ||
first: function(data) { | ||
return expect(data).toEqual({ | ||
a: 'A', | ||
b: 'B' | ||
}); | ||
}, | ||
second: function(data) { | ||
return expect(data).toEqual({ | ||
a: 'A', | ||
b: 'B' | ||
}); | ||
} | ||
}; | ||
spyOn(listeners, 'first').and.callThrough(); | ||
spyOn(listeners, 'second').and.callThrough(); | ||
stream.subscribe(listeners.first); | ||
stream.subscribe(listeners.second); | ||
expect(listeners.first).not.toHaveBeenCalled(); | ||
expect(listeners.second).not.toHaveBeenCalled(); | ||
stream.push(data); | ||
expect(listeners.first).toHaveBeenCalled(); | ||
return expect(listeners.second).toHaveBeenCalled(); | ||
}); | ||
it('should remove all listeners on destroy call', function() { | ||
var listeners; | ||
listeners = stream.listeners; | ||
expect(listeners.length).toBe(0); | ||
stream.subscribe(function() {}); | ||
stream.subscribe(function() {}); | ||
expect(listeners.length).not.toBe(0); | ||
stream.destroy(); | ||
return expect(listeners.length).toBe(0); | ||
}); | ||
return it('should call the unsubscribe listener on unsubscribe call', function() { | ||
var listener, unsubscribe; | ||
spyOn(stream, 'onUnsubscribe'); | ||
listener = function() {}; | ||
unsubscribe = stream.subscribe(listener); | ||
expect(stream.onUnsubscribe).not.toHaveBeenCalled(); | ||
unsubscribe(); | ||
return expect(stream.onUnsubscribe).toHaveBeenCalledWith(listener); | ||
}); | ||
}); | ||
}).call(this); |
@@ -1,1 +0,1 @@ | ||
(function(){var e;e=function(){function e(){return[]}return e}(),angular.module("bbData",new e)}).call(this),function(){var e;e=function(){function e(e){e.interceptors.push(function(e,t){return{request:function(n){return 0===n.url.indexOf(t)&&e.debug(n.method+" "+n.url),n}}})}return e}(),angular.module("bbData").config(["$httpProvider",e])}.call(this),function(){var e,t;e=function(){function e(){return"api/v2/"}return e}(),t=function(){function e(){return["builders","builds","buildrequests","buildslaves","buildsets","changes","changesources","masters","sourcestamps","schedulers","forceschedulers"]}return e}(),angular.module("bbData").constant("API",e()).constant("ENDPOINTS",t())}.call(this),function(){var e,t=[].slice;e=function(){function e(e,n,r){var o;return o=function(){function o(e,t,n){var o;if(this.endpoint=t,null==n&&(n=[]),!angular.isString(this.endpoint))throw new TypeError("Parameter 'endpoint' must be a string, not "+typeof this.endpoint);this.update(e),this.constructor.generateFunctions(n),o=r.classId(this.endpoint),this.id=this[o],this.subscribe()}return o.prototype.update=function(e){return angular.merge(this,e)},o.prototype.get=function(){var n;return n=1<=arguments.length?t.call(arguments,0):[],e.get.apply(e,[this.endpoint,this.id].concat(t.call(n)))},o.prototype.subscribe=function(){var e;return e=function(e){return function(t){var n,r,o;return n=t.k,r=t.m,o=RegExp("^"+e.endpoint+"\\/"+e.id+"\\/\\w+$","g"),o.test(n)?e.update(r):void 0}}(this),this.unsubscribeEventListener=n.eventStream.subscribe(e),this.listenerId=e.id},o.prototype.unsubscribe=function(){var e,t;for(e in this)t=this[e],angular.isArray(t)&&t.forEach(function(e){return e instanceof o?e.unsubscribe():void 0});return this.unsubscribeEventListener()},o.generateFunctions=function(e){return e.forEach(function(e){return function(n){var o;return o=r.capitalize(n),e.prototype["load"+o]=function(){var e,r;return e=1<=arguments.length?t.call(arguments,0):[],r=this.get.apply(this,[n].concat(t.call(e))),this[n]=r.getArray(),r}}}(this))},o}()}return e}(),angular.module("bbData").factory("Base",["dataService","socketService","dataUtilsService",e])}.call(this),function(){describe("Base class",function(){var e,t,n,r,o;return beforeEach(module("bbData")),t=n=o=e=null,r=function(r){return t=r.get("Base"),n=r.get("dataService"),o=r.get("socketService"),e=r.get("$q")},beforeEach(inject(r)),it("should be defined",function(){return expect(t).toBeDefined()}),it("should merge the passed in object with the instance",function(){var e,n;return n={a:1,b:2},e=new t(n,"ab"),expect(e.a).toEqual(n.a),expect(e.b).toEqual(n.b)}),it("should have loadXxx function for child endpoints",function(){var e,n,r,o,u,i,s;for(r=["a","bcd","ccc"],n=new t({},"ab",r),s=[],u=0,i=r.length;i>u;u++)o=r[u],e=o[0].toUpperCase()+o.slice(1).toLowerCase(),s.push(expect(angular.isFunction(n["load"+e])).toBeTruthy());return s}),it("should subscribe a listener to socket service events",function(){var e;return expect(o.eventStream.listeners.length).toBe(0),e=new t({},"ab"),expect(o.eventStream.listeners.length).toBe(1)}),it("should remove the listener on unsubscribe",function(){var e;return expect(o.eventStream.listeners.length).toBe(0),e=new t({},"ab"),expect(o.eventStream.listeners.length).toBe(1),e.unsubscribe(),expect(o.eventStream.listeners.length).toBe(0)}),it("should update the instance when the event key matches",function(){var e,n;return n={buildid:1,a:2,b:3},e=new t(n,"builds"),expect(e.a).toEqual(n.a),o.eventStream.push({k:"builds/2/update",m:{a:3}}),expect(e.a).toEqual(n.a),o.eventStream.push({k:"builds/1/update",m:{a:3,c:4}}),expect(e.a).toEqual(3),expect(e.c).toEqual(4)}),it("should remove the listeners of child endpoints on unsubscribe",function(){var r,u,i,s;return r=new t({},"",["ccc"]),u=new t({},""),s=[u],i=e.resolve(s),i.getArray=function(){return s},spyOn(n,"get").and.returnValue(i),r.loadCcc(),expect(r.ccc).toEqual(s),expect(o.eventStream.listeners.length).toBe(2),r.unsubscribe(),expect(o.eventStream.listeners.length).toBe(0)})})}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["changes","properties","steps"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Build",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["builds","buildrequests","forceschedulers","buildslaves","masters"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Builder",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["builds"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Buildrequest",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["properties"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Buildset",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Buildslave",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Change",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(n)}return e}(),angular.module("bbData").factory("Changesource",["dataService","Base",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Forcescheduler",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["builders","buildslaves","changesources","schedulers"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Master",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Scheduler",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["changes"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Sourcestamp",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n=[].slice;e=function(){function e(){}return e.prototype.cache=!1,e.prototype.$get=function(e,r,o,u,i,s,c){var a;return new(a=function(){function a(){this.socketCloseListener=t(this.socketCloseListener,this),this.unsubscribeListener=t(this.unsubscribeListener,this),l=this,i.eventStream.onUnsubscribe=this.unsubscribeListener,i.socket.onclose=this.socketCloseListener,this.constructor.generateEndpoints()}var l;return l=null,a.prototype.get=function(){var t,c,a,l,p,d;return t=1<=arguments.length?n.call(arguments,0):[],t=t.filter(function(e){return null!=e}),c=t[t.length-1],p=c.subscribe||null==c.subscribe,angular.isObject(c)&&(l=t.pop(),delete l.subscribe),d=[],a=o(function(n){return function(c,a){var f,h,b,v;return p?(f=[],v=i.eventStream.subscribe(function(e){return f.push(e)}),h=s.socketPath(t),b=n.startConsuming(h)):b=o.resolve(),b.then(function(){var o,b;return o=s.restPath(t),b=u.get(o,l),b.then(function(u){var l,b,g,y,m,x;x=s.type(o),u=u[x];try{g=s.className(o),l=r.get(g)}catch(B){y=B,l=r.get("Base")}return angular.isArray(u)?(m=s.endpointPath(t),u=u.map(function(e){return new l(e,m)}),null==n.listeners&&(n.listeners={}),null==(b=n.listeners)[h]&&(b[h]=[]),u.forEach(function(e){return n.listeners[h].push(e.listenerId)}),i.eventStream.subscribe(function(e){var t,r,o,u;return t=e.k,r=e.m,u=RegExp("^"+m+"\\/(\\w+|\\d+)\\/new$","g"),u.test(t)?(o=new l(r,m),d.push(o),n.listeners[h].push(o.listenerId)):void 0}),p&&(f.forEach(function(e){return i.eventStream.push(e)}),v()),angular.copy(u,d),c(d)):(y=u+" is not an array",e.error(y),a(y))},function(e){return a(e)})},function(e){return a(e)})}}(this)),a.getArray=function(){return d},a},a.prototype.startConsuming=function(e){return i.send({cmd:"startConsuming",path:e})},a.prototype.stopConsuming=function(e){return i.send({cmd:"stopConsuming",path:e})},a.prototype.unsubscribeListener=function(e){var t,n,r,o,u;o=this.listeners,u=[];for(r in o)n=o[r],t=n.indexOf(e.id),t>-1?(n.splice(t,1),u.push(0===n.length?this.stopConsuming(r):void 0)):u.push(void 0);return u},a.prototype.socketCloseListener=function(){var e,t,n;if(null!=this.listeners){n=this.listeners;for(t in n)e=n[t],e.length>0&&this.startConsuming(t);return null}},a.prototype.control=function(e,t){return u.post({id:this.getNextId(),jsonrpc:"2.0",method:e,params:t})},a.prototype.getNextId=function(){return null==this.jsonrpc&&(this.jsonrpc=1),this.jsonrpc++},a.generateEndpoints=function(){return c.forEach(function(e){return function(t){var r;return r=s.capitalize(t),e.prototype["get"+r]=function(){var e;return e=1<=arguments.length?n.call(arguments,0):[],l.get.apply(l,[t].concat(n.call(e)))}}}(this))},a.prototype.open=function(){var e;return new(e=function(){function e(){this.rootClasses=t,this.constructor.generateEndpoints()}var t;return t=[],e.prototype.close=function(){return this.rootClasses.forEach(function(e){return e.unsubscribe()})},e.prototype.closeOnDestroy=function(e){if(!angular.isFunction(e.$on))throw new TypeError("Parameter 'scope' doesn't have an $on function");return e.$on("$destroy",function(e){return function(){return e.close()}}(this))},e.generateEndpoints=function(){return c.forEach(function(e){return function(r){var o;return o=s.capitalize(r),e.prototype["get"+o]=function(){var e,r;return e=1<=arguments.length?n.call(arguments,0):[],r=l["get"+o].apply(l,e),r.then(function(e){return e.forEach(function(e){return t.push(e)})}),r}}}(this))},e}())},a}())},e.prototype.$get.$inject=["$log","$injector","$q","restService","socketService","dataUtilsService","ENDPOINTS"],e}(),angular.module("bbData").provider("dataProvider",[e])}.call(this),function(){describe("Data service",function(){var e,t,n,r,o,u,i,s;return beforeEach(module("bbData")),o=i=s=r=n=t=e=null,u=function(u){return o=u.get("dataService"),i=u.get("restService"),s=u.get("socketService"),r=u.get("ENDPOINTS"),n=u.get("$rootScope"),t=u.get("$q"),e=u.get("$httpBackend")},beforeEach(inject(u)),it("should be defined",function(){return expect(o).toBeDefined()}),it("should have getXxx functions for endpoints",function(){var e,t,n,u,i;for(i=[],n=0,u=r.length;u>n;n++)t=r[n],e=t[0].toUpperCase()+t.slice(1).toLowerCase(),expect(o["get"+e]).toBeDefined(),i.push(expect(angular.isFunction(o["get"+e])).toBeTruthy());return i}),describe("get()",function(){return it("should return a promise",function(){var e;return e=o.getBuilds(),expect(angular.isFunction(e.then)).toBeTruthy(),expect(angular.isFunction(e.getArray)).toBeTruthy()}),it("should call get for the rest api endpoint",function(){var e;return e=t.defer(),spyOn(i,"get").and.returnValue(e.promise),expect(i.get).not.toHaveBeenCalled(),n.$apply(function(){return o.get("asd",{subscribe:!1})}),expect(i.get).toHaveBeenCalledWith("asd",{})}),it("should send startConsuming with the socket path",function(){var e;return e=t.defer(),spyOn(s,"send").and.returnValue(e.promise),expect(s.send).not.toHaveBeenCalled(),n.$apply(function(){return o.get("asd")}),expect(s.send).toHaveBeenCalledWith({cmd:"startConsuming",path:"asd/*/*"}),n.$apply(function(){return o.get("asd",1)}),expect(s.send).toHaveBeenCalledWith({cmd:"startConsuming",path:"asd/1/*"})}),it("should not call startConsuming when {subscribe: false} is passed in",function(){var e;return e=t.defer(),spyOn(i,"get").and.returnValue(e.promise),spyOn(o,"startConsuming"),expect(o.startConsuming).not.toHaveBeenCalled(),n.$apply(function(){return o.getBuilds({subscribe:!1})}),expect(o.startConsuming).not.toHaveBeenCalled()}),it("should add the new instance on /new WebSocket message",function(){var e;return spyOn(i,"get").and.returnValue(t.resolve({builds:[]})),e=null,n.$apply(function(){return e=o.getBuilds({subscribe:!1}).getArray()}),s.eventStream.push({k:"builds/111/new",m:{asd:111}}),expect(e.pop().asd).toBe(111)})}),describe("control(method, params)",function(){return it("should send a jsonrpc message using POST",function(){var e,t;return spyOn(i,"post"),expect(i.post).not.toHaveBeenCalled(),e="force",t={a:1},o.control(e,t),expect(i.post).toHaveBeenCalledWith({id:1,jsonrpc:"2.0",method:e,params:t})})}),describe("open()",function(){var e;return e=null,beforeEach(function(){return e=o.open()}),it("should return a new accessor",function(){return expect(e).toEqual(jasmine.any(Object))}),it("should have getXxx functions for endpoints",function(){var t,n,o,u,i;for(i=[],o=0,u=r.length;u>o;o++)n=r[o],t=n[0].toUpperCase()+n.slice(1).toLowerCase(),expect(e["get"+t]).toBeDefined(),i.push(expect(angular.isFunction(e["get"+t])).toBeTruthy());return i}),it("should call unsubscribe on each root class on close",function(){var r,o,u,s,c,a,l,p,d,f;for(d=t.resolve({builds:[{},{},{}]}),spyOn(i,"get").and.returnValue(d),o=null,n.$apply(function(){return o=e.getBuilds({subscribe:!1}).getArray()}),expect(o.length).toBe(3),u=0,a=o.length;a>u;u++)r=o[u],spyOn(r,"unsubscribe");for(s=0,l=o.length;l>s;s++)r=o[s],expect(r.unsubscribe).not.toHaveBeenCalled();for(e.close(),f=[],c=0,p=o.length;p>c;c++)r=o[c],f.push(expect(r.unsubscribe).toHaveBeenCalled());return f}),it("should call close when the $scope is destroyed",function(){var t;return spyOn(e,"close"),t=n.$new(),e.closeOnDestroy(t),expect(e.close).not.toHaveBeenCalled(),t.$destroy(),expect(e.close).toHaveBeenCalled()})})})}.call(this),function(){var e;e=function(){function e(){return new(e=function(){function e(){}return e.prototype.capitalize=function(e){return e[0].toUpperCase()+e.slice(1).toLowerCase()},e.prototype.type=function(e){var t,n,r;for(r=e.split("/");;)if(t=r.pop(),n=parseInt(t),0===r.length||!angular.isNumber(n)||isNaN(n))break;return t},e.prototype.singularType=function(e){return this.type(e).replace(/s$/,"")},e.prototype.classId=function(e){return this.singularType(e)+"id"},e.prototype.className=function(e){return this.capitalize(this.singularType(e))},e.prototype.socketPath=function(e){var t;return t=["*"],e.length%2===1&&t.push("*"),e.concat(t).join("/")},e.prototype.restPath=function(e){return e.slice().join("/")},e.prototype.endpointPath=function(e){var t;return t=e.slice(),t.length%2===0&&t.pop(),t.join("/")},e}())}return e}(),angular.module("bbData").service("dataUtilsService",[e])}.call(this),function(){describe("Helper service",function(){var e,t;return beforeEach(module("bbData")),e=null,t=function(t){return e=t.get("dataUtilsService")},beforeEach(inject(t)),it("should be defined",function(){return expect(e).toBeDefined()}),it("should capitalize the first word",function(){return expect(e.capitalize("abc")).toBe("Abc"),expect(e.capitalize("abc cba")).toBe("Abc cba")}),it("should return the endpoint name for rest endpoints",function(){var t,n,r,o;r={"builders/100/forceschedulers":"forcescheduler","builders/1/builds":"build","builders/2/builds/1":"build"},n=[];for(t in r)o=r[t],n.push(expect(e.singularType(t)).toBe(o));return n}),it("should return the class name for rest endpoints",function(){var t,n,r,o;r={"builders/100/forceschedulers":"Forcescheduler","builders/1/builds":"Build","builders/2/builds/1":"Build"},n=[];for(t in r)o=r[t],n.push(expect(e.className(t)).toBe(o));return n}),it("should return the WebSocket path for an endpoint",function(){var t,n,r,o;r={"builders/100/forceschedulers/*/*":["builders",100,"forceschedulers"],"builders/1/builds/*/*":["builders",1,"builds"],"builders/2/builds/1/*":["builders",2,"builds",1]},n=[];for(t in r)o=r[t],n.push(expect(e.socketPath(o)).toBe(t));return n}),it("should return the path for an endpoint",function(){var t,n,r,o;r={"builders/100/forceschedulers":["builders",100,"forceschedulers"],"builders/1/builds":["builders",1,"builds"],"builders/2/builds":["builders",2,"builds",1]},n=[];for(t in r)o=r[t],n.push(expect(e.endpointPath(o)).toBe(t));return n})})}.call(this),function(){var e,t=[].slice;e=function(){function e(e,n,r){var o;return new(o=function(){function o(){}return o.prototype.execute=function(t){return n(function(n){return function(n,r){return e(t).success(function(e){var t,o;try{return t=angular.fromJson(e),n(t)}catch(u){return o=u,r(o)}}).error(function(e){return r(e)})}}(this))},o.prototype.get=function(e,t){var n;return null==t&&(t={}),n={method:"GET",url:this.parse(r,e),params:t,headers:{Accept:"application/json"}},this.execute(n)},o.prototype.post=function(e,t){var n;return null==t&&(t={}),n={method:"POST",url:this.parse(r,e),data:t,headers:{"Content-Type":"application/json"}},this.execute(n)},o.prototype.parse=function(){var e;return e=1<=arguments.length?t.call(arguments,0):[],e.join("/").replace(/\/\//,"/")},o}())}return e}(),angular.module("bbData").service("restService",["$http","$q","API",e])}.call(this),function(){describe("Rest service",function(){var e,t,n;return beforeEach(module("bbData")),beforeEach(function(){return module(function(e){return e.constant("API","/api/")})}),n=e=null,t=function(t){return n=t.get("restService"),e=t.get("$httpBackend")},beforeEach(inject(t)),afterEach(function(){return e.verifyNoOutstandingExpectation(),e.verifyNoOutstandingRequest()}),it("should be defined",function(){return expect(n).toBeDefined()}),it("should make an ajax GET call to /api/endpoint",function(){var t,r;return r={a:"A"},e.whenGET("/api/endpoint").respond(r),t=null,n.get("endpoint").then(function(e){return t=e}),expect(t).toBeNull(),e.flush(),expect(t).toEqual(r)}),it("should make an ajax GET call to /api/endpoint with parameters",function(){var t;return t={key:"value"},e.whenGET("/api/endpoint?key=value").respond(200),n.get("endpoint",t),e.flush()}),it("should reject the promise on error",function(){var t,r;return t="Internal server error",e.expectGET("/api/endpoint").respond(500,t),r=null,n.get("endpoint").then(function(e){return r=e},function(e){return r=e}),e.flush(),expect(r).toBe(t)}),it("should make an ajax POST call to /api/endpoint",function(){var t,r,o;return o={},t={b:"B"},e.expectPOST("/api/endpoint",t).respond(o),r=null,n.post("endpoint",t).then(function(e){return r=e}),e.flush(),expect(r).toEqual(o)}),it("should reject the promise when the response is not valid JSON",function(){var t,r,o;return o="aaa",t={b:"B"},e.expectPOST("/api/endpoint",t).respond(o),r=null,n.post("endpoint",t).then(function(e){return r=e},function(e){return r=e}),e.flush(),expect(r).not.toBeNull(),expect(r).not.toEqual(o)})})}.call(this),function(){var e;e=function(){function e(e,t,n,r,o,u){var i;return new(i=function(){function i(){this.queue=[],this.deferred={},this.open()}return i.prototype.eventStream=null,i.prototype.open=function(){return null==this.socket&&(this.socket=u.getWebSocket(this.getUrl())),this.socket.onopen=function(e){return function(){return e.flush()}}(this),this.setupEventStream()},i.prototype.setupEventStream=function(){return null==this.eventStream&&(this.eventStream=new o),this.socket.onmessage=function(t){return function(r){var o,u,i,s,c,a;try{return o=angular.fromJson(r.data),e.debug("WS message",o),null!=o.code?(i=o._id,200===o.code?null!=(s=t.deferred[i])?s.resolve(!0):void 0:null!=(c=t.deferred[i])?c.reject(o):void 0):n.$applyAsync(function(){return t.eventStream.push(o)})}catch(l){return u=l,null!=(a=t.deferred[i])?a.reject(u):void 0}}}(this)},i.prototype.close=function(){return this.socket.close()},i.prototype.send=function(n){var r,o;return o=this.nextId(),n._id=o,null==(r=this.deferred)[o]&&(r[o]=t.defer()),n=angular.toJson(n),this.socket.readyState===(this.socket.OPEN||1)?(e.debug("WS send",angular.fromJson(n)),this.socket.send(n)):this.queue.push(n),this.deferred[o].promise},i.prototype.flush=function(){var t,n;for(n=[];t=this.queue.pop();)e.debug("WS send",angular.fromJson(t)),n.push(this.socket.send(t));return n},i.prototype.nextId=function(){return null==this.id&&(this.id=0),this.id=this.id<1e3?this.id+1:0,this.id},i.prototype.getUrl=function(){var e,t;return e=r.host(),t=80===r.port()?"":":"+r.port(),"ws://"+e+t+"/ws"},i}())}return e}(),angular.module("bbData").service("socketService",["$log","$q","$rootScope","$location","Stream","webSocketService",e])}.call(this),function(){describe("Socket service",function(){var e,t,n,r,o,u;return t=function(){function e(){n=this,this.webSocket=new t}var t,n;return e.prototype.sendQueue=[],e.prototype.receiveQueue=[],n=null,e.prototype.send=function(e){var t;return t={data:e},this.sendQueue.push(t)},e.prototype.flush=function(){var e,t;for(t=[];e=this.sendQueue.shift();)t.push(this.webSocket.onmessage(e));return t},e.prototype.getWebSocket=function(){return this.webSocket},t=function(){function e(){}return e.prototype.OPEN=1,e.prototype.send=function(e){return n.receiveQueue.push(e)},e}(),e}(),u=new t,beforeEach(function(){return module("bbData"),module(function(e){return e.constant("webSocketService",u)})}),e=o=r=null,n=function(t){return e=t.get("$rootScope"),o=t.get("socketService"),r=o.socket,spyOn(r,"send").and.callThrough(),spyOn(r,"onmessage").and.callThrough()},beforeEach(inject(n)),it("should be defined",function(){return expect(o).toBeDefined()}),it("should send the data, when the WebSocket is open",function(){var e,t,n;return r.readyState=0,e={a:1},t={b:2},n={c:3},o.send(e),o.send(t),expect(r.send).not.toHaveBeenCalled(),r.onopen(),expect(r.send).toHaveBeenCalled(),expect(u.receiveQueue).toContain(angular.toJson(e)),expect(u.receiveQueue).toContain(angular.toJson(t)),expect(u.receiveQueue).not.toContain(angular.toJson(n))}),it("should add an _id to each message",function(){var e;return r.readyState=1,expect(r.send).not.toHaveBeenCalled(),o.send({}),expect(r.send).toHaveBeenCalledWith(jasmine.any(String)),e=r.send.calls.argsFor(0)[0],expect(angular.fromJson(e)._id).toBeDefined()}),it("should resolve the promise when a response message is received with code 200",function(){var t,n,i,s,c,a;return r.readyState=1,s={cmd:"command"},c=o.send(s),n=jasmine.createSpy("handler"),c.then(n),expect(n).not.toHaveBeenCalled(),t=r.send.calls.argsFor(0)[0],i=angular.fromJson(t)._id,a=angular.toJson({_id:i,code:200}),u.send(a),e.$apply(function(){return u.flush()}),expect(n).toHaveBeenCalled()}),it("should reject the promise when a response message is received, but the code is not 200",function(){var t,n,i,s,c,a,l;return r.readyState=1,c={cmd:"command"},a=o.send(c),i=jasmine.createSpy("handler"),n=jasmine.createSpy("errorHandler"),a.then(i,n),expect(i).not.toHaveBeenCalled(),expect(n).not.toHaveBeenCalled(),t=r.send.calls.argsFor(0)[0],s=angular.fromJson(t)._id,l=angular.toJson({_id:s,code:500}),u.send(l),e.$apply(function(){return u.flush()}),expect(i).not.toHaveBeenCalled(),expect(n).toHaveBeenCalled()})})}.call(this),function(){var e;e=function(){function e(e){var t;return new(t=function(){function t(){}return t.prototype.getWebSocket=function(t){var n;if(n=/wss?:\/\//.exec(t),!n)throw new Error("Invalid url provided");return null!=e.ReconnectingWebSocket?new e.ReconnectingWebSocket(t):new e.WebSocket(t)},t}())}return e}(),angular.module("bbData").service("webSocketService",["$window",e])}.call(this),function(){var e;e=function(){function e(){var e;return e=function(){function e(){}return e.prototype.onUnsubscribe=null,e.prototype.listeners=[],e.prototype.subscribe=function(e){if(!angular.isFunction(e))throw new TypeError("Parameter 'listener' must be a function, not "+typeof e);return e.id=this.generateId(),this.listeners.push(e),function(t){return function(){var n,r;return n=t.listeners.indexOf(e),r=t.listeners.splice(n,1),angular.isFunction(t.onUnsubscribe)?t.onUnsubscribe(e):void 0}}(this)},e.prototype.push=function(e){var t,n,r,o,u;for(o=this.listeners,u=[],t=0,n=o.length;n>t;t++)r=o[t],u.push(r(e));return u},e.prototype.destroy=function(){var e;for(e=[];this.listeners.length>0;)e.push(this.listeners.pop());return e},e.prototype.generateId=function(){return null==this.lastId&&(this.lastId=0),this.lastId++},e}()}return e}(),angular.module("bbData").factory("Stream",[e])}.call(this),function(){describe("Stream service",function(){var e,t,n;return beforeEach(module("bbData")),e=n=null,t=function(t){return e=t.get("Stream"),n=new e},beforeEach(inject(t)),it("should be defined",function(){return expect(e).toBeDefined(),expect(n).toBeDefined()}),it("should add the listener to listeners on subscribe call",function(){var e;return e=n.listeners,expect(e.length).toBe(0),n.subscribe(function(){}),expect(e.length).toBe(1)}),it("should add a unique id to each listener passed in to subscribe",function(){var e,t,r;return r=n.listeners,e=function(){},t=function(){},n.subscribe(e),n.subscribe(t),expect(e.id).toBeDefined(),expect(t.id).toBeDefined(),expect(e.id).not.toBe(t.id)}),it("should return the unsubscribe function on subscribe call",function(){var e,t,r,o;return t=n.listeners,e=function(){},r=function(){},o=n.subscribe(e),n.subscribe(r),expect(t).toContain(e),o(),expect(t).not.toContain(e),expect(t).toContain(r)}),it("should call all listeners on push call",function(){var e,t;return e={a:"A",b:"B"},t={first:function(e){return expect(e).toEqual({a:"A",b:"B"})},second:function(e){return expect(e).toEqual({a:"A",b:"B"})}},spyOn(t,"first").and.callThrough(),spyOn(t,"second").and.callThrough(),n.subscribe(t.first),n.subscribe(t.second),expect(t.first).not.toHaveBeenCalled(),expect(t.second).not.toHaveBeenCalled(),n.push(e),expect(t.first).toHaveBeenCalled(),expect(t.second).toHaveBeenCalled()}),it("should remove all listeners on destroy call",function(){var e;return e=n.listeners,expect(e.length).toBe(0),n.subscribe(function(){}),n.subscribe(function(){}),expect(e.length).not.toBe(0),n.destroy(),expect(e.length).toBe(0)}),it("should call the unsubscribe listener on unsubscribe call",function(){var e,t;return spyOn(n,"onUnsubscribe"),e=function(){},t=n.subscribe(e),expect(n.onUnsubscribe).not.toHaveBeenCalled(),t(),expect(n.onUnsubscribe).toHaveBeenCalledWith(e)})})}.call(this); | ||
(function(){var t;t=function(){function t(){return[]}return t}(),angular.module("bbData",new t)}).call(this),function(){var t;t=function(){function t(t){t.interceptors.push(["$log","API",function(t,n){return{request:function(r){return 0===r.url.indexOf(n)&&t.debug(r.method+" "+r.url),r}}}])}return t}(),angular.module("bbData").config(["$httpProvider",t])}.call(this),function(){var t,n;t=function(){function t(){return"api/v2/"}return t}(),n=function(){function t(){return["builders","builds","buildrequests","buildslaves","buildsets","changes","changesources","masters","sourcestamps","schedulers","forceschedulers"]}return t}(),angular.module("bbData").constant("API",t()).constant("ENDPOINTS",n())}.call(this),function(){var t,n=[].slice;t=function(){function t(t,r,e){var o;return o=function(){function o(t,n,r){var o;if(this.endpoint=n,null==r&&(r=[]),!angular.isString(this.endpoint))throw new TypeError("Parameter 'endpoint' must be a string, not "+typeof this.endpoint);this.update(t),this.constructor.generateFunctions(r),o=e.classId(this.endpoint),this.id=this[o],this.subscribe()}return o.prototype.update=function(t){return angular.merge(this,t)},o.prototype.get=function(){var r;return r=1<=arguments.length?n.call(arguments,0):[],t.get.apply(t,[this.endpoint,this.id].concat(n.call(r)))},o.prototype.subscribe=function(){var t;return t=function(t){return function(n){var r,e,o;return r=n.k,e=n.m,o=RegExp("^"+t.endpoint+"\\/"+t.id+"\\/\\w+$","g"),o.test(r)?t.update(e):void 0}}(this),this.unsubscribeEventListener=r.eventStream.subscribe(t),this.listenerId=t.id},o.prototype.unsubscribe=function(){var t,n;for(t in this)n=this[t],angular.isArray(n)&&n.forEach(function(t){return t instanceof o?t.unsubscribe():void 0});return this.unsubscribeEventListener()},o.generateFunctions=function(t){return t.forEach(function(t){return function(r){var o;return o=e.capitalize(r),t.prototype["load"+o]=function(){var t,e;return t=1<=arguments.length?n.call(arguments,0):[],e=this.get.apply(this,[r].concat(n.call(t))),this[r]=e.getArray(),e}}}(this))},o}()}return t}(),angular.module("bbData").factory("Base",["dataService","socketService","dataUtilsService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){var e;e=["changes","properties","steps"],r.__super__.constructor.call(this,t,n,e)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Build",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){var e;e=["builds","buildrequests","forceschedulers","buildslaves","masters"],r.__super__.constructor.call(this,t,n,e)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Builder",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){var e;e=["builds"],r.__super__.constructor.call(this,t,n,e)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Buildrequest",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){var e;e=["properties"],r.__super__.constructor.call(this,t,n,e)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Buildset",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){r.__super__.constructor.call(this,t,n)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Buildslave",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){r.__super__.constructor.call(this,t,n)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Change",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){r.__super__.constructor.call(this,t,n)}return n(r,t),r}(r)}return t}(),angular.module("bbData").factory("Changesource",["dataService","Base",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){r.__super__.constructor.call(this,t,n)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Forcescheduler",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){var e;e=["builders","buildslaves","changesources","schedulers"],r.__super__.constructor.call(this,t,n,e)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Master",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){r.__super__.constructor.call(this,t,n)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Scheduler",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t},r={}.hasOwnProperty;t=function(){function t(t,r){var e;return e=function(t){function r(t,n){var e;e=["changes"],r.__super__.constructor.call(this,t,n,e)}return n(r,t),r}(t)}return t}(),angular.module("bbData").factory("Sourcestamp",["Base","dataService",t])}.call(this),function(){var t,n=function(t,n){return function(){return t.apply(n,arguments)}},r=[].slice;t=function(){function t(){}return t.prototype.cache=!1,t.prototype.$get=function(t,e,o,u,i,s,c){var a;return new(a=function(){function a(){this.socketCloseListener=n(this.socketCloseListener,this),this.unsubscribeListener=n(this.unsubscribeListener,this),p=this,i.eventStream.onUnsubscribe=this.unsubscribeListener,i.socket.onclose=this.socketCloseListener,this.constructor.generateEndpoints()}var p;return p=null,a.prototype.get=function(){var n,c,a,p,l,f;return n=1<=arguments.length?r.call(arguments,0):[],n=n.filter(function(t){return null!=t}),c=n[n.length-1],l=c.subscribe||null==c.subscribe,angular.isObject(c)&&(p=n.pop(),delete p.subscribe),f=[],a=o(function(r){return function(c,a){var h,d,v,y;return l?(h=[],y=i.eventStream.subscribe(function(t){return h.push(t)}),d=s.socketPath(n),v=r.startConsuming(d)):v=o.resolve(),v.then(function(){var o,v;return o=s.restPath(n),v=u.get(o,p),v.then(function(u){var p,v,g,b,_,m;m=s.type(o),u=u[m];try{g=s.className(o),p=e.get(g)}catch(S){b=S,p=e.get("Base")}return angular.isArray(u)?(_=s.endpointPath(n),u=u.map(function(t){return new p(t,_)}),null==r.listeners&&(r.listeners={}),null==(v=r.listeners)[d]&&(v[d]=[]),u.forEach(function(t){return r.listeners[d].push(t.listenerId)}),i.eventStream.subscribe(function(t){var n,e,o,u;return n=t.k,e=t.m,u=RegExp("^"+_+"\\/(\\w+|\\d+)\\/new$","g"),u.test(n)?(o=new p(e,_),f.push(o),r.listeners[d].push(o.listenerId)):void 0}),l&&(h.forEach(function(t){return i.eventStream.push(t)}),y()),angular.copy(u,f),c(f)):(b=u+" is not an array",t.error(b),a(b))},function(t){return a(t)})},function(t){return a(t)})}}(this)),a.getArray=function(){return f},a},a.prototype.startConsuming=function(t){return i.send({cmd:"startConsuming",path:t})},a.prototype.stopConsuming=function(t){return i.send({cmd:"stopConsuming",path:t})},a.prototype.unsubscribeListener=function(t){var n,r,e,o,u;o=this.listeners,u=[];for(e in o)r=o[e],n=r.indexOf(t.id),n>-1?(r.splice(n,1),u.push(0===r.length?this.stopConsuming(e):void 0)):u.push(void 0);return u},a.prototype.socketCloseListener=function(){var t,n,r;if(null!=this.listeners){r=this.listeners;for(n in r)t=r[n],t.length>0&&this.startConsuming(n);return null}},a.prototype.control=function(t,n){return u.post({id:this.getNextId(),jsonrpc:"2.0",method:t,params:n})},a.prototype.getSpecification=function(){return u.get("application.spec")},a.prototype.getNextId=function(){return null==this.jsonrpc&&(this.jsonrpc=1),this.jsonrpc++},a.generateEndpoints=function(){return c.forEach(function(t){return function(n){var e;return e=s.capitalize(n),t.prototype["get"+e]=function(){var t;return t=1<=arguments.length?r.call(arguments,0):[],p.get.apply(p,[n].concat(r.call(t)))}}}(this))},a.prototype.open=function(){var t;return new(t=function(){function t(){this.rootClasses=n,this.constructor.generateEndpoints()}var n;return n=[],t.prototype.close=function(){return this.rootClasses.forEach(function(t){return t.unsubscribe()})},t.prototype.closeOnDestroy=function(t){if(!angular.isFunction(t.$on))throw new TypeError("Parameter 'scope' doesn't have an $on function");return t.$on("$destroy",function(t){return function(){return t.close()}}(this))},t.generateEndpoints=function(){return c.forEach(function(t){return function(e){var o;return o=s.capitalize(e),t.prototype["get"+o]=function(){var t,e;return t=1<=arguments.length?r.call(arguments,0):[],e=p["get"+o].apply(p,t),e.then(function(t){return t.forEach(function(t){return n.push(t)})}),e}}}(this))},t}())},a}())},t.prototype.$get.$inject=["$log","$injector","$q","restService","socketService","dataUtilsService","ENDPOINTS"],t}(),angular.module("bbData").provider("dataService",[t])}.call(this),function(){var t;t=function(){function t(){}return t.prototype.capitalize=function(t){return t[0].toUpperCase()+t.slice(1).toLowerCase()},t.prototype.type=function(t){var n,r,e;for(e=t.split("/");;)if(n=e.pop(),r=parseInt(n),0===e.length||!angular.isNumber(r)||isNaN(r))break;return n},t.prototype.singularType=function(t){return this.type(t).replace(/s$/,"")},t.prototype.classId=function(t){return this.singularType(t)+"id"},t.prototype.className=function(t){return this.capitalize(this.singularType(t))},t.prototype.socketPath=function(t){var n;return n=["*"],t.length%2===1&&n.push("*"),t.concat(n).join("/")},t.prototype.restPath=function(t){return t.slice().join("/")},t.prototype.endpointPath=function(t){var n;return n=t.slice(),n.length%2===0&&n.pop(),n.join("/")},t}(),angular.module("bbData").service("dataUtilsService",[t])}.call(this),function(){var t,n=[].slice;t=function(){function t(t,r,e){var o;return new(o=function(){function o(){}return o.prototype.execute=function(n){return r(function(r){return function(r,e){return t(n).success(function(t){var n,o;try{return n=angular.fromJson(t),r(n)}catch(u){return o=u,e(o)}}).error(function(t){return e(t)})}}(this))},o.prototype.get=function(t,n){var r;return null==n&&(n={}),r={method:"GET",url:this.parse(e,t),params:n,headers:{Accept:"application/json"}},this.execute(r)},o.prototype.post=function(t,n){var r;return null==n&&(n={}),r={method:"POST",url:this.parse(e,t),data:n,headers:{"Content-Type":"application/json"}},this.execute(r)},o.prototype.parse=function(){var t;return t=1<=arguments.length?n.call(arguments,0):[],t.join("/").replace(/\/\//,"/")},o}())}return t}(),angular.module("bbData").service("restService",["$http","$q","API",t])}.call(this),function(){var t;t=function(){function t(t,n,r,e,o,u){var i;return new(i=function(){function i(){this.queue=[],this.deferred={},this.open()}return i.prototype.eventStream=null,i.prototype.open=function(){return null==this.socket&&(this.socket=u.getWebSocket(this.getUrl())),this.socket.onopen=function(t){return function(){return t.flush()}}(this),this.setupEventStream()},i.prototype.setupEventStream=function(){return null==this.eventStream&&(this.eventStream=new o),this.socket.onmessage=function(n){return function(e){var o,u,i,s,c,a;try{return o=angular.fromJson(e.data),t.debug("WS message",o),null!=o.code?(i=o._id,200===o.code?null!=(s=n.deferred[i])?s.resolve(!0):void 0:null!=(c=n.deferred[i])?c.reject(o):void 0):r.$applyAsync(function(){return n.eventStream.push(o)})}catch(p){return u=p,null!=(a=n.deferred[i])?a.reject(u):void 0}}}(this)},i.prototype.close=function(){return this.socket.close()},i.prototype.send=function(r){var e,o;return o=this.nextId(),r._id=o,null==(e=this.deferred)[o]&&(e[o]=n.defer()),r=angular.toJson(r),this.socket.readyState===(this.socket.OPEN||1)?(t.debug("WS send",angular.fromJson(r)),this.socket.send(r)):this.queue.push(r),this.deferred[o].promise},i.prototype.flush=function(){var n,r;for(r=[];n=this.queue.pop();)t.debug("WS send",angular.fromJson(n)),r.push(this.socket.send(n));return r},i.prototype.nextId=function(){return null==this.id&&(this.id=0),this.id=this.id<1e3?this.id+1:0,this.id},i.prototype.getUrl=function(){var t,n;return t=e.host(),n=80===e.port()?"":":"+e.port(),"ws://"+t+n+"/ws"},i}())}return t}(),angular.module("bbData").service("socketService",["$log","$q","$rootScope","$location","Stream","webSocketService",t])}.call(this),function(){var t;t=function(){function t(t){var n;return new(n=function(){function n(){}return n.prototype.getWebSocket=function(n){var r;if(r=/wss?:\/\//.exec(n),!r)throw new Error("Invalid url provided");return null!=t.ReconnectingWebSocket?new t.ReconnectingWebSocket(n):new t.WebSocket(n)},n}())}return t}(),angular.module("bbData").service("webSocketService",["$window",t])}.call(this),function(){var t;t=function(){function t(){var t;return t=function(){function t(){}return t.prototype.onUnsubscribe=null,t.prototype.listeners=[],t.prototype.subscribe=function(t){if(!angular.isFunction(t))throw new TypeError("Parameter 'listener' must be a function, not "+typeof t);return t.id=this.generateId(),this.listeners.push(t),function(n){return function(){var r,e;return r=n.listeners.indexOf(t),e=n.listeners.splice(r,1),angular.isFunction(n.onUnsubscribe)?n.onUnsubscribe(t):void 0}}(this)},t.prototype.push=function(t){var n,r,e,o,u;for(o=this.listeners,u=[],n=0,r=o.length;r>n;n++)e=o[n],u.push(e(t));return u},t.prototype.destroy=function(){var t;for(t=[];this.listeners.length>0;)t.push(this.listeners.pop());return t},t.prototype.generateId=function(){return null==this.lastId&&(this.lastId=0),this.lastId++},t}()}return t}(),angular.module("bbData").factory("Stream",[t])}.call(this); |
{ | ||
"name": "buildbot-data", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Buildbot AngularJS data module", | ||
@@ -5,0 +5,0 @@ "readme": "README.md", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
99141
921