UNPKG

@vulcan-sql/build

Version:

VulcanSQL package for building projects

47 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtractPaginationParams = void 0; const tslib_1 = require("tslib"); const core_1 = require("@vulcan-sql/core"); const middleware_1 = require("./middleware"); class ExtractPaginationParams extends middleware_1.SchemaParserMiddleware { handle(schemas, next) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { yield next(); const transformedSchemas = schemas; const paginationParameters = []; if (((_a = transformedSchemas.pagination) === null || _a === void 0 ? void 0 : _a.mode) === core_1.PaginationMode.OFFSET) { paginationParameters.push({ fieldName: 'limit', fieldIn: core_1.FieldInType.QUERY, description: 'Offset-based Pagination: The maximum number of rows to return. default: 20', type: core_1.FieldDataType.STRING, validators: [{ name: 'integer', args: { min: 0 } }], constraints: [], }); paginationParameters.push({ fieldName: 'offset', fieldIn: core_1.FieldInType.QUERY, description: 'Offset-based Pagination: The offset from the row. default: 0', type: core_1.FieldDataType.STRING, validators: [{ name: 'integer', args: { min: 0 } }], constraints: [], }); } // merge parameters for (const param of paginationParameters) { const existed = transformedSchemas.request.find((req) => req.fieldName === param.fieldName && req.fieldIn === param.fieldIn); if (existed) { existed.description = existed.description || param.description; existed.validators = [...existed.validators, ...param.validators]; } else { transformedSchemas.request.push(param); } } }); } } exports.ExtractPaginationParams = ExtractPaginationParams; //# sourceMappingURL=extractPaginationParams.js.map