diff --git a/src/services/api/base.ts b/src/services/api/base.ts index a222b04ed3..c7177ddf4b 100644 --- a/src/services/api/base.ts +++ b/src/services/api/base.ts @@ -18,17 +18,20 @@ export type AxiosOptions = { export interface BaseAPIParams { singleClusterMode: undefined | boolean; proxyMeta: undefined | boolean; + useRelativePath: undefined | boolean; } export class BaseYdbAPI extends AxiosWrapper { DEFAULT_RETRIES_COUNT = 0; singleClusterMode: BaseAPIParams['singleClusterMode']; + useRelativePath: BaseAPIParams['useRelativePath']; constructor(axiosOptions: AxiosWrapperOptions, baseApiParams: BaseAPIParams) { super(axiosOptions); this.singleClusterMode = baseApiParams.singleClusterMode; + this.useRelativePath = baseApiParams.useRelativePath; axiosRetry(this._axios, { retries: this.DEFAULT_RETRIES_COUNT, @@ -91,8 +94,19 @@ export class BaseYdbAPI extends AxiosWrapper { return `${BACKEND ?? ''}${path}`; } - getSchemaPath(props: {path?: string; database?: string}) { - return props.path; + getSchemaPath({path, database}: {path?: string; database?: string}) { + if (!this.useRelativePath || !path || !database) { + return path; + } + + if (path === database) { + return ''; + } + + if (path.startsWith(database + '/')) { + return path.slice(database.length + 1); + } + return path; } prepareArrayRequestParam(arr: (string | number)[]) { diff --git a/src/services/api/index.ts b/src/services/api/index.ts index 2bd3b439ab..b7c6e524c3 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -23,6 +23,8 @@ interface YdbEmbeddedAPIProps { withCredentials: undefined | boolean; singleClusterMode: undefined | boolean; proxyMeta: undefined | boolean; + // this setting allows to use schema object path relative to database in api requests + useRelativePath: undefined | boolean; csrfTokenGetter: undefined | (() => string | undefined); defaults: undefined | AxiosRequestConfig; } @@ -48,9 +50,10 @@ export class YdbEmbeddedAPI { proxyMeta = false, csrfTokenGetter = () => undefined, defaults = {}, + useRelativePath = false, }: YdbEmbeddedAPIProps) { const axiosParams: AxiosWrapperOptions = {config: {withCredentials, ...defaults}}; - const baseApiParams = {singleClusterMode, proxyMeta}; + const baseApiParams = {singleClusterMode, proxyMeta, useRelativePath}; this.auth = new AuthAPI(axiosParams, baseApiParams); if (webVersion) { diff --git a/src/services/api/scheme.ts b/src/services/api/scheme.ts index a12e47ce70..5febade721 100644 --- a/src/services/api/scheme.ts +++ b/src/services/api/scheme.ts @@ -10,7 +10,7 @@ export class SchemeAPI extends BaseYdbAPI { {}, { database, - path, + path: this.getSchemaPath({path, database}), }, { requestConfig: {signal}, diff --git a/src/store/configureStore.ts b/src/store/configureStore.ts index b73cca461a..820e7df1da 100644 --- a/src/store/configureStore.ts +++ b/src/store/configureStore.ts @@ -63,6 +63,7 @@ export function configureStore({ withCredentials: !customBackend, proxyMeta: false, csrfTokenGetter: undefined, + useRelativePath: false, defaults: undefined, }), } = {}) {