Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/services/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)[]) {
Expand Down
5 changes: 4 additions & 1 deletion src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/api/scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class SchemeAPI extends BaseYdbAPI {
{},
{
database,
path,
path: this.getSchemaPath({path, database}),
},
{
requestConfig: {signal},
Expand Down
Loading