Skip to content

Commit

Permalink
Merge mrschmidt-validateuserinput
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Dec 28, 2018
1 parent 094ec19 commit 877b620
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,72 +1232,6 @@ follow these steps, YOUR APP MAY BREAK.`);
}
}

/**
* Validates a JavaScript object for usage as a Firestore document.
*
* @private
* @param obj JavaScript object to validate.
* @param options Validation options
* @returns 'true' when the object is valid.
* @throws when the object is invalid.
*/
function validateDocumentData(
obj: DocumentData, options: ValidationOptions): boolean {
if (!isPlainObject(obj)) {
throw customObjectError(obj);
}

options = options || {};

let isEmpty = true;

for (const prop in obj) {
if (obj.hasOwnProperty(prop)) {
isEmpty = false;
validateFieldValue(obj[prop], options, new FieldPath(prop));
}
}

if (options.allowEmpty === false && isEmpty) {
throw new Error('At least one field must be updated.');
}

return true;
}

/**
* Validates the use of 'options' as ReadOptions and enforces that 'fieldMask'
* is an array of strings or field paths.
*
* @private
* @param options.fieldMask - The subset of fields to return from a read
* operation.
*/
export function validateReadOptions(options: ReadOptions): boolean {
if (!is.object(options)) {
throw new Error('Input is not an object.');
}

if (options.fieldMask === undefined) {
return true;
}

if (!Array.isArray(options.fieldMask)) {
throw new Error('"fieldMask" is not an array.');
}

for (let i = 0; i < options.fieldMask.length; ++i) {
try {
FieldPath.validateFieldPath(options.fieldMask[i]);
} catch (err) {
throw new Error(
`Element at index ${i} is not a valid FieldPath. ${err.message}`);
}
}

return true;
}

/**
* A logging function that takes a single string.
*
Expand Down

0 comments on commit 877b620

Please sign in to comment.