Skip to content

Commit

Permalink
chore: remove strict validation of unknown fields in Request
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Sep 11, 2023
1 parent 08cceb5 commit 17a21a2
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/core/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import util from 'node:util';
import { normalizeUrl } from '@apify/utilities';
import type { Dictionary } from '@crawlee/types';
import type { BasePredicate } from 'ow';
import ow, { ArgumentError } from 'ow';
import ow from 'ow';

import { log as defaultLog } from './log';
import type { AllowedHttpMethods } from './typedefs';
Expand Down Expand Up @@ -35,11 +35,6 @@ const requestOptionalPredicates = {
state: ow.optional.number.greaterThanOrEqual(0).lessThanOrEqual(6),
};

const ignoredProperties = [
'lockByClient',
'lockExpiresAt',
];

export enum RequestState {
UNPROCESSED,
BEFORE_NAV,
Expand Down Expand Up @@ -146,14 +141,15 @@ export class Request<UserData extends Dictionary = Dictionary> {
// properties and speeds up the validation cca 3-fold.
// See https://github.com/sindresorhus/ow/issues/193
keys(options).forEach((prop) => {
// skip url, because it is validated above
if (prop === 'url') {
return;
}

const predicate = requestOptionalPredicates[prop as keyof typeof requestOptionalPredicates];
const value = options[prop];
if (predicate) {
ow(value, `RequestOptions.${prop}`, predicate as BasePredicate);
// 'url' is checked above because it's not optional, and lockExpiresAt is ignored
} else if (prop !== 'url' && !ignoredProperties.includes(prop)) {
const msg = `Did not expect property \`${prop}\` to exist, got \`${value}\` in object \`RequestOptions\``;
throw new ArgumentError(msg, this.constructor);
}
});

Expand Down

0 comments on commit 17a21a2

Please sign in to comment.