@qrvey/utils 1.13.0-9 → 1.14.0-0

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.
Files changed (55) hide show
  1. package/dist/cache-managers/cache-chart-manager.d.ts +5 -17
  2. package/dist/cache-managers/cache-chart-manager.js +25 -23
  3. package/dist/cache-managers/cache-manager.d.ts +25 -29
  4. package/dist/cache-managers/cache-manager.js +92 -32
  5. package/dist/cache-managers/cache-metric-manager.d.ts +6 -18
  6. package/dist/cache-managers/cache-metric-manager.js +26 -30
  7. package/dist/cache-managers/cache-model-manager.d.ts +5 -17
  8. package/dist/cache-managers/cache-model-manager.js +23 -25
  9. package/dist/cache-managers/cache-permissions-manager.d.ts +5 -18
  10. package/dist/cache-managers/cache-permissions-manager.js +22 -24
  11. package/dist/cache-managers/cache-theme-manager.d.ts +5 -18
  12. package/dist/cache-managers/cache-theme-manager.js +22 -24
  13. package/dist/cache-managers/clean-cache-managers.d.ts +1 -0
  14. package/dist/cache-managers/clean-cache-managers.js +26 -0
  15. package/dist/cache-managers/index.d.ts +7 -0
  16. package/dist/cache-managers/index.js +7 -0
  17. package/dist/cjs/cache-managers/cache-chart-manager.d.ts +5 -17
  18. package/dist/cjs/cache-managers/cache-chart-manager.js +25 -23
  19. package/dist/cjs/cache-managers/cache-manager.d.ts +25 -29
  20. package/dist/cjs/cache-managers/cache-manager.js +92 -32
  21. package/dist/cjs/cache-managers/cache-metric-manager.d.ts +6 -18
  22. package/dist/cjs/cache-managers/cache-metric-manager.js +26 -30
  23. package/dist/cjs/cache-managers/cache-model-manager.d.ts +5 -17
  24. package/dist/cjs/cache-managers/cache-model-manager.js +23 -25
  25. package/dist/cjs/cache-managers/cache-permissions-manager.d.ts +5 -18
  26. package/dist/cjs/cache-managers/cache-permissions-manager.js +22 -24
  27. package/dist/cjs/cache-managers/cache-theme-manager.d.ts +5 -18
  28. package/dist/cjs/cache-managers/cache-theme-manager.js +22 -24
  29. package/dist/cjs/cache-managers/clean-cache-managers.d.ts +1 -0
  30. package/dist/cjs/cache-managers/clean-cache-managers.js +30 -0
  31. package/dist/cjs/cache-managers/index.d.ts +7 -0
  32. package/dist/cjs/cache-managers/index.js +23 -0
  33. package/dist/cjs/globalization/interfaces/dashboard/II18nDashboardMessages.d.ts +2 -0
  34. package/dist/cjs/globalization/interfaces/panel/II18nPanelTooltips.d.ts +1 -0
  35. package/dist/cjs/globalization/labels/dashboard/I18N_DASHBOARD.js +3 -1
  36. package/dist/cjs/globalization/labels/panel/I18N_PANEL.js +1 -0
  37. package/dist/cjs/index.d.ts +2 -1
  38. package/dist/cjs/index.js +2 -1
  39. package/dist/cjs/qrvey/interfaces/IBDataset.d.ts +2 -0
  40. package/dist/cjs/qrvey/interfaces/IDataset.d.ts +3 -1
  41. package/dist/cjs/services/adapters/BDatasetsToUIDatasets.adapter.js +1 -0
  42. package/dist/cjs/services/api/metrics.api.js +1 -1
  43. package/dist/cjs/services/helpers/Request.js +5 -1
  44. package/dist/globalization/interfaces/dashboard/II18nDashboardMessages.d.ts +2 -0
  45. package/dist/globalization/interfaces/panel/II18nPanelTooltips.d.ts +1 -0
  46. package/dist/globalization/labels/dashboard/I18N_DASHBOARD.js +3 -1
  47. package/dist/globalization/labels/panel/I18N_PANEL.js +1 -0
  48. package/dist/index.d.ts +2 -1
  49. package/dist/index.js +2 -1
  50. package/dist/qrvey/interfaces/IBDataset.d.ts +2 -0
  51. package/dist/qrvey/interfaces/IDataset.d.ts +3 -1
  52. package/dist/services/adapters/BDatasetsToUIDatasets.adapter.js +1 -0
  53. package/dist/services/api/metrics.api.js +1 -1
  54. package/dist/services/helpers/Request.js +5 -1
  55. package/package.json +1 -1
