Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | 6x 6x 25x 1x 1x 6x 1x 5x 5x 5x 20x 20x 20x 3x 3x 1x 2x 2x 17x 5x 4x 2x 2x 12x 11x 6x 6x 6x 1x 6x 6x 2x 2x 1x 2x 4x 3x 3x 3x 1x 3x 1x 5x 3x 2x 2x 1x 2x 2x 1x 2x 1x | /*
Copyright (C) 2021 owner Roman Piontik R.Piontik@mail.ru
Copyright (C) 2022 Sber
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
In any derivative products, you must retain the information of
owner of the original code and provide clear attribution to the project
https://dochub.info
The use of this product or its derivatives for any purpose cannot be a secret.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Maintainers:
R.Piontik <r.piontik@mail.ru>
Contributors:
R.Piontik <r.piontik@mail.ru> - 2023
Rostislav Kabalin <kabalin2009@yandex.ru> - 2022
*/
import requests from './requests';
import query from '../manifest/query';
import source from '../../global/datasets/source.mjs';
import datasetDriver from '@global/datasets/driver.mjs';
import pathTool from '@global/manifest/tools/path.mjs';
import env from '@front/helpers/env';
import { PerformanceLogger } from '@global/logger/perf-logger.mjs';
import {getLogger, getLoggerWithTag} from '@global/logger/v2/logger.mjs';
import {unenvelopeDocument} from '@global/helpers/api/unenvelope.js';
import {datasetSourceKey, pullDatasetSource} from '@front/helpers/datasetSourceCache';
const LOG_TAG = 'dataset-driver';
const logger = getLoggerWithTag(LOG_TAG);
export default function() {
return Object.assign({
parentParseSource: datasetDriver.parseSource
}, datasetDriver,
{
// Дефолтный метод получения объекта данных
dsResolver(datasetID) {
const state = window.Vuex.state;
return {
// Обогащаем профиль информацией об идентификаторе
subject: Object.assign({_id: datasetID}, (state.manifest.datasets || {})[datasetID]),
baseURI: state.sources[`/datasets/${datasetID}`][0]
};
},
pathResolver(path) {
if (env.isBackendMode)
throw `pathResolver is not correct call for backend mode ... [${path}]`;
const state = window.Vuex.state;
return {
context: state.manifest,
subject: pathTool.get(state.manifest, path),
baseURI: (state.sources[path] || ['/'])[0]
};
},
// Драйвер запросов к ресурсам
request(url, baseURI) {
return requests.request(url, baseURI);
},
// Драйвер запросов JSONata
jsonataDriver: query,
performanceLogger: env.isPerfLoggerEnabled ? new PerformanceLogger(getLogger()) : null,
async parseSource(context, data, subject, params, baseURI, datasetsWithError) {
const sourceType = source.type(data);
// С учетом subject: .yaml у dataset с type: manifest — вложенный манифест, иначе файл данных
const loadedSourceType = source.type(data, subject);
if (sourceType === 'id' && env.isPlugin() && env.isCacheMode) {
const args = {context, data, subject, params, baseURI};
return await window.$PAPI.pullFromCache(`{"path":"/datasets/${data}"}`, async() => {
return await this.parentParseSource(context, data, subject, params, baseURI, undefined, datasetsWithError);
}, args)
.catch((error) => {
if (!datasetsWithError[data]) datasetsWithError[data] = {uri: baseURI, error};
throw error;
});
} else if (['data-file', 'data-manifest'].includes(loadedSourceType)) {
// Файл данных и вложенный манифест загружаются один раз на загрузку манифеста, а не при каждом обращении к dataset
return await pullDatasetSource(window.Vuex?.state?.moment, datasetSourceKey(loadedSourceType, baseURI, data), () => {
return this.parentParseSource(context, data, subject, params, baseURI, undefined, datasetsWithError);
})
.catch((error) => {
Iif (datasetsWithError && !datasetsWithError[data]) datasetsWithError[data] = {uri: baseURI, error};
throw error;
});
} else {
return await this.parentParseSource(context, data, subject, params, baseURI, undefined, datasetsWithError);
}
},
// Переопределяем метод получения данных для работы с бэком
getDataOriginal: datasetDriver.getData,
async getData(context, subject, params, baseURI, datasetsWithError) {
if (env.isBackendMode) {
const url = 'backend://release-data-profile';
const body = {
query: subject,
params: params || null,
baseURI
};
if (env.isEnvelopedRequests) {
body.envelope = true;
}
try {
const response = await requests.request(url, null, { method: 'POST', data: body });
let result = response.data;
if (env.isEnvelopedRequests) {
result = unenvelopeDocument(result);
}
return result;
} catch (e) {
if (e?.response?.data) {
logger.error(() => `Error request to url ${url}`, e);
let errorResponse = e.response.data.message ?? e.response.data;
if ((!errorResponse || Object.keys(errorResponse).length === 0) && e.response.status) {
errorResponse = `Http error: ${e.response.status}`;
}
return Promise.reject(errorResponse);
} else return Promise.reject(e);
}
} else return await this.getDataOriginal(context, subject, params, baseURI, datasetsWithError);
},
getReleaseData: datasetDriver.releaseData,
async releaseData(path, params) {
if (env.isBackendMode) {
const body = {
query: path,
params: params || null
};
if (env.isEnvelopedRequests) {
body.envelope = true;
}
let result = (await requests.request('backend://release-data-profile', null, {
method: 'POST',
data: body
})).data;
if (env.isEnvelopedRequests) {
result = unenvelopeDocument(result);
}
return result;
} else return await this.getReleaseData(path, params);
}
});
}
|