Skip to content

Commit 3069209

Browse files
authored
feat: configurable use relative paths in api (#2841)
1 parent c81a708 commit 3069209

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

src/services/api/base.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ export type AxiosOptions = {
1818
export interface BaseAPIParams {
1919
singleClusterMode: undefined | boolean;
2020
proxyMeta: undefined | boolean;
21+
useRelativePath: undefined | boolean;
2122
}
2223

2324
export class BaseYdbAPI extends AxiosWrapper {
2425
DEFAULT_RETRIES_COUNT = 0;
2526

2627
singleClusterMode: BaseAPIParams['singleClusterMode'];
28+
useRelativePath: BaseAPIParams['useRelativePath'];
2729

2830
constructor(axiosOptions: AxiosWrapperOptions, baseApiParams: BaseAPIParams) {
2931
super(axiosOptions);
3032

3133
this.singleClusterMode = baseApiParams.singleClusterMode;
34+
this.useRelativePath = baseApiParams.useRelativePath;
3235

3336
axiosRetry(this._axios, {
3437
retries: this.DEFAULT_RETRIES_COUNT,
@@ -91,8 +94,19 @@ export class BaseYdbAPI extends AxiosWrapper {
9194
return `${BACKEND ?? ''}${path}`;
9295
}
9396

94-
getSchemaPath(props: {path?: string; database?: string}) {
95-
return props.path;
97+
getSchemaPath({path, database}: {path?: string; database?: string}) {
98+
if (!this.useRelativePath || !path || !database) {
99+
return path;
100+
}
101+
102+
if (path === database) {
103+
return '';
104+
}
105+
106+
if (path.startsWith(database + '/')) {
107+
return path.slice(database.length + 1);
108+
}
109+
return path;
96110
}
97111

98112
prepareArrayRequestParam(arr: (string | number)[]) {

src/services/api/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ interface YdbEmbeddedAPIProps {
2323
withCredentials: undefined | boolean;
2424
singleClusterMode: undefined | boolean;
2525
proxyMeta: undefined | boolean;
26+
// this setting allows to use schema object path relative to database in api requests
27+
useRelativePath: undefined | boolean;
2628
csrfTokenGetter: undefined | (() => string | undefined);
2729
defaults: undefined | AxiosRequestConfig;
2830
}
@@ -48,9 +50,10 @@ export class YdbEmbeddedAPI {
4850
proxyMeta = false,
4951
csrfTokenGetter = () => undefined,
5052
defaults = {},
53+
useRelativePath = false,
5154
}: YdbEmbeddedAPIProps) {
5255
const axiosParams: AxiosWrapperOptions = {config: {withCredentials, ...defaults}};
53-
const baseApiParams = {singleClusterMode, proxyMeta};
56+
const baseApiParams = {singleClusterMode, proxyMeta, useRelativePath};
5457

5558
this.auth = new AuthAPI(axiosParams, baseApiParams);
5659
if (webVersion) {

src/services/api/scheme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class SchemeAPI extends BaseYdbAPI {
1010
{},
1111
{
1212
database,
13-
path,
13+
path: this.getSchemaPath({path, database}),
1414
},
1515
{
1616
requestConfig: {signal},

src/store/configureStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function configureStore({
6363
withCredentials: !customBackend,
6464
proxyMeta: false,
6565
csrfTokenGetter: undefined,
66+
useRelativePath: false,
6667
defaults: undefined,
6768
}),
6869
} = {}) {

0 commit comments

Comments
 (0)