@@ -1,39 +1,37 @@
1
- import { createStore } from "@stencil/store";
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
2
10
  import { QrveyCacheManager } from "./cache-manager";
3
11
  import { getCurrentTheme, getThemeById } from "../services/api/Themes.api";
4
12
  export class ThemeCacheManager extends QrveyCacheManager {
5
13
  static getInstance() {
6
- if (!window.themeCacheManager) {
7
- window.themeCacheManager = new ThemeCacheManager();
14
+ if (!window.qvThemeCacheManager) {
15
+ window.qvThemeCacheManager = new ThemeCacheManager();
8
16
  }
9
- return window.themeCacheManager;
17
+ return window.qvThemeCacheManager;
10
18
  }
11
- getConfigPropertyName() {
19
+ getConfigEntityId() {
12
20
  return "theme_id";
13
21
  }
14
- getStorePropertyName() {
15
- return "theme";
16
- }
17
22
  buildStoreId({ theme_id, app_id }) {
18
23
  return `${app_id}-${theme_id !== null && theme_id !== void 0 ? theme_id : "current"}`;
19
24
  }
20
- createStore() {
21
- return createStore({
22
- theme: null,
23
- loading: true,
24
- error: null,
25
- });
26
- }
27
25
  fetchDataAndUpdateStore(state, config) {
28
- (config.theme_id ? getThemeById(config) : getCurrentTheme(config))
29
- .then((theme) => {
30
- state.theme = theme;
31
- state.error = null;
32
- state.loading = false;
33
- })
34
- .catch((e) => {
35
- state.error = e;
36
- state.loading = false;
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return (config.theme_id ? getThemeById(config) : getCurrentTheme(config))
28
+ .then((theme) => {
29
+ state.entity = theme;
30
+ state.error = null;
31
+ })
32
+ .catch((e) => {
33
+ state.error = e;
34
+ });
37
35
  });
38
36
  }
39
37
  }
@@ -0,0 +1 @@
1
+ export declare const cleanCacheManagers: () => Promise<void>;
@@ -0,0 +1,26 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { ChartCacheManager } from "./cache-chart-manager";
11
+ import { MetricCacheManager } from "./cache-metric-manager";
12
+ import { ModelCacheManager } from "./cache-model-manager";
13
+ import { PermissionsCacheManager } from "./cache-permissions-manager";
14
+ import { ThemeCacheManager } from "./cache-theme-manager";
15
+ export const cleanCacheManagers = () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const chartManager = ChartCacheManager.getInstance();
17
+ yield chartManager.cleanAllStores();
18
+ const metricManager = MetricCacheManager.getInstance();
19
+ yield metricManager.cleanAllStores();
20
+ const modelManager = ModelCacheManager.getInstance();
21
+ yield modelManager.cleanAllStores();
22
+ const permissionsManager = PermissionsCacheManager.getInstance();
23
+ yield permissionsManager.cleanAllStores();
24
+ const themeManager = ThemeCacheManager.getInstance();
25
+ yield themeManager.cleanAllStores();
26
+ });
@@ -0,0 +1,7 @@
1
+ export * from "./cache-chart-manager";
2
+ export * from "./cache-manager";
3
+ export * from "./cache-metric-manager";
4
+ export * from "./cache-model-manager";
5
+ export * from "./cache-permissions-manager";
6
+ export * from "./cache-theme-manager";
7
+ export * from "./clean-cache-managers";
@@ -0,0 +1,7 @@
1
+ export * from "./cache-chart-manager";
2
+ export * from "./cache-manager";
3
+ export * from "./cache-metric-manager";
4
+ export * from "./cache-model-manager";
5
+ export * from "./cache-permissions-manager";
6
+ export * from "./cache-theme-manager";
7
+ export * from "./clean-cache-managers";
@@ -1,4 +1,4 @@
1
- import { OnChangeType, QrveyCacheManager } from "./cache-manager";
1
+ import { QrveyCacheManager, QvCacheStoreProperties } from "./cache-manager";
2
2
  export interface IGetChartConfig {
3
3
  qv_token?: string;
4
4
  api_key?: string;
@@ -14,21 +14,9 @@ export interface IGetChartConfig {
14
14
  "temporal-tokens"?: boolean;
15
15
  };
16
16
  }
17
- interface IChartStoreState {
18
- chart: any;
19
- loading: boolean;
20
- error: any;
21
- }
22
- export declare class ChartCacheManager extends QrveyCacheManager<IChartStoreState, IGetChartConfig> {
23
- static getInstance(): ChartCacheManager;
24
- protected getConfigPropertyName(): keyof IGetChartConfig;
25
- protected getStorePropertyName(): keyof IChartStoreState;
17
+ export declare class ChartCacheManager extends QrveyCacheManager<QvCacheStoreProperties, IGetChartConfig> {
18
+ static getInstance(): any;
19
+ protected getConfigEntityId(): keyof IGetChartConfig;
26
20
  protected buildStoreId({ chart_id }: IGetChartConfig): string;
27
- protected createStore(_initialState?: Partial<IChartStoreState>): {
28
- state: IChartStoreState;
29
- onChange: OnChangeType;
30
- set: (property: keyof IChartStoreState, value: unknown) => void;
31
- };
32
- protected fetchDataAndUpdateStore(state: IChartStoreState, config: IGetChartConfig): void;
21
+ protected fetchDataAndUpdateStore(state: QvCacheStoreProperties, config: IGetChartConfig): Promise<void>;
33
22
  }
34
- export {};
@@ -1,44 +1,46 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  exports.ChartCacheManager = void 0;
7
- const store_1 = require("@stencil/store");
8
16
  const cache_manager_1 = require("./cache-manager");
9
17
  const Charts_api_1 = __importDefault(require("../services/api/Charts.api"));
10
18
  class ChartCacheManager extends cache_manager_1.QrveyCacheManager {
11
19
  static getInstance() {
12
- if (!window.chartCacheManager) {
13
- window.chartCacheManager = new ChartCacheManager();
20
+ if (!window.qvChartCacheManager) {
21
+ window.qvChartCacheManager = new ChartCacheManager();
14
22
  }
15
- return window.chartCacheManager;
23
+ return window.qvChartCacheManager;
16
24
  }
17
- getConfigPropertyName() {
25
+ getConfigEntityId() {
18
26
  return "chart_id";
19
27
  }
20
- getStorePropertyName() {
21
- return "chart";
22
- }
23
28
  buildStoreId({ chart_id }) {
24
29
  return `${chart_id}`;
25
30
  }
26
- createStore(_initialState) {
27
- return (0, store_1.createStore)(Object.assign({ chart: null, loading: true, error: null }, _initialState));
28
- }
29
31
  fetchDataAndUpdateStore(state, config) {
30
- const chartConfig = Object.assign(Object.assign({}, config), { translated: true });
31
- const api = new Charts_api_1.default(chartConfig);
32
- api
33
- .getChart(chartConfig)
34
- .then((chart) => {
35
- state.chart = chart;
36
- state.error = null;
37
- state.loading = false;
38
- })
39
- .catch((e) => {
40
- state.error = e;
41
- state.loading = false;
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const chartConfig = Object.assign(Object.assign({}, config), { translated: true });
34
+ const api = new Charts_api_1.default(chartConfig);
35
+ return api
36
+ .getChart(chartConfig)
37
+ .then((chart) => {
38
+ state.entity = chart;
39
+ state.error = null;
40
+ })
41
+ .catch((e) => {
42
+ state.error = e;
43
+ });
42
44
  });
43
45
  }
44
46
  }
@@ -1,36 +1,32 @@
1
1
  export type OnChangeType = (property: string | number | symbol, callback: (entity: unknown) => void) => () => void;
2
- export declare abstract class QrveyCacheManager<TStoreState, TConfig> {
3
- protected stores: Map<string, {
4
- state: TStoreState;
5
- onChange: OnChangeType;
6
- set: (property: keyof TStoreState, value: unknown) => void;
7
- }>;
8
- protected abstract getConfigPropertyName(): keyof TConfig;
9
- protected abstract getStorePropertyName(): keyof TStoreState;
2
+ export interface QvCacheStoreProperties {
3
+ entity: unknown;
4
+ error: boolean;
5
+ }
6
+ interface QrveyCacheStore<T> {
7
+ state: T;
8
+ onChange: OnChangeType;
9
+ set: (property: keyof T, value: unknown) => void;
10
+ dispose: () => void;
11
+ }
12
+ export declare abstract class QrveyCacheManager<TStoreState extends QvCacheStoreProperties, TConfig> {
13
+ protected stores: Map<string, QrveyCacheStore<TStoreState> | Promise<QrveyCacheStore<TStoreState>>>;
14
+ operationLocks: Map<any, any>;
15
+ protected abstract getConfigEntityId(): keyof TConfig;
10
16
  protected abstract buildStoreId(config: TConfig): string;
11
- protected abstract fetchDataAndUpdateStore(state: TStoreState, config: TConfig): void;
12
- protected abstract createStore(_initialState?: Partial<TStoreState>): {
13
- state: TStoreState;
14
- onChange: OnChangeType;
15
- set: (property: keyof TStoreState, value: unknown) => void;
16
- };
17
- protected getStoreFromPromise(config: TConfig, id: string): Promise<{
18
- state: TStoreState;
19
- onChange: OnChangeType;
20
- set: (property: keyof TStoreState, value: unknown) => void;
21
- }>;
17
+ protected abstract fetchDataAndUpdateStore(state: TStoreState, config: TConfig): Promise<void>;
18
+ protected createStore(_initialState?: Partial<TStoreState>): Promise<QrveyCacheStore<TStoreState>>;
19
+ getStoreFromPromise(config: TConfig, id: string): Promise<QrveyCacheStore<TStoreState>>;
22
20
  private getCreatedStore;
23
- getStore(config: TConfig): {
24
- state: TStoreState;
25
- onChange: OnChangeType;
26
- set: (property: keyof TStoreState, value: unknown) => void;
27
- };
28
- getMultipleStores(config: TConfig, ids: string[]): Promise<{
29
- state: TStoreState;
30
- onChange: OnChangeType;
31
- }[]>;
21
+ private initializeStore;
22
+ getStore(config: TConfig): Promise<QrveyCacheStore<TStoreState>>;
23
+ getMultipleStores(config: TConfig, ids: string[]): Promise<QrveyCacheStore<TStoreState>[]>;
32
24
  setStoresFromData(stores: {
33
25
  storeId: string;
34
26
  state: Partial<TStoreState>;
35
- }[]): void;
27
+ }[]): Promise<void[]>;
28
+ private deleteStoreRegister;
29
+ cleanStore(storeId: string): Promise<void>;
30
+ cleanAllStores(): Promise<void>;
36
31
  }
32
+ export {};
@@ -1,57 +1,117 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.QrveyCacheManager = void 0;
13
+ const store_1 = require("@stencil/store");
4
14
  class QrveyCacheManager {
5
15
  constructor() {
6
16
  this.stores = new Map();
17
+ this.operationLocks = new Map();
18
+ }
19
+ createStore(_initialState) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const initialState = Object.assign({ entity: null, error: null }, _initialState);
22
+ return (0, store_1.createStore)(initialState);
23
+ });
7
24
  }
8
25
  getStoreFromPromise(config, id) {
9
- return new Promise((resolve) => {
10
- const configProperty = this.getConfigPropertyName();
11
- const storeProperty = this.getStorePropertyName();
12
- const extendedConfig = Object.assign(Object.assign({}, config), { [configProperty]: id });
13
- const store = this.getStore(extendedConfig);
14
- if (store.state[storeProperty] !== null) {
15
- resolve(store);
16
- }
17
- else {
18
- const unsubscribe = store.onChange(storeProperty, (entity) => {
19
- if (entity !== null) {
20
- unsubscribe();
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return new Promise((resolve, reject) => {
28
+ (() => __awaiter(this, void 0, void 0, function* () {
29
+ try {
30
+ const configEntityId = this.getConfigEntityId();
31
+ const extendedConfig = Object.assign(Object.assign({}, config), { [configEntityId]: id });
32
+ const store = yield this.getStore(extendedConfig);
21
33
  resolve(store);
22
34
  }
23
- });
24
- }
35
+ catch (error) {
36
+ reject(error);
37
+ }
38
+ }))();
39
+ });
25
40
  });
26
41
  }
27
42
  getCreatedStore(storeId) {
28
- return this.stores.get(storeId);
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ return this.stores.get(storeId);
45
+ });
46
+ }
47
+ initializeStore(config, storeId) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const newStore = yield this.createStore();
50
+ yield this.fetchDataAndUpdateStore(newStore.state, config);
51
+ this.stores.set(storeId, newStore);
52
+ return newStore;
53
+ });
29
54
  }
30
55
  getStore(config) {
31
- const storeId = this.buildStoreId(config);
32
- const store = this.getCreatedStore(storeId);
33
- if (store) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const storeId = this.buildStoreId(config);
58
+ while (this.operationLocks.has(storeId)) {
59
+ yield this.operationLocks.get(storeId);
60
+ }
61
+ let store = this.stores.get(storeId);
62
+ if (!store) {
63
+ let resolveLock;
64
+ const lockPromise = new Promise((resolve) => (resolveLock = resolve));
65
+ this.operationLocks.set(storeId, lockPromise);
66
+ try {
67
+ store = yield this.initializeStore(config, storeId);
68
+ this.stores.set(storeId, store);
69
+ }
70
+ finally {
71
+ resolveLock();
72
+ this.operationLocks.delete(storeId);
73
+ }
74
+ }
34
75
  return store;
35
- }
36
- const { state, onChange, set } = store !== null && store !== void 0 ? store : this.createStore();
37
- this.stores.set(storeId, { state, onChange, set });
38
- this.fetchDataAndUpdateStore(state, config);
39
- return { state, onChange, set };
76
+ });
40
77
  }
41
78
  getMultipleStores(config, ids) {
42
- const promises = ids.map((id) => this.getStoreFromPromise(config, id));
79
+ const promises = ids.map((id) => __awaiter(this, void 0, void 0, function* () { return yield this.getStoreFromPromise(config, id); }));
43
80
  return Promise.all(promises);
44
81
  }
45
82
  setStoresFromData(stores) {
46
- stores.forEach((store) => {
47
- const createdStore = this.getCreatedStore(store.storeId);
48
- if (!createdStore) {
49
- const newStore = this.createStore(store.state);
50
- this.stores.set(store.storeId, newStore);
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ return Promise.all(stores.map((store) => __awaiter(this, void 0, void 0, function* () {
85
+ let createdStore = yield this.getCreatedStore(store.storeId);
86
+ if (!createdStore) {
87
+ createdStore = yield this.createStore();
88
+ this.stores.set(store.storeId, createdStore);
89
+ }
90
+ Object.entries(store.state).forEach(([key, value]) => {
91
+ createdStore.set(key, value);
92
+ });
93
+ })));
94
+ });
95
+ }
96
+ deleteStoreRegister(storeId) {
97
+ this.stores.delete(storeId);
98
+ }
99
+ cleanStore(storeId) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ const existingStore = yield this.getCreatedStore(storeId);
102
+ if (existingStore) {
103
+ const store = existingStore instanceof Promise ? yield existingStore : existingStore;
104
+ store.dispose();
105
+ this.deleteStoreRegister(storeId);
106
+ }
107
+ });
108
+ }
109
+ cleanAllStores() {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const storeIds = Array.from(this.stores.keys());
112
+ for (const storeId of storeIds) {
113
+ yield this.cleanStore(storeId);
51
114
  }
52
- Object.entries(store.state).forEach(([key, value]) => {
53
- createdStore.set(key, value);
54
- });
55
115
  });
56
116
  }
57
117
  }
@@ -1,4 +1,4 @@
1
- import { OnChangeType, QrveyCacheManager } from "./cache-manager";
1
+ import { QrveyCacheManager, QvCacheStoreProperties } from "./cache-manager";
2
2
  export interface IGetMetricConfig {
3
3
  qv_token?: string;
4
4
  api_key?: string;
@@ -15,21 +15,9 @@ export interface IGetMetricConfig {
15
15
  "temporal-tokens"?: boolean;
16
16
  };
17
17
  }
18
- interface IMetricStoreState {
19
- metric: any;
20
- loading: boolean;
21
- error: any;
18
+ export declare class MetricCacheManager extends QrveyCacheManager<QvCacheStoreProperties, IGetMetricConfig> {
19
+ static getInstance(): any;
20
+ protected getConfigEntityId(): keyof IGetMetricConfig;
21
+ protected buildStoreId({ metric_id }: IGetMetricConfig): string;
22
+ protected fetchDataAndUpdateStore(state: QvCacheStoreProperties, config: IGetMetricConfig): Promise<void>;
22
23
  }
23
- export declare class MetricCacheManager extends QrveyCacheManager<IMetricStoreState, IGetMetricConfig> {
24
- static getInstance(): MetricCacheManager;
25
- protected getConfigPropertyName(): keyof IGetMetricConfig;
26
- protected getStorePropertyName(): keyof IMetricStoreState;
27
- protected buildStoreId({ metric_id, translated }: IGetMetricConfig): string;
28
- protected createStore(): {
29
- state: IMetricStoreState;
30
- onChange: OnChangeType;
31
- set: (property: keyof IMetricStoreState, value: unknown) => void;
32
- };
33
- protected fetchDataAndUpdateStore(state: IMetricStoreState, config: IGetMetricConfig): void;
34
- }
35
- export {};
@@ -1,49 +1,45 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  exports.MetricCacheManager = void 0;
7
- const store_1 = require("@stencil/store");
8
16
  const cache_manager_1 = require("./cache-manager");
9
- const isEmpty_1 = require("../general/mix/isEmpty");
10
17
  const metrics_api_1 = __importDefault(require("../services/api/metrics.api"));
11
18
  class MetricCacheManager extends cache_manager_1.QrveyCacheManager {
12
19
  static getInstance() {
13
- if (!window.metricCacheManager) {
14
- window.metricCacheManager = new MetricCacheManager();
20
+ if (!window.qvMetricCacheManager) {
21
+ window.qvMetricCacheManager = new MetricCacheManager();
15
22
  }
16
- return window.metricCacheManager;
23
+ return window.qvMetricCacheManager;
17
24
  }
18
- getConfigPropertyName() {
25
+ getConfigEntityId() {
19
26
  return "metric_id";
20
27
  }
21
- getStorePropertyName() {
22
- return "metric";
23
- }
24
- buildStoreId({ metric_id, translated }) {
25
- const translate = (0, isEmpty_1.isEmpty)(translated) ? true : translated;
26
- return `${metric_id}-${translate ? "translated" : ""}`;
27
- }
28
- createStore() {
29
- return (0, store_1.createStore)({
30
- metric: null,
31
- loading: true,
32
- error: null,
33
- });
28
+ buildStoreId({ metric_id }) {
29
+ return `${metric_id}`;
34
30
  }
35
31
  fetchDataAndUpdateStore(state, config) {
36
- const api = new metrics_api_1.default();
37
- api
38
- .getMetricConfig(config)
39
- .then((metric) => {
40
- state.metric = metric;
41
- state.error = null;
42
- state.loading = false;
43
- })
44
- .catch((e) => {
45
- state.error = e;
46
- state.loading = false;
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const api = new metrics_api_1.default();
34
+ return api
35
+ .getMetricConfig(config)
36
+ .then((metric) => {
37
+ state.entity = metric;
38
+ state.error = null;
39
+ })
40
+ .catch((e) => {
41
+ state.error = e;
42
+ });
47
43
  });
48
44
  }
49
45
  }
@@ -1,5 +1,4 @@
1
- import { OnChangeType, QrveyCacheManager } from "./cache-manager";
2
- import { IModel } from "../qrvey";
1
+ import { QrveyCacheManager, QvCacheStoreProperties } from "./cache-manager";
3
2
  interface IGetModelConfig {
4
3
  qv_token?: string;
5
4
  api_key?: string;
@@ -10,21 +9,10 @@ interface IGetModelConfig {
10
9
  qrvey_id: string;
11
10
  i18n?: any;
12
11
  }
13
- interface IModelStoreState {
14
- model: IModel;
15
- loading: boolean;
16
- error: any;
17
- }
18
- export declare class ModelCacheManager extends QrveyCacheManager<IModelStoreState, IGetModelConfig> {
19
- static getInstance(): ModelCacheManager;
20
- protected getConfigPropertyName(): keyof IGetModelConfig;
21
- protected getStorePropertyName(): keyof IModelStoreState;
12
+ export declare class ModelCacheManager extends QrveyCacheManager<QvCacheStoreProperties, IGetModelConfig> {
13
+ static getInstance(): any;
14
+ protected getConfigEntityId(): keyof IGetModelConfig;
22
15
  protected buildStoreId({ qrvey_id }: IGetModelConfig): string;
23
- protected createStore(): {
24
- state: IModelStoreState;
25
- onChange: OnChangeType;
26
- set: (property: keyof IModelStoreState, value: unknown) => void;
27
- };
28
- protected fetchDataAndUpdateStore(state: IModelStoreState, config: IGetModelConfig): void;
16
+ protected fetchDataAndUpdateStore(state: QvCacheStoreProperties, config: IGetModelConfig): Promise<void>;
29
17
  }
30
18
  export {};
@@ -1,43 +1,41 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.ModelCacheManager = void 0;
4
- const store_1 = require("@stencil/store");
5
13
  const cache_manager_1 = require("./cache-manager");
6
14
  const getModel_api_1 = require("../services/api/getModel.api");
7
15
  class ModelCacheManager extends cache_manager_1.QrveyCacheManager {
8
16
  static getInstance() {
9
- if (!window.modelCacheManager) {
10
- window.modelCacheManager = new ModelCacheManager();
17
+ if (!window.qvModelCacheManager) {
18
+ window.qvModelCacheManager = new ModelCacheManager();
11
19
  }
12
- return window.modelCacheManager;
20
+ return window.qvModelCacheManager;
13
21
  }
14
- getConfigPropertyName() {
22
+ getConfigEntityId() {
15
23
  return "qrvey_id";
16
24
  }
17
- getStorePropertyName() {
18
- return "model";
19
- }
20
25
  buildStoreId({ qrvey_id }) {
21
26
  return `${qrvey_id}`;
22
27
  }
23
- createStore() {
24
- return (0, store_1.createStore)({
25
- model: null,
26
- loading: true,
27
- error: null,
28
- });
29
- }
30
28
  fetchDataAndUpdateStore(state, config) {
31
- const includeInfo = ["bucketsInfo", "formulaInfo", "colorByValueInfo"];
32
- (0, getModel_api_1.getModel)(config, { includeInfo })
33
- .then((model) => {
34
- state.model = model;
35
- state.error = null;
36
- state.loading = false;
37
- })
38
- .catch((e) => {
39
- state.error = e;
40
- state.loading = false;
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const includeInfo = ["bucketsInfo", "formulaInfo", "colorByValueInfo"];
31
+ return (0, getModel_api_1.getModel)(config, { includeInfo })
32
+ .then((model) => {
33
+ state.entity = model;
34
+ state.error = null;
35
+ })
36
+ .catch((e) => {
37
+ state.error = e;
38
+ });
41
39
  });
42
40
  }
43
41
  }