diff --git a/tdrive/backend/node/src/core/platform/framework/api/crud-service.ts b/tdrive/backend/node/src/core/platform/framework/api/crud-service.ts index de716d12..d9b7bad1 100644 --- a/tdrive/backend/node/src/core/platform/framework/api/crud-service.ts +++ b/tdrive/backend/node/src/core/platform/framework/api/crud-service.ts @@ -160,6 +160,17 @@ export class CrudException extends Error { } export interface Paginable { + /** + * In page token can be different type of data depending of the source. + * For ES it will be exactly page token, identifier of the next page. + * For PostgreSQL it will be number of the next page. + * For MongoDB it will be offset. + * This information is relevant for the Service/Repository level, in the controller + * we have only offset there for every type of source because in the "browse" controller + * we do not pass "next_page_token" to frontend and hence we are calculating + * offset on the frontend side and then passing offset to DocumentService. + * + */ page_token?: string; limitStr?: string; reversed?: boolean; diff --git a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/abstract-connector.ts b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/abstract-connector.ts index 51d703be..a8ba3555 100644 --- a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/abstract-connector.ts +++ b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/abstract-connector.ts @@ -3,7 +3,7 @@ import { Connector, UpsertOptions } from "."; import { ConnectionOptions, DatabaseType } from "../.."; import { FindOptions } from "../repository/repository"; import { ColumnDefinition, EntityDefinition } from "../types"; -import { ListResult } from "../../../../../framework/api/crud-service"; +import { ListResult, Paginable, Pagination } from "../../../../../framework/api/crud-service"; export abstract class AbstractConnector implements Connector { constructor(protected type: DatabaseType, protected options: T, protected secret: string) {} @@ -38,6 +38,8 @@ export abstract class AbstractConnector implements options: FindOptions, ): Promise>; + abstract getOffsetPagination(options: Paginable): Pagination; + getOptions(): T { return this.options; } diff --git a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/index.ts b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/index.ts index 3ef487e2..f1c6792e 100644 --- a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/index.ts +++ b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/index.ts @@ -3,7 +3,7 @@ import { DatabaseType } from "../.."; import { MongoConnectionOptions } from "./mongodb/mongodb"; import { ColumnDefinition, EntityDefinition } from "../types"; import { FindOptions } from "../repository/repository"; -import { ListResult } from "../../../../../framework/api/crud-service"; +import { ListResult, Paginable, Pagination } from "../../../../../framework/api/crud-service"; import { PostgresConnectionOptions } from "./postgres/postgres"; export * from "./mongodb/mongodb"; @@ -92,6 +92,13 @@ export interface Connector extends Initializable { filters: any, options: FindOptions, ): Promise>; + + /** + * Get the pagination for the given options where the pagination is offset based + * @param options Paginable + * @returns Pagination + */ + getOffsetPagination(options: Paginable): Pagination; } export declare type ConnectionOptions = MongoConnectionOptions | PostgresConnectionOptions; diff --git a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/mongodb/mongodb.ts b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/mongodb/mongodb.ts index 598f419c..7958110a 100644 --- a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/mongodb/mongodb.ts +++ b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/mongodb/mongodb.ts @@ -316,4 +316,9 @@ export class MongoConnector extends AbstractConnector { const nextPage: Paginable = new Pagination(nextToken, options.pagination.limitStr || "100"); return new ListResult(entityDefinition.type, entities, nextPage); } + + getOffsetPagination(options: Paginable): Pagination { + const { page_token, limitStr } = options; + return new Pagination(`${page_token}`, `${limitStr}`, options.reversed); + } } diff --git a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/postgres/postgres.ts b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/postgres/postgres.ts index aa29d4dd..696e8899 100644 --- a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/postgres/postgres.ts +++ b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/postgres/postgres.ts @@ -358,6 +358,12 @@ export class PostgresConnector extends AbstractConnector