Skip to content

Commit

Permalink
#87: Fixed max page size header issue
Browse files Browse the repository at this point in the history
  • Loading branch information
darnjo committed Dec 14, 2023
1 parent d3c71e1 commit a01a704
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { findVariations, updateVariations, computeVariations, DEFAULT_FUZZINESS }
const { replicate } = require('./lib/replication');
const { convertMetadata, convertAndSaveMetadata } = require('./lib/metadata');
const { DEFAULT_DD_VERSION, parseBooleanValue } = require('./common');
const { DEFAULT_PAGE_SIZE } = require('./lib/replication/utils');

//Only load commander interpreter if running from the CLI
if (require?.main === module) {
Expand Down Expand Up @@ -62,11 +63,11 @@ if (require?.main === module) {
.option('-x, --expansions <items>', 'Comma-separated list of items to expand during the query process, e.g. Media,OpenHouse')
.option('-f, --filter <string>', 'OData $filter expression')
.option('-t, --top <number>', 'Optional parameter to use for OData $top')
.option('-m, --maxPageSize <number>', 'Optional parameter for the odata.maxpagesize header')
.option('-m, --maxPageSize <number>', 'Optional parameter for the odata.maxpagesize header', DEFAULT_PAGE_SIZE)
.option('-o, --outputPath <string>', 'Name of directory for results')
.option('-l, --limit <number>', 'Limit total number of records at client level')
.option('-v, --version <string>', 'Data Dictionary version to use', DEFAULT_DD_VERSION)
.option('-j, --jsonSchemaValidation <boolean>', 'Sets whether to use JSON schema validation', false)
.option('-j, --jsonSchemaValidation', 'Use JSON schema validation')
.option('-N, --originatingSystemName <string>', 'Used when additional filters are needed for OriginatingSystemName')
.option('-I, --originatingSystemId <string>', 'Used when additional filters are needed for OriginatingSystemID')
.option('-S, --strictMode <boolean>', 'Fail immediately on schema validation errors if strict mode is true', true)
Expand All @@ -82,6 +83,8 @@ if (require?.main === module) {
scope,
strictMode = true,
jsonSchemaValidation = false,
maxPageSize,
top,
...remainingOptions
} = options;

Expand All @@ -91,7 +94,9 @@ if (require?.main === module) {
shouldGenerateReports: !!pathToMetadataReportJson,
fromCli: FROM_CLI,
jsonSchemaValidation: parseBooleanValue(jsonSchemaValidation),
strictMode: parseBooleanValue(strictMode)
strictMode: parseBooleanValue(strictMode),
maxPageSize: parseInt(maxPageSize) ?? undefined,
top: parseInt(top) ?? undefined
};

if (bearerToken) {
Expand Down
2 changes: 2 additions & 0 deletions lib/replication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const replicate = async ({
clientCredentials = {},
outputPath,
limit,
maxPageSize,
resourceName,
expansions: expansionArrayOrCommaSeparatedString,
metadataReportJson = {},
Expand Down Expand Up @@ -165,6 +166,7 @@ const replicate = async ({
initialRequestUri,
strategy,
limit,
maxPageSize,
secondsDelayBetweenRequests,
authService
})) {
Expand Down
10 changes: 6 additions & 4 deletions lib/replication/replication-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ async function* replicationIterator({
strategy,
secondsDelayBetweenRequests,
authService,
timestampFieldName = DEFAULT_TIMESTAMP_FIELD
}) {
timestampFieldName = DEFAULT_TIMESTAMP_FIELD,
maxPageSize
} = {}) {

let pageSize = DEFAULT_PAGE_SIZE,
pagesFetched = 0,
numErrors = 0,
Expand All @@ -59,8 +61,8 @@ async function* replicationIterator({
lastIsoTimestamp = null,
nextLink = null;

if (strategy === REPLICATION_STRATEGIES.NEXT_LINK) {
headers[ODATA_PREFER_HEADER_NAME] = `${ODATA_MAX_PAGE_SIZE_HEADER_NAME}=${pageSize}`;
if (strategy === REPLICATION_STRATEGIES.NEXT_LINK && !!maxPageSize) {
headers[ODATA_PREFER_HEADER_NAME] = `${ODATA_MAX_PAGE_SIZE_HEADER_NAME}=${maxPageSize}`;
}

// wait once if specified
Expand Down
1 change: 1 addition & 0 deletions lib/replication/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ module.exports = {
REPLICATION_STRATEGIES,
DEFAULT_DD_VERSION,
DEFAULT_TIMESTAMP_FIELD,
DEFAULT_PAGE_SIZE,
computeLastIsoTimestamp,
scorePayload,
writeAnalyticsReports,
Expand Down

0 comments on commit a01a704

Please sign in to comment.