@bluecopa/core 0.1.75 → 0.1.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -9975,32 +9975,6 @@ function applyWorkbookBindings(fileRead, bindings) {
9975
9975
  }
9976
9976
  return remapped;
9977
9977
  }
9978
- function applyReconBindings(fileRead, bindings) {
9979
- if (!fileRead || !Array.isArray(fileRead.imports)) return fileRead;
9980
- return {
9981
- ...fileRead,
9982
- imports: fileRead.imports.map((imp) => {
9983
- if (!(imp == null ? void 0 : imp.loc)) return imp;
9984
- const resolved = resolveBinding(imp.loc, bindings);
9985
- return resolved ? { ...imp, loc: resolved } : imp;
9986
- })
9987
- };
9988
- }
9989
- function applyDefinitionBindings(fileRead, bindings, definitionType) {
9990
- if (!fileRead || !bindings || !Object.keys(bindings).length) return fileRead;
9991
- switch (definitionType) {
9992
- case "PIPELINE":
9993
- return applyPipelineBindings(fileRead, bindings);
9994
- case "SCHEDULE":
9995
- return applyScheduleBindings(fileRead, bindings);
9996
- case "WORKBOOK":
9997
- return applyWorkbookBindings(fileRead, bindings);
9998
- case "RECON":
9999
- return applyReconBindings(fileRead, bindings);
10000
- default:
10001
- return fileRead;
10002
- }
10003
- }
10004
9978
  function applyTargetedBindings(fileRead, bindings) {
10005
9979
  if (!fileRead || !bindings || !Object.keys(bindings).length) return fileRead;
10006
9980
  let result = { ...fileRead };
@@ -10026,13 +10000,9 @@ async function fetchSolutionBindings() {
10026
10000
  }
10027
10001
  function applyBindings(fileRead, bindings, definitionType) {
10028
10002
  if (!fileRead || !Object.keys(bindings).length) return fileRead;
10029
- return definitionType ? applyDefinitionBindings(
10030
- fileRead,
10031
- bindings,
10032
- definitionType
10033
- ) : applyTargetedBindings(fileRead, bindings);
10003
+ return applyTargetedBindings(fileRead, bindings);
10034
10004
  }
10035
- const hydrateWorksheet = async (sheet) => {
10005
+ const hydrateWorksheet = async (sheet, prefetchedBindings) => {
10036
10006
  try {
10037
10007
  if (!sheet) return sheet;
10038
10008
  const isHydrated = sheet.definitionModel && sheet.customModel;
@@ -10054,43 +10024,56 @@ const hydrateWorksheet = async (sheet) => {
10054
10024
  "application/json"
10055
10025
  );
10056
10026
  }
10057
- if (!definitionModel || !definitionModel[sheetId]) {
10058
- return sheet;
10059
- }
10060
- const bindings = await fetchSolutionBindings();
10061
- sheet.definitionModel = applyBindings(
10062
- definitionModel[sheetId],
10063
- bindings
10064
- );
10065
- sheet.customModel = applyBindings(
10066
- customModel[sheetId],
10027
+ const bindings = prefetchedBindings ?? await fetchSolutionBindings();
10028
+ const reboundDefinitionModel = applyBindings(
10029
+ definitionModel,
10067
10030
  bindings
10068
10031
  );
10032
+ const reboundCustomModel = applyBindings(customModel, bindings);
10033
+ if (!reboundDefinitionModel || !reboundDefinitionModel[sheetId] || !(reboundCustomModel == null ? void 0 : reboundCustomModel[sheetId])) {
10034
+ return sheet;
10035
+ }
10036
+ sheet.definitionModel = reboundDefinitionModel[sheetId];
10037
+ sheet.customModel = reboundCustomModel[sheetId];
10069
10038
  return sheet;
10070
10039
  } catch (error) {
10071
10040
  console.error("Error hydrating portal page:", error);
10072
10041
  throw error;
10073
10042
  }
10074
10043
  };
10044
+ const resolveBoundId = (rawId, bindings) => {
10045
+ const value = bindings[rawId];
10046
+ if (typeof value === "string") return value;
10047
+ if (value && typeof value === "object" && "id" in value) {
10048
+ const id = value.id;
10049
+ if (typeof id === "string") return id;
10050
+ }
10051
+ return rawId;
10052
+ };
10075
10053
  const getData$3 = async (metricSheetId, options) => {
10076
- var _a, _b, _c, _d, _e, _f;
10077
- const worksheets = await getWorksheets([metricSheetId]);
10054
+ var _a, _b, _c, _d, _e, _f, _g;
10055
+ const bindings = await fetchSolutionBindings();
10056
+ const resolvedMetricSheetId = resolveBoundId(metricSheetId, bindings);
10057
+ const worksheets = await getWorksheets([resolvedMetricSheetId]);
10078
10058
  if (_.isEmpty(worksheets)) return {};
10079
10059
  const selectedWorksheet = worksheets[0];
10080
- const hydratedSheet = await hydrateWorksheet(selectedWorksheet);
10060
+ const hydratedSheet = await hydrateWorksheet(selectedWorksheet, bindings);
10081
10061
  if (!hydratedSheet) return {};
10082
10062
  const selectedMetricsParentIds = getSelectedMetricsParentIds([
10083
10063
  { sheet: selectedWorksheet }
10084
10064
  ]);
10085
- const parentWorksheets = await getWorksheets(selectedMetricsParentIds);
10086
- const parentSheet = _.find(
10087
- parentWorksheets,
10088
- (ps) => ps.id === (hydratedSheet == null ? void 0 : hydratedSheet.customFields.parentTableId)
10065
+ const resolvedParentIds = selectedMetricsParentIds.map(
10066
+ (id) => resolveBoundId(id, bindings)
10089
10067
  );
10068
+ const rawParentTableId = (_a = hydratedSheet == null ? void 0 : hydratedSheet.customFields) == null ? void 0 : _a.parentTableId;
10069
+ const resolvedParentTableId = typeof rawParentTableId === "string" ? resolveBoundId(rawParentTableId, bindings) : void 0;
10070
+ const parentFetchIds = resolvedParentTableId ? Array.from(/* @__PURE__ */ new Set([...resolvedParentIds, resolvedParentTableId])) : resolvedParentIds;
10071
+ const parentWorksheets = await getWorksheets(parentFetchIds);
10072
+ const parentSheet = resolvedParentTableId ? _.find(parentWorksheets, (ps) => ps.id === resolvedParentTableId) : void 0;
10090
10073
  let definitionModel;
10091
10074
  let customModel;
10092
10075
  if (parentSheet) {
10093
- const hydratedParentSheet = await hydrateWorksheet(parentSheet);
10076
+ const hydratedParentSheet = await hydrateWorksheet(parentSheet, bindings);
10094
10077
  if (hydratedParentSheet == null ? void 0 : hydratedParentSheet.definitionModel) {
10095
10078
  const {
10096
10079
  definitionModel: parentDefinitionModel,
@@ -10112,7 +10095,7 @@ const getData$3 = async (metricSheetId, options) => {
10112
10095
  const dModel = definitionModel;
10113
10096
  const gridColumnState = cModel == null ? void 0 : cModel.gridColumnState;
10114
10097
  const { variable, parentTableVariable, inputs } = cModel;
10115
- const aliases = (_a = dModel == null ? void 0 : dModel.aliases) == null ? void 0 : _a[parentTableVariable];
10098
+ const aliases = (_b = dModel == null ? void 0 : dModel.aliases) == null ? void 0 : _b[parentTableVariable];
10116
10099
  let timeBin = "";
10117
10100
  if (options == null ? void 0 : options.isKPI) {
10118
10101
  timeBin = (options == null ? void 0 : options.plotAsTrend) ? !_.isEmpty(cModel == null ? void 0 : cModel.timeBin) ? cModel == null ? void 0 : cModel.timeBin : "per_month" : "";
@@ -10135,13 +10118,13 @@ const getData$3 = async (metricSheetId, options) => {
10135
10118
  datasetName: (cModel == null ? void 0 : cModel.datasetName) ?? "",
10136
10119
  columnSettings: columnSettings ?? [],
10137
10120
  filterColumnsBy: (cModel == null ? void 0 : cModel.filterColumnsBy) ?? {},
10138
- filterModel: ((_c = (_b = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _b.gridColumnState) == null ? void 0 : _c.filterModel) ?? {},
10121
+ filterModel: ((_d = (_c = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _c.gridColumnState) == null ? void 0 : _d.filterModel) ?? {},
10139
10122
  valueCols: valueCols ?? [],
10140
10123
  rowGroupCols: (gridColumnState == null ? void 0 : gridColumnState.rowGroupCols) ?? [],
10141
10124
  pivotCols: (gridColumnState == null ? void 0 : gridColumnState.pivotCols) ?? [],
10142
10125
  dateColumn: cModel == null ? void 0 : cModel.dateColumn,
10143
10126
  timeBin,
10144
- dateRange: (_d = cModel == null ? void 0 : cModel.inputs) == null ? void 0 : _d.date_range,
10127
+ dateRange: (_e = cModel == null ? void 0 : cModel.inputs) == null ? void 0 : _e.date_range,
10145
10128
  aliases,
10146
10129
  lastModifiedDate: hydratedSheet == null ? void 0 : hydratedSheet.lastModifiedDate,
10147
10130
  hierarchy: cModel == null ? void 0 : cModel.hierarchy,
@@ -10159,8 +10142,8 @@ const getData$3 = async (metricSheetId, options) => {
10159
10142
  lastModifiedDate: hydratedSheet.lastModifiedDate,
10160
10143
  promotedFiltersStoreValue: {},
10161
10144
  promotedFilters: [],
10162
- dateRangeModel: ((_e = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _e.dateRangeModel) ?? defaultDashboardDateRangeModel,
10163
- currencyModel: ((_f = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _f.currencyModel) ?? defaultCurrencyModel,
10145
+ dateRangeModel: ((_f = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _f.dateRangeModel) ?? defaultDashboardDateRangeModel,
10146
+ currencyModel: ((_g = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _g.currencyModel) ?? defaultCurrencyModel,
10164
10147
  commonFilters: []
10165
10148
  });
10166
10149
  let resultData = [];