Skip to content

Commit

Permalink
Remove registry from CE (#1765)
Browse files Browse the repository at this point in the history
  • Loading branch information
melikhov-dev authored Oct 30, 2024
1 parent e77ad3f commit 4976e13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import fs from 'fs';

import ivm from 'isolated-vm';

import type {DashWidgetConfig, FeatureConfig} from '../../../../../../shared';
import type {
ConnectorType,
DashWidgetConfig,
FeatureConfig,
Palette,
} from '../../../../../../shared';
import {EDITOR_TYPE_CONFIG_TABS, Feature} from '../../../../../../shared';
import {registry} from '../../../../../registry';
import type {ChartsEngine} from '../../../index';
import type {ResolvedConfig} from '../../storage/types';
import {Processor} from '../index';
Expand Down Expand Up @@ -38,6 +42,8 @@ type IsolatedSandboxChartBuilderArgs = {
key: string,
params?: Record<string, string | number>,
) => string;
getAvailablePalettesMap: () => Record<string, Palette>;
getQLConnectionTypeMap: () => Record<string, ConnectorType>;
};

export const getIsolatedSandboxChartBuilder = async (
Expand All @@ -53,16 +59,16 @@ export const getIsolatedSandboxChartBuilder = async (
workbookId,
serverFeatures,
getTranslation,
getAvailablePalettesMap,
getQLConnectionTypeMap,
} = args;
const type = config.meta.stype;
let shared: Record<string, any>;
const getAvailablePalettesMap = registry.common.functions.get('getAvailablePalettesMap');

const palettes = getAvailablePalettesMap();

const isolate = new ivm.Isolate({memoryLimit: 1024});
const context = isolate.createContextSync();
const getQLConnectionTypeMap = registry.getQLConnectionTypeMap();

const qlConnectionTypeMap = getQLConnectionTypeMap();
context.evalSync(
`
// I do not know why, but this is not exists in V8 Isolate.
Expand All @@ -73,7 +79,7 @@ export const getIsolatedSandboxChartBuilder = async (
let __runtimeMetadata = {userParamsOverride: undefined};
let __features = JSON.parse('${JSON.stringify(serverFeatures)}');
let __palettes = JSON.parse('${JSON.stringify(palettes)}');
let __qlConnectionTypeMap = JSON.parse('${JSON.stringify(getQLConnectionTypeMap)}');
let __qlConnectionTypeMap = JSON.parse('${JSON.stringify(qlConnectionTypeMap)}');
`,
);

Expand Down
5 changes: 5 additions & 0 deletions src/server/components/charts-engine/runners/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {AppContext} from '@gravity-ui/nodekit';
import type {DashWidgetConfig} from '../../../../shared';
import {Feature, getServerFeatures, isEnabledServerFeature} from '../../../../shared';
import {getTranslationFn} from '../../../../shared/modules/language';
import {registry} from '../../../registry';
import {createI18nInstance} from '../../../utils/language';
import {getIsolatedSandboxChartBuilder} from '../components/processor/isolated-sandbox/isolated-sandbox-chart-builder';

Expand Down Expand Up @@ -33,6 +34,8 @@ async function getChartBuilder({
const i18n = createI18nInstance({lang: userLang});
const getTranslation = getTranslationFn(i18n.getI18nServer());
const serverFeatures = getServerFeatures(parentContext);
const getAvailablePalettesMap = registry.common.functions.get('getAvailablePalettesMap');
const getQLConnectionTypeMap = registry.getQLConnectionTypeMap;
const chartBuilder = await getIsolatedSandboxChartBuilder({
userLang,
userLogin,
Expand All @@ -42,6 +45,8 @@ async function getChartBuilder({
chartsEngine,
serverFeatures,
getTranslation,
getAvailablePalettesMap,
getQLConnectionTypeMap,
});

return {chartBuilder};
Expand Down

0 comments on commit 4976e13

Please sign in to comment.