Prettier some files + opti object relation (#7044)
This commit is contained in:
@@ -44,9 +44,7 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
await expectMissingFile(encryptedAdapter, 'myFileName');
|
await expectMissingFile(encryptedAdapter, 'myFileName');
|
||||||
const originalString = 'abcdefghi';
|
const originalString = 'abcdefghi';
|
||||||
await encryptedAdapter.createFile('myFileName', originalString);
|
await encryptedAdapter.createFile('myFileName', originalString);
|
||||||
const unencryptedResult = await unencryptedAdapter.getFileData(
|
const unencryptedResult = await unencryptedAdapter.getFileData('myFileName');
|
||||||
'myFileName'
|
|
||||||
);
|
|
||||||
expect(unencryptedResult.toString('utf8')).not.toBe(originalString);
|
expect(unencryptedResult.toString('utf8')).not.toBe(originalString);
|
||||||
const encryptedResult = await encryptedAdapter.getFileData('myFileName');
|
const encryptedResult = await encryptedAdapter.getFileData('myFileName');
|
||||||
expect(encryptedResult.toString('utf8')).toBe(originalString);
|
expect(encryptedResult.toString('utf8')).toBe(originalString);
|
||||||
@@ -71,10 +69,7 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
const unencryptedResult2 = await unencryptedAdapter.getFileData(fileName2);
|
const unencryptedResult2 = await unencryptedAdapter.getFileData(fileName2);
|
||||||
expect(unencryptedResult2.toString('utf8')).toBe(data2);
|
expect(unencryptedResult2.toString('utf8')).toBe(data2);
|
||||||
//Check if encrypted adapter can read data and make sure it's not the same as unEncrypted adapter
|
//Check if encrypted adapter can read data and make sure it's not the same as unEncrypted adapter
|
||||||
const {
|
const { rotated, notRotated } = await encryptedAdapter.rotateEncryptionKey();
|
||||||
rotated,
|
|
||||||
notRotated,
|
|
||||||
} = await encryptedAdapter.rotateEncryptionKey();
|
|
||||||
expect(rotated.length).toEqual(2);
|
expect(rotated.length).toEqual(2);
|
||||||
expect(
|
expect(
|
||||||
rotated.filter(function (value) {
|
rotated.filter(function (value) {
|
||||||
@@ -101,30 +96,18 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
|
|
||||||
it('should rotate key of all old encrypted GridFS files to encrypted files', async () => {
|
it('should rotate key of all old encrypted GridFS files to encrypted files', async () => {
|
||||||
const oldEncryptionKey = 'oldKeyThatILoved';
|
const oldEncryptionKey = 'oldKeyThatILoved';
|
||||||
const oldEncryptedAdapter = new GridFSBucketAdapter(
|
const oldEncryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, oldEncryptionKey);
|
||||||
databaseURI,
|
const encryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, 'newKeyThatILove');
|
||||||
{},
|
|
||||||
oldEncryptionKey
|
|
||||||
);
|
|
||||||
const encryptedAdapter = new GridFSBucketAdapter(
|
|
||||||
databaseURI,
|
|
||||||
{},
|
|
||||||
'newKeyThatILove'
|
|
||||||
);
|
|
||||||
const fileName1 = 'file1.txt';
|
const fileName1 = 'file1.txt';
|
||||||
const data1 = 'hello world';
|
const data1 = 'hello world';
|
||||||
const fileName2 = 'file2.txt';
|
const fileName2 = 'file2.txt';
|
||||||
const data2 = 'hello new world';
|
const data2 = 'hello new world';
|
||||||
//Store unecrypted files
|
//Store unecrypted files
|
||||||
await oldEncryptedAdapter.createFile(fileName1, data1);
|
await oldEncryptedAdapter.createFile(fileName1, data1);
|
||||||
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(
|
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(fileName1);
|
||||||
fileName1
|
|
||||||
);
|
|
||||||
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
|
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
|
||||||
await oldEncryptedAdapter.createFile(fileName2, data2);
|
await oldEncryptedAdapter.createFile(fileName2, data2);
|
||||||
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(
|
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(fileName2);
|
||||||
fileName2
|
|
||||||
);
|
|
||||||
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
|
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
|
||||||
//Check if encrypted adapter can read data and make sure it's not the same as unEncrypted adapter
|
//Check if encrypted adapter can read data and make sure it's not the same as unEncrypted adapter
|
||||||
const { rotated, notRotated } = await encryptedAdapter.rotateEncryptionKey({
|
const { rotated, notRotated } = await encryptedAdapter.rotateEncryptionKey({
|
||||||
@@ -170,11 +153,7 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
|
|
||||||
it('should rotate key of all old encrypted GridFS files to unencrypted files', async () => {
|
it('should rotate key of all old encrypted GridFS files to unencrypted files', async () => {
|
||||||
const oldEncryptionKey = 'oldKeyThatILoved';
|
const oldEncryptionKey = 'oldKeyThatILoved';
|
||||||
const oldEncryptedAdapter = new GridFSBucketAdapter(
|
const oldEncryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, oldEncryptionKey);
|
||||||
databaseURI,
|
|
||||||
{},
|
|
||||||
oldEncryptionKey
|
|
||||||
);
|
|
||||||
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
|
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
|
||||||
const fileName1 = 'file1.txt';
|
const fileName1 = 'file1.txt';
|
||||||
const data1 = 'hello world';
|
const data1 = 'hello world';
|
||||||
@@ -182,20 +161,13 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
const data2 = 'hello new world';
|
const data2 = 'hello new world';
|
||||||
//Store unecrypted files
|
//Store unecrypted files
|
||||||
await oldEncryptedAdapter.createFile(fileName1, data1);
|
await oldEncryptedAdapter.createFile(fileName1, data1);
|
||||||
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(
|
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(fileName1);
|
||||||
fileName1
|
|
||||||
);
|
|
||||||
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
|
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
|
||||||
await oldEncryptedAdapter.createFile(fileName2, data2);
|
await oldEncryptedAdapter.createFile(fileName2, data2);
|
||||||
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(
|
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(fileName2);
|
||||||
fileName2
|
|
||||||
);
|
|
||||||
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
|
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
|
||||||
//Check if unEncrypted adapter can read data and make sure it's not the same as oldEncrypted adapter
|
//Check if unEncrypted adapter can read data and make sure it's not the same as oldEncrypted adapter
|
||||||
const {
|
const { rotated, notRotated } = await unEncryptedAdapter.rotateEncryptionKey({
|
||||||
rotated,
|
|
||||||
notRotated,
|
|
||||||
} = await unEncryptedAdapter.rotateEncryptionKey({
|
|
||||||
oldKey: oldEncryptionKey,
|
oldKey: oldEncryptionKey,
|
||||||
});
|
});
|
||||||
expect(rotated.length).toEqual(2);
|
expect(rotated.length).toEqual(2);
|
||||||
@@ -238,16 +210,8 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
|
|
||||||
it('should only encrypt specified fileNames', async () => {
|
it('should only encrypt specified fileNames', async () => {
|
||||||
const oldEncryptionKey = 'oldKeyThatILoved';
|
const oldEncryptionKey = 'oldKeyThatILoved';
|
||||||
const oldEncryptedAdapter = new GridFSBucketAdapter(
|
const oldEncryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, oldEncryptionKey);
|
||||||
databaseURI,
|
const encryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, 'newKeyThatILove');
|
||||||
{},
|
|
||||||
oldEncryptionKey
|
|
||||||
);
|
|
||||||
const encryptedAdapter = new GridFSBucketAdapter(
|
|
||||||
databaseURI,
|
|
||||||
{},
|
|
||||||
'newKeyThatILove'
|
|
||||||
);
|
|
||||||
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
|
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
|
||||||
const fileName1 = 'file1.txt';
|
const fileName1 = 'file1.txt';
|
||||||
const data1 = 'hello world';
|
const data1 = 'hello world';
|
||||||
@@ -255,14 +219,10 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
const data2 = 'hello new world';
|
const data2 = 'hello new world';
|
||||||
//Store unecrypted files
|
//Store unecrypted files
|
||||||
await oldEncryptedAdapter.createFile(fileName1, data1);
|
await oldEncryptedAdapter.createFile(fileName1, data1);
|
||||||
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(
|
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(fileName1);
|
||||||
fileName1
|
|
||||||
);
|
|
||||||
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
|
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
|
||||||
await oldEncryptedAdapter.createFile(fileName2, data2);
|
await oldEncryptedAdapter.createFile(fileName2, data2);
|
||||||
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(
|
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(fileName2);
|
||||||
fileName2
|
|
||||||
);
|
|
||||||
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
|
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
|
||||||
//Inject unecrypted file to see if causes an issue
|
//Inject unecrypted file to see if causes an issue
|
||||||
const fileName3 = 'file3.txt';
|
const fileName3 = 'file3.txt';
|
||||||
@@ -318,16 +278,8 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
|
|
||||||
it("should return fileNames of those it can't encrypt with the new key", async () => {
|
it("should return fileNames of those it can't encrypt with the new key", async () => {
|
||||||
const oldEncryptionKey = 'oldKeyThatILoved';
|
const oldEncryptionKey = 'oldKeyThatILoved';
|
||||||
const oldEncryptedAdapter = new GridFSBucketAdapter(
|
const oldEncryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, oldEncryptionKey);
|
||||||
databaseURI,
|
const encryptedAdapter = new GridFSBucketAdapter(databaseURI, {}, 'newKeyThatILove');
|
||||||
{},
|
|
||||||
oldEncryptionKey
|
|
||||||
);
|
|
||||||
const encryptedAdapter = new GridFSBucketAdapter(
|
|
||||||
databaseURI,
|
|
||||||
{},
|
|
||||||
'newKeyThatILove'
|
|
||||||
);
|
|
||||||
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
|
const unEncryptedAdapter = new GridFSBucketAdapter(databaseURI);
|
||||||
const fileName1 = 'file1.txt';
|
const fileName1 = 'file1.txt';
|
||||||
const data1 = 'hello world';
|
const data1 = 'hello world';
|
||||||
@@ -335,14 +287,10 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
|
|||||||
const data2 = 'hello new world';
|
const data2 = 'hello new world';
|
||||||
//Store unecrypted files
|
//Store unecrypted files
|
||||||
await oldEncryptedAdapter.createFile(fileName1, data1);
|
await oldEncryptedAdapter.createFile(fileName1, data1);
|
||||||
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(
|
const oldEncryptedResult1 = await oldEncryptedAdapter.getFileData(fileName1);
|
||||||
fileName1
|
|
||||||
);
|
|
||||||
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
|
expect(oldEncryptedResult1.toString('utf8')).toBe(data1);
|
||||||
await oldEncryptedAdapter.createFile(fileName2, data2);
|
await oldEncryptedAdapter.createFile(fileName2, data2);
|
||||||
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(
|
const oldEncryptedResult2 = await oldEncryptedAdapter.getFileData(fileName2);
|
||||||
fileName2
|
|
||||||
);
|
|
||||||
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
|
expect(oldEncryptedResult2.toString('utf8')).toBe(data2);
|
||||||
//Inject unecrypted file to see if causes an issue
|
//Inject unecrypted file to see if causes an issue
|
||||||
const fileName3 = 'file3.txt';
|
const fileName3 = 'file3.txt';
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ it('Should succeed with right credentials when LDAPS is used and certifcate is n
|
|||||||
suffix: 'o=example',
|
suffix: 'o=example',
|
||||||
url: `ldaps://localhost:${sslport}`,
|
url: `ldaps://localhost:${sslport}`,
|
||||||
dn: 'uid={{id}}, o=example',
|
dn: 'uid={{id}}, o=example',
|
||||||
tlsOptions: { rejectUnauthorized: false }
|
tlsOptions: { rejectUnauthorized: false },
|
||||||
};
|
};
|
||||||
ldap
|
ldap
|
||||||
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
|
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
|
||||||
@@ -57,8 +57,8 @@ it('Should succeed when LDAPS is used and the presented certificate is the expec
|
|||||||
dn: 'uid={{id}}, o=example',
|
dn: 'uid={{id}}, o=example',
|
||||||
tlsOptions: {
|
tlsOptions: {
|
||||||
ca: fs.readFileSync(__dirname + '/support/cert/cert.pem'),
|
ca: fs.readFileSync(__dirname + '/support/cert/cert.pem'),
|
||||||
rejectUnauthorized: true
|
rejectUnauthorized: true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
ldap
|
ldap
|
||||||
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
|
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
|
||||||
@@ -76,8 +76,8 @@ it('Should fail when LDAPS is used and the presented certificate is not the expe
|
|||||||
dn: 'uid={{id}}, o=example',
|
dn: 'uid={{id}}, o=example',
|
||||||
tlsOptions: {
|
tlsOptions: {
|
||||||
ca: fs.readFileSync(__dirname + '/support/cert/anothercert.pem'),
|
ca: fs.readFileSync(__dirname + '/support/cert/anothercert.pem'),
|
||||||
rejectUnauthorized: true
|
rejectUnauthorized: true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
ldap
|
ldap
|
||||||
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
|
.validateAuthData({ id: 'testuser', password: 'secret' }, options)
|
||||||
@@ -98,8 +98,8 @@ it('Should fail when LDAPS is used certifcate matches but credentials are wrong'
|
|||||||
dn: 'uid={{id}}, o=example',
|
dn: 'uid={{id}}, o=example',
|
||||||
tlsOptions: {
|
tlsOptions: {
|
||||||
ca: fs.readFileSync(__dirname + '/support/cert/cert.pem'),
|
ca: fs.readFileSync(__dirname + '/support/cert/cert.pem'),
|
||||||
rejectUnauthorized: true
|
rejectUnauthorized: true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
ldap
|
ldap
|
||||||
.validateAuthData({ id: 'testuser', password: 'wrong!' }, options)
|
.validateAuthData({ id: 'testuser', password: 'wrong!' }, options)
|
||||||
@@ -112,7 +112,6 @@ it('Should fail when LDAPS is used certifcate matches but credentials are wrong'
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Should fail with wrong credentials', done => {
|
it('Should fail with wrong credentials', done => {
|
||||||
mockLdapServer(port, 'uid=testuser, o=example').then(server => {
|
mockLdapServer(port, 'uid=testuser, o=example').then(server => {
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ const fs = require('fs');
|
|||||||
|
|
||||||
const tlsOptions = {
|
const tlsOptions = {
|
||||||
key: fs.readFileSync(__dirname + '/support/cert/key.pem'),
|
key: fs.readFileSync(__dirname + '/support/cert/key.pem'),
|
||||||
certificate: fs.readFileSync(__dirname + '/support/cert/cert.pem')
|
certificate: fs.readFileSync(__dirname + '/support/cert/cert.pem'),
|
||||||
}
|
};
|
||||||
|
|
||||||
function newServer(port, dn, provokeSearchError = false, ssl = false) {
|
function newServer(port, dn, provokeSearchError = false, ssl = false) {
|
||||||
const server = ssl ? ldapjs.createServer(tlsOptions) : ldapjs.createServer();
|
const server = ssl ? ldapjs.createServer(tlsOptions) : ldapjs.createServer();
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ const needToGetAllKeys = (fields, keys, parseClasses) =>
|
|||||||
? keys.split(',').some(keyName => {
|
? keys.split(',').some(keyName => {
|
||||||
const key = keyName.split('.');
|
const key = keyName.split('.');
|
||||||
if (fields[key[0]]) {
|
if (fields[key[0]]) {
|
||||||
|
if (fields[key[0]].type === 'Relation') return false;
|
||||||
if (fields[key[0]].type === 'Pointer') {
|
if (fields[key[0]].type === 'Pointer') {
|
||||||
const subClass = parseClasses.find(
|
const subClass = parseClasses.find(
|
||||||
({ className: parseClassName }) =>
|
({ className: parseClassName }) => fields[key[0]].targetClass === parseClassName
|
||||||
fields[key[0]].targetClass === parseClassName
|
|
||||||
);
|
);
|
||||||
if (subClass && subClass.fields[key[1]]) {
|
if (subClass && subClass.fields[key[1]]) {
|
||||||
// Current sub key is not custom
|
// Current sub key is not custom
|
||||||
@@ -50,9 +50,7 @@ const getObject = async (
|
|||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
!needToGetAllKeys(
|
!needToGetAllKeys(
|
||||||
parseClasses.find(
|
parseClasses.find(({ className: parseClassName }) => className === parseClassName).fields,
|
||||||
({ className: parseClassName }) => className === parseClassName
|
|
||||||
).fields,
|
|
||||||
keys,
|
keys,
|
||||||
parseClasses
|
parseClasses
|
||||||
)
|
)
|
||||||
@@ -141,15 +139,7 @@ const findObjects = async (
|
|||||||
preCountOptions.subqueryReadPreference = subqueryReadPreference;
|
preCountOptions.subqueryReadPreference = subqueryReadPreference;
|
||||||
}
|
}
|
||||||
preCount = (
|
preCount = (
|
||||||
await rest.find(
|
await rest.find(config, auth, className, where, preCountOptions, info.clientSDK, info.context)
|
||||||
config,
|
|
||||||
auth,
|
|
||||||
className,
|
|
||||||
where,
|
|
||||||
preCountOptions,
|
|
||||||
info.clientSDK,
|
|
||||||
info.context
|
|
||||||
)
|
|
||||||
).count;
|
).count;
|
||||||
if ((skip || 0) + limit < preCount) {
|
if ((skip || 0) + limit < preCount) {
|
||||||
skip = preCount - limit;
|
skip = preCount - limit;
|
||||||
@@ -158,11 +148,7 @@ const findObjects = async (
|
|||||||
|
|
||||||
const options = {};
|
const options = {};
|
||||||
|
|
||||||
if (
|
if (selectedFields.find(field => field.startsWith('edges.') || field.startsWith('pageInfo.'))) {
|
||||||
selectedFields.find(
|
|
||||||
field => field.startsWith('edges.') || field.startsWith('pageInfo.')
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
if (limit || limit === 0) {
|
if (limit || limit === 0) {
|
||||||
options.limit = limit;
|
options.limit = limit;
|
||||||
} else {
|
} else {
|
||||||
@@ -181,9 +167,7 @@ const findObjects = async (
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!needToGetAllKeys(
|
!needToGetAllKeys(
|
||||||
parseClasses.find(
|
parseClasses.find(({ className: parseClassName }) => className === parseClassName).fields,
|
||||||
({ className: parseClassName }) => className === parseClassName
|
|
||||||
).fields,
|
|
||||||
keys,
|
keys,
|
||||||
parseClasses
|
parseClasses
|
||||||
)
|
)
|
||||||
@@ -245,9 +229,7 @@ const findObjects = async (
|
|||||||
|
|
||||||
pageInfo = {
|
pageInfo = {
|
||||||
hasPreviousPage:
|
hasPreviousPage:
|
||||||
((preCount && preCount > 0) || (count && count > 0)) &&
|
((preCount && preCount > 0) || (count && count > 0)) && skip !== undefined && skip > 0,
|
||||||
skip !== undefined &&
|
|
||||||
skip > 0,
|
|
||||||
startCursor: offsetToCursor(skip || 0),
|
startCursor: offsetToCursor(skip || 0),
|
||||||
endCursor: offsetToCursor((skip || 0) + (results.length || 1) - 1),
|
endCursor: offsetToCursor((skip || 0) + (results.length || 1) - 1),
|
||||||
hasNextPage: (preCount || count) > (skip || 0) + results.length,
|
hasNextPage: (preCount || count) > (skip || 0) + results.length,
|
||||||
@@ -261,14 +243,7 @@ const findObjects = async (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const calculateSkipAndLimit = (
|
const calculateSkipAndLimit = (skipInput, first, after, last, before, maxLimit) => {
|
||||||
skipInput,
|
|
||||||
first,
|
|
||||||
after,
|
|
||||||
last,
|
|
||||||
before,
|
|
||||||
maxLimit
|
|
||||||
) => {
|
|
||||||
let skip = undefined;
|
let skip = undefined;
|
||||||
let limit = undefined;
|
let limit = undefined;
|
||||||
let needToPreCount = false;
|
let needToPreCount = false;
|
||||||
@@ -276,10 +251,7 @@ const calculateSkipAndLimit = (
|
|||||||
// Validates the skip input
|
// Validates the skip input
|
||||||
if (skipInput || skipInput === 0) {
|
if (skipInput || skipInput === 0) {
|
||||||
if (skipInput < 0) {
|
if (skipInput < 0) {
|
||||||
throw new Parse.Error(
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Skip should be a positive number');
|
||||||
Parse.Error.INVALID_QUERY,
|
|
||||||
'Skip should be a positive number'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
skip = skipInput;
|
skip = skipInput;
|
||||||
}
|
}
|
||||||
@@ -288,10 +260,7 @@ const calculateSkipAndLimit = (
|
|||||||
if (after) {
|
if (after) {
|
||||||
after = cursorToOffset(after);
|
after = cursorToOffset(after);
|
||||||
if ((!after && after !== 0) || after < 0) {
|
if ((!after && after !== 0) || after < 0) {
|
||||||
throw new Parse.Error(
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'After is not a valid cursor');
|
||||||
Parse.Error.INVALID_QUERY,
|
|
||||||
'After is not a valid cursor'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If skip and after are passed, a new skip is calculated by adding them
|
// If skip and after are passed, a new skip is calculated by adding them
|
||||||
@@ -301,10 +270,7 @@ const calculateSkipAndLimit = (
|
|||||||
// Validates the first param
|
// Validates the first param
|
||||||
if (first || first === 0) {
|
if (first || first === 0) {
|
||||||
if (first < 0) {
|
if (first < 0) {
|
||||||
throw new Parse.Error(
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'First should be a positive number');
|
||||||
Parse.Error.INVALID_QUERY,
|
|
||||||
'First should be a positive number'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The first param is translated to the limit param of the Parse legacy API
|
// The first param is translated to the limit param of the Parse legacy API
|
||||||
@@ -316,10 +282,7 @@ const calculateSkipAndLimit = (
|
|||||||
// This method converts the cursor to the index of the object
|
// This method converts the cursor to the index of the object
|
||||||
before = cursorToOffset(before);
|
before = cursorToOffset(before);
|
||||||
if ((!before && before !== 0) || before < 0) {
|
if ((!before && before !== 0) || before < 0) {
|
||||||
throw new Parse.Error(
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Before is not a valid cursor');
|
||||||
Parse.Error.INVALID_QUERY,
|
|
||||||
'Before is not a valid cursor'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((skip || 0) >= before) {
|
if ((skip || 0) >= before) {
|
||||||
@@ -334,10 +297,7 @@ const calculateSkipAndLimit = (
|
|||||||
// Validates the last param
|
// Validates the last param
|
||||||
if (last || last === 0) {
|
if (last || last === 0) {
|
||||||
if (last < 0) {
|
if (last < 0) {
|
||||||
throw new Parse.Error(
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Last should be a positive number');
|
||||||
Parse.Error.INVALID_QUERY,
|
|
||||||
'Last should be a positive number'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last > maxLimit) {
|
if (last > maxLimit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user