From 686263ad8ce101983252a1c6fa46cc9f887fbc6b Mon Sep 17 00:00:00 2001 From: Elena Makarova Date: Fri, 5 Sep 2025 16:45:54 +0300 Subject: [PATCH 1/3] feat: configurable use relative paths in api --- src/services/api/base.ts | 18 ++++++++++++++++-- src/services/api/index.ts | 4 +++- src/services/api/scheme.ts | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) 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..ef45ce4044 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -23,6 +23,7 @@ interface YdbEmbeddedAPIProps { withCredentials: undefined | boolean; singleClusterMode: undefined | boolean; proxyMeta: undefined | boolean; + useRelativePath: undefined | boolean; csrfTokenGetter: undefined | (() => string | undefined); defaults: undefined | AxiosRequestConfig; } @@ -48,9 +49,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}, From 3d3c5797936008a320d252212b97450a48ba4def Mon Sep 17 00:00:00 2001 From: Elena Makarova Date: Fri, 5 Sep 2025 16:50:36 +0300 Subject: [PATCH 2/3] fix: review --- src/services/api/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/api/index.ts b/src/services/api/index.ts index ef45ce4044..b7c6e524c3 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -23,6 +23,7 @@ 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; From 970a66f373abbddd6a2bb9357fdc3701729db1db Mon Sep 17 00:00:00 2001 From: Elena Makarova Date: Fri, 5 Sep 2025 16:51:39 +0300 Subject: [PATCH 3/3] fix: configureStore --- src/store/configureStore.ts | 1 + 1 file changed, 1 insertion(+) 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, }), } = {}) {