/* global ubs_globalCache, _App */
const UB = require('@unitybase/ub')
ubs_globalCache.entity.addMethod('select')

/**
 * Read only access to server-side global cache
 *
 * @function select
 * @memberOf ubs_globalCache_ns.prototype
 * @memberOfModule @unitybase/ubs
 * @published
 * @param {ubMethodParams} ctx
 * @param {UBQL} ctx.mParams ORM query in UBQL format
 * @returns {boolean}
 */
ubs_globalCache.select = function (ctx) {
  ctx.dataStore.currentDataName = 'select'
  if (!_App.globalCacheList) throw new UB.UBAbort('<<<Upgrade your UB server version >=5.7.5>>>')
  const arrData = JSON.parse(_App.globalCacheList())
  ctx.dataStore.initialize(arrData, ['ID', 'key', 'keyValue'])
  return true // everything is OK
}