Skip to content

Commit c8782d8

Browse files
authored
Merge branch 'alpha' into feat-disable-collation
2 parents d4d455e + 80b987d commit c8782d8

File tree

8 files changed

+239
-128
lines changed

8 files changed

+239
-128
lines changed

changelogs/CHANGELOG_alpha.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# [6.4.0-alpha.7](https://github.com/parse-community/parse-server/compare/6.4.0-alpha.6...6.4.0-alpha.7) (2023-10-25)
2+
3+
4+
### Features
5+
6+
* Add `$setOnInsert` operator to `Parse.Server.database.update` ([#8791](https://github.com/parse-community/parse-server/issues/8791)) ([f630a45](https://github.com/parse-community/parse-server/commit/f630a45aa5e87bc73a81fded061400c199b71a29))
7+
8+
# [6.4.0-alpha.6](https://github.com/parse-community/parse-server/compare/6.4.0-alpha.5...6.4.0-alpha.6) (2023-10-18)
9+
10+
11+
### Bug Fixes
12+
13+
* Security bump @babel/traverse from 7.20.5 to 7.23.2 ([#8777](https://github.com/parse-community/parse-server/issues/8777)) ([2d6b3d1](https://github.com/parse-community/parse-server/commit/2d6b3d18499179e99be116f25c0850d3f449509c))
14+
115
# [6.4.0-alpha.5](https://github.com/parse-community/parse-server/compare/6.4.0-alpha.4...6.4.0-alpha.5) (2023-10-14)
216

317

package-lock.json

Lines changed: 128 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse-server",
3-
"version": "6.4.0-alpha.5",
3+
"version": "6.4.0-alpha.7",
44
"description": "An express module providing a Parse-compatible API server",
55
"main": "lib/index.js",
66
"repository": {

spec/MongoStorageAdapter.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,61 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
254254
expect(obj.get('foo').test.date[0] instanceof Date).toBeTrue();
255255
});
256256

257+
it('upserts with $setOnInsert', async () => {
258+
const uuid = require('uuid');
259+
const uuid1 = uuid.v4();
260+
const uuid2 = uuid.v4();
261+
const schema = {
262+
className: 'MyClass',
263+
fields: {
264+
x: { type: 'Number' },
265+
count: { type: 'Number' },
266+
},
267+
classLevelPermissions: {},
268+
};
269+
270+
const myClassSchema = new Parse.Schema(schema.className);
271+
myClassSchema.setCLP(schema.classLevelPermissions);
272+
await myClassSchema.save();
273+
274+
const query = {
275+
x: 1,
276+
};
277+
const update = {
278+
objectId: {
279+
__op: 'SetOnInsert',
280+
amount: uuid1,
281+
},
282+
count: {
283+
__op: 'Increment',
284+
amount: 1,
285+
},
286+
};
287+
await Parse.Server.database.update(
288+
'MyClass',
289+
query,
290+
update,
291+
{ upsert: true },
292+
);
293+
update.objectId.amount = uuid2;
294+
await Parse.Server.database.update(
295+
'MyClass',
296+
query,
297+
update,
298+
{ upsert: true },
299+
);
300+
301+
const res = await Parse.Server.database.find(
302+
schema.className,
303+
{},
304+
{},
305+
);
306+
expect(res.length).toBe(1);
307+
expect(res[0].objectId).toBe(uuid1);
308+
expect(res[0].count).toBe(2);
309+
expect(res[0].x).toBe(1);
310+
});
311+
257312
it('handles updating a single object with array, object date', done => {
258313
const adapter = new MongoStorageAdapter({ uri: databaseURI });
259314

spec/ParseFile.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,34 @@ describe('Parse.File testing', () => {
14321432
}
14331433
});
14341434

1435+
it('allows file without extension', async () => {
1436+
await reconfigureServer({
1437+
fileUpload: {
1438+
enableForPublic: true,
1439+
fileExtensions: ['^[^hH][^tT][^mM][^lL]?$'],
1440+
},
1441+
});
1442+
const headers = {
1443+
'X-Parse-Application-Id': 'test',
1444+
'X-Parse-REST-API-Key': 'rest',
1445+
};
1446+
1447+
const values = ['filenamewithoutextension'];
1448+
1449+
for (const value of values) {
1450+
await expectAsync(
1451+
request({
1452+
method: 'POST',
1453+
headers: headers,
1454+
url: `http://localhost:8378/1/files/${value}`,
1455+
body: '<html></html>\n',
1456+
}).catch(e => {
1457+
throw new Error(e.data.error);
1458+
})
1459+
).toBeResolved();
1460+
}
1461+
});
1462+
14351463
it('works with array', async () => {
14361464
await reconfigureServer({
14371465
fileUpload: {

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,13 @@ function transformUpdateOperator({ __op, amount, objects }, flatten) {
986986
return { __op: '$inc', arg: amount };
987987
}
988988

989+
case 'SetOnInsert':
990+
if (flatten) {
991+
return amount;
992+
} else {
993+
return { __op: '$setOnInsert', arg: amount };
994+
}
995+
989996
case 'Add':
990997
case 'AddUnique':
991998
if (!(objects instanceof Array)) {

src/Controllers/DatabaseController.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ const flattenUpdateOperatorsForCreate = object => {
279279
}
280280
object[key] = object[key].amount;
281281
break;
282+
case 'SetOnInsert':
283+
object[key] = object[key].amount;
284+
break;
282285
case 'Add':
283286
if (!(object[key].objects instanceof Array)) {
284287
throw new Parse.Error(Parse.Error.INVALID_JSON, 'objects to add must be an array');
@@ -1832,7 +1835,7 @@ class DatabaseController {
18321835
keyUpdate &&
18331836
typeof keyUpdate === 'object' &&
18341837
keyUpdate.__op &&
1835-
['Add', 'AddUnique', 'Remove', 'Increment'].indexOf(keyUpdate.__op) > -1
1838+
['Add', 'AddUnique', 'Remove', 'Increment', 'SetOnInsert'].indexOf(keyUpdate.__op) > -1
18361839
) {
18371840
// only valid ops that produce an actionable result
18381841
// the op may have happened on a keypath

src/Routers/FilesRouter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ export class FilesRouter {
159159
} else if (contentType && contentType.includes('/')) {
160160
extension = contentType.split('/')[1];
161161
}
162-
extension = extension.split(' ').join('');
162+
extension = extension?.split(' ')?.join('');
163163

164-
if (!isValidExtension(extension)) {
164+
if (extension && !isValidExtension(extension)) {
165165
next(
166166
new Parse.Error(
167167
Parse.Error.FILE_SAVE_ERROR,

0 commit comments

Comments
 (0)