reveal-sdk-node
Version:
RevealBI Node.js SDK
178 lines (177 loc) • 7.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerDataSource = exports.toSdkDSI = exports.toSdkDS = void 0;
const DataSources = require("./rvDataSourceExports");
const dsTypeMap = {
'ANALYSISSERVICES': {
fromJson: function (dsJson) {
var _a;
return "HTTP" == ((_a = dsJson["Properties"]) === null || _a === void 0 ? void 0 : _a["Mode"])
? new DataSources.RVHttpAnalysisServicesDataSource(dsJson)
: new DataSources.RVNativeAnalysisServicesDataSource(dsJson);
}
},
'AMAZON_ATHENA': DataSources.RVAthenaDataSource,
'AZURE_ANALYSIS_SERVICES': DataSources.RVAzureAnalysisServicesDataSource,
'AZURE_SQL': DataSources.RVAzureSqlDataSource,
'AZURE_SYNAPSE': DataSources.RVAzureSynapseDataSource,
'BIG_QUERY': DataSources.RVBigQueryDataSource,
'BOXPROVIDER': DataSources.RVBoxDataSource,
'CSVLOCALFILEPROVIDER': DataSources.RVCsvDataSource,
'DYNAMICS_CRM': DataSources.RVDynamicsCrmDataSource,
'EXCELLOCALFILEPROVIDER': DataSources.RVExcelDataSource,
'GOOGLE_ANALYTICS_4': DataSources.RVGoogleAnalytics4DataSource,
'GOOGLEDRIVEPROVIDER': DataSources.RVGoogleDriveDataSource,
'GOOGLE_SEARCH_CONSOLE': DataSources.RVGoogleSearchConsoleDataSource,
'GOOGLESHEETLOCALFILEPROVIDER': DataSources.RVGoogleSheetDataSource,
'HUBSPOT': DataSources.RVHubspotDataSource,
'JSON': DataSources.RVJsonDataSource,
'LOCALFILE': DataSources.RVLocalFileDataSource,
'MARKETO': DataSources.RVMarketoDataSource,
'MONGODB': DataSources.RVMongoDBDataSource,
'MYSQL': DataSources.RVMySqlDataSource,
'ODATAPROVIDER': DataSources.RVODataDataSource,
'ONEDRIVEPROVIDER': DataSources.RVOneDriveDataSource,
'ORACLE': {
fromJson: function (dsJson) {
var _a;
return ((_a = dsJson.Properties) === null || _a === void 0 ? void 0 : _a["SID"])
? new DataSources.RVOracleSIDDataSource(dsJson)
: new DataSources.RVOracleServiceDataSource(dsJson);
}
},
'POSTGRES': DataSources.RVPostgresDataSource,
'QUICK_BOOKS': DataSources.RVQuickBooksDataSource,
'AMAZON_REDSHIFT': DataSources.RVRedshiftDataSource,
'REST': DataSources.RVRESTDataSource,
'AMAZON_S3': DataSources.RVS3DataSource,
'SHAREPOINT': DataSources.RVSharePointDataSource,
'SNOWFLAKE': DataSources.RVSnowflakeDataSource,
'SSRS': DataSources.RVReportingServicesDataSource,
'SYBASE': DataSources.RVSyBaseDataSource,
'SQLSERVER': DataSources.RVSqlServerDataSource,
'WEBSERVICE': DataSources.RVWebResourceDataSource,
'DATABRICKS': DataSources.RVDatabricksDataSource, //TODO [databricks] Will undo it when we move databricks to a module.
};
const dsiTypeMap = {
'ANALYSISSERVICES': DataSources.RVAnalysisServicesDataSourceItem,
'AMAZON_ATHENA': DataSources.RVAthenaDataSourceItem,
'AZURE_ANALYSIS_SERVICES': DataSources.RVAnalysisServicesDataSourceItem,
'AZURE_SQL': DataSources.RVAzureSqlDataSourceItem,
'AZURE_SYNAPSE': DataSources.RVAzureSynapseDataSourceItem,
'BIG_QUERY': DataSources.RVBigQueryDataSourceItem,
'BOXPROVIDER': DataSources.RVBoxDataSourceItem,
'CSVLOCALFILEPROVIDER': DataSources.RVCsvDataSourceItem,
'DYNAMICS_CRM': DataSources.RVDynamicsCrmDataSourceItem,
'EXCELLOCALFILEPROVIDER': DataSources.RVExcelDataSourceItem,
'GOOGLE_ANALYTICS_4': DataSources.RVGoogleAnalytics4DataSourceItem,
'GOOGLEDRIVEPROVIDER': DataSources.RVGoogleDriveDataSourceItem,
'GOOGLE_SEARCH_CONSOLE': DataSources.RVGoogleSearchConsoleDataSourceItem,
'GOOGLESHEETLOCALFILEPROVIDER': DataSources.RVGoogleSheetDataSourceItem,
'HUBSPOT': DataSources.RVHubspotDataSourceItem,
'InMemory': DataSources.RVInMemoryDataSourceItem,
'JSON': DataSources.RVJsonDataSourceItem,
'LOCALFILE': DataSources.RVLocalFileDataSourceItem,
'MARKETO': DataSources.RVMarketoDataSourceItem,
'MONGODB': DataSources.RVMongoDBDataSourceItem,
'MYSQL': DataSources.RVMySqlDataSourceItem,
'ODATAPROVIDER': DataSources.RVODataDataSourceItem,
'ONEDRIVEPROVIDER': DataSources.RVOneDriveDataSourceItem,
'ORACLE': DataSources.RVOracleDataSourceItem,
'POSTGRES': DataSources.RVPostgresDataSourceItem,
'QUICK_BOOKS': DataSources.RVQuickBooksDataSourceItem,
'AMAZON_REDSHIFT': DataSources.RVRedshiftDataSourceItem,
'REST': DataSources.RVRESTDataSourceItem,
'AMAZON_S3': DataSources.RVS3DataSourceItem,
'SHAREPOINT': {
fromJson: function (dsiJson) {
var itemType = dsiJson["ItemType"];
if (itemType == "Site") {
return new DataSources.RVSharePointSiteDataSourceItem(dsiJson);
}
else if (itemType == "List") {
return new DataSources.RVSharePointListDataSourceItem(dsiJson);
}
else if (itemType == "ListItem") {
return new DataSources.RVSharePointListItemDataSourceItem(dsiJson);
}
else if (itemType == "People") {
return new DataSources.RVSharePointPeopleDataSourceItem(dsiJson);
}
else {
return null;
}
}
},
'SNOWFLAKE': DataSources.RVSnowflakeDataSourceItem,
'SSRS': DataSources.RVReportingServicesDataSourceItem,
'SYBASE': DataSources.RVSyBaseDataSourceItem,
'SQLSERVER': DataSources.RVSqlServerDataSourceItem,
'WEBSERVICE': DataSources.RVWebResourceDataSourceItem,
'DATABRICKS': DataSources.RVDatabricksDataSourceItem, //TODO [databricks] Will undo it when we move databricks to a module.
};
function toSdkDS(dsJson) {
var provider = dsJson['Provider'];
var type = dsTypeMap[provider];
if (!type)
throw new Error(`Don't know how to deal with ${provider} data source type`);
if (type.fromJson) {
return type.fromJson(dsJson);
}
else {
return new type(dsJson);
}
}
exports.toSdkDS = toSdkDS;
/**
*
* @param dsiJson The result of the model data source item 'toJson()' method, plus the 'DataSource' properties, as follows:
* {
* ...
* DataSource: {
* ...
* },
* ResourceItem: {
* ...
* DataSource: {
* ...
* }
* }
* }
*
* As an alternative, we can pass just the data source item toJson() dictionary, plus both data source toJson() dictionaries, without any
* modification.
*
* Please note that the dictionaries may be mutated.
* @returns
*/
function toSdkDSI(dsiJson, dsJsonP, resourceDataSourceP) {
if (dsJsonP) {
dsiJson["DataSource"] = dsJsonP;
if (resourceDataSourceP) {
var resourceItem = dsiJson["ResourceItem"];
if (resourceItem) {
resourceItem["DataSource"] = resourceDataSourceP;
}
}
}
var dsJson = dsiJson["DataSource"];
var provider = dsJson["Provider"];
var type = dsiTypeMap[provider];
if (!type)
throw new Error(`Don't know how to deal with ${provider} data source type`);
if (type.fromJson) {
return type.fromJson(dsiJson);
}
else {
return new type(dsiJson);
}
}
exports.toSdkDSI = toSdkDSI;
DataSources.RVDataSourceItem.dataSourceFactory = toSdkDS;
DataSources.RVDataSourceItem.dataSourceItemFactory = toSdkDSI;
function registerDataSource(name, ds, dsi) {
dsTypeMap[name] = ds;
dsiTypeMap[name] = dsi;
}
exports.registerDataSource = registerDataSource;