MCPcopy
hub / github.com/buildbot/buildbot / getAny

Method getAny

www/data-module/src/data/DataClient.ts:51–81  ·  view source on GitHub ↗
(endpoint: string, accessor: IDataAccessor,
                                    descriptor: IAnyDataDescriptor, query: Query,
                                    subscribe: boolean, collectionFactory: () => T)

Source from the content-addressed store, hash-verified

49 }
50
51 getAny<T extends IDataCollection>(endpoint: string, accessor: IDataAccessor,
52 descriptor: IAnyDataDescriptor, query: Query,
53 subscribe: boolean, collectionFactory: () => T) {
54 // subscribe for changes if 'subscribe' is true
55 if (subscribe && !accessor) {
56 console.warn("subscribe call should be done after DataClient.open() for " +
57 "maintaining trace of observers");
58 subscribe = false;
59 }
60
61 const collection = collectionFactory();
62
63 const subscribePromise = subscribe ? collection.subscribe() : Promise.resolve();
64
65 subscribePromise.then(() =>
66 // get the data from the rest api
67 this.restClient.get(endpoint, query).then((response) => {
68 const datalist = response[descriptor.restArrayField];
69 // the response should always be an array
70 if (!Array.isArray(datalist)) {
71 console.error(`${datalist} is not an array when retrieving ${descriptor.restArrayField}`);
72 return;
73 }
74
75 // fill up the collection with initial data
76 collection.initial(datalist);
77 })
78 );
79
80 return collection;
81 }
82
83 control(endpoint: string, method: string, params: ControlParams) {
84 return this.restClient.post(endpoint, {

Callers 2

getMethod · 0.95
getPropertiesMethod · 0.95

Calls 5

subscribeMethod · 0.65
getMethod · 0.65
initialMethod · 0.65
resolveMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected