Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/alpha' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza committed Jul 8, 2024
2 parents a94c744 + c764203 commit 70f63f7
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 270 deletions.
14 changes: 14 additions & 0 deletions changelogs/CHANGELOG_alpha.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [7.1.0-alpha.15](https://github.com/parse-community/parse-server/compare/7.1.0-alpha.14...7.1.0-alpha.15) (2024-07-08)


### Features

* Upgrade to @parse/push-adapter 6.4.0 ([#9182](https://github.com/parse-community/parse-server/issues/9182)) ([ef1634b](https://github.com/parse-community/parse-server/commit/ef1634bf1f360429108d29b08032fc7961ff96a1))

# [7.1.0-alpha.14](https://github.com/parse-community/parse-server/compare/7.1.0-alpha.13...7.1.0-alpha.14) (2024-07-07)


### Features

* Upgrade to Parse JS SDK 5.3.0 ([#9180](https://github.com/parse-community/parse-server/issues/9180)) ([dca187f](https://github.com/parse-community/parse-server/commit/dca187f91b93cbb362b22a3fb9ee38451799ff13))

# [7.1.0-alpha.13](https://github.com/parse-community/parse-server/compare/7.1.0-alpha.12...7.1.0-alpha.13) (2024-07-01)


Expand Down
427 changes: 195 additions & 232 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parse-server",
"version": "7.1.0-alpha.13",
"version": "7.1.0-alpha.15",
"description": "An express module providing a Parse-compatible API server",
"main": "lib/index.js",
"repository": {
Expand All @@ -25,7 +25,7 @@
"@graphql-tools/schema": "10.0.3",
"@graphql-tools/utils": "8.12.0",
"@parse/fs-files-adapter": "3.0.0",
"@parse/push-adapter": "6.2.0",
"@parse/push-adapter": "6.4.0",
"bcryptjs": "2.4.3",
"body-parser": "1.20.2",
"commander": "12.0.0",
Expand All @@ -49,7 +49,7 @@
"mongodb": "5.9.0",
"mustache": "4.2.0",
"otpauth": "9.2.2",
"parse": "5.2.0",
"parse": "5.3.0",
"path-to-regexp": "6.2.1",
"pg-monitor": "2.0.0",
"pg-promise": "11.7.8",
Expand Down
7 changes: 3 additions & 4 deletions spec/AdapterLoader.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const loadAdapter = require('../lib/Adapters/AdapterLoader').loadAdapter;
const { loadAdapter, loadModule } = require('../lib/Adapters/AdapterLoader');
const FilesAdapter = require('@parse/fs-files-adapter').default;
const ParsePushAdapter = require('@parse/push-adapter').default;
const MockFilesAdapter = require('mock-files-adapter');
const Config = require('../lib/Config');

Expand Down Expand Up @@ -103,19 +102,19 @@ describe('AdapterLoader', () => {
done();
});

it('should load push adapter from options', done => {
it('should load push adapter from options', async () => {
const options = {
android: {
senderId: 'yolo',
apiKey: 'yolo',
},
};
const ParsePushAdapter = await loadModule('@parse/push-adapter');
expect(() => {
const adapter = loadAdapter(undefined, ParsePushAdapter, options);
expect(adapter.constructor).toBe(ParsePushAdapter);
expect(adapter).not.toBe(undefined);
}).not.toThrow();
done();
});

it('should load custom push adapter from string (#3544)', done => {
Expand Down
1 change: 1 addition & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ describe('Cloud Code', () => {
});

it('should not encode Parse Objects', async () => {
await reconfigureServer({ encodeParseObjectInCloudFunction: false });
const user = new Parse.User();
user.setUsername('username');
user.setPassword('password');
Expand Down
1 change: 1 addition & 0 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ describe('miscellaneous', function () {
});

it('test cloud function query parameters with array of pointers', async () => {
await reconfigureServer({ encodeParseObjectInCloudFunction: false });
Parse.Cloud.define('echoParams', req => {
return req.params;
});
Expand Down
38 changes: 38 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2055,4 +2055,42 @@ describe('Parse.Object testing', () => {
const object = new Parse.Object('CloudCodeIsNew');
await object.save();
});

it('returns correct field values', async () => {
const values = [
{ field: 'string', value: 'string' },
{ field: 'number', value: 1 },
{ field: 'boolean', value: true },
{ field: 'array', value: [0, 1, 2] },
{ field: 'array', value: [1, 2, 3] },
{ field: 'array', value: [{ '0': 'a' }, 2, 3] },
{ field: 'object', value: { key: 'value' } },
{ field: 'object', value: { key1: 'value1', key2: 'value2' } },
{ field: 'object', value: { key1: 1, key2: 2 } },
{ field: 'object', value: { '1x1': 1 } },
{ field: 'object', value: { '1x1': 1, '2': 2 } },
{ field: 'object', value: { '0': 0 } },
{ field: 'object', value: { '1': 1 } },
{ field: 'object', value: { '0': { '0': 'a', '1': 'b' } } },
{ field: 'date', value: new Date() },
{
field: 'file',
value: Parse.File.fromJSON({
__type: 'File',
name: 'name',
url: 'http://localhost:8378/1/files/test/name',
}),
},
{ field: 'geoPoint', value: new Parse.GeoPoint(40, -30) },
{ field: 'bytes', value: { __type: 'Bytes', base64: 'ZnJveW8=' } },
];
for (const value of values) {
const object = new TestObject();
object.set(value.field, value.value);
await object.save();
const query = new Parse.Query(TestObject);
const objectAgain = await query.get(object.id);
expect(objectAgain.get(value.field)).toEqual(value.value);
}
});
});
37 changes: 22 additions & 15 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ const defaultConfiguration = {
directAccess: true,
silent,
logLevel,
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
fileUpload: {
enableForPublic: true,
enableForAnonymousUser: true,
Expand All @@ -134,6 +138,7 @@ const defaultConfiguration = {
shortLivedAuth: mockShortLivedAuth(),
},
allowClientClassCreation: true,
encodeParseObjectInCloudFunction: true,
};

if (silent) {
Expand Down Expand Up @@ -162,15 +167,15 @@ const destroyAliveConnections = function () {
}
};
// Set up a default API server for testing with default configuration.
let server;

let parseServer;
let didChangeConfiguration = false;

// Allows testing specific configurations of Parse Server
const reconfigureServer = async (changedConfiguration = {}) => {
if (server) {
await new Promise(resolve => server.close(resolve));
server = undefined;
if (parseServer) {
destroyAliveConnections();
await new Promise(resolve => parseServer.server.close(resolve));
parseServer = undefined;
return reconfigureServer(changedConfiguration);
}
didChangeConfiguration = Object.keys(changedConfiguration).length !== 0;
Expand All @@ -179,14 +184,20 @@ const reconfigureServer = async (changedConfiguration = {}) => {
port,
});
cache.clear();
const parseServer = await ParseServer.startApp(newConfiguration);
server = parseServer.server;
parseServer = await ParseServer.startApp(newConfiguration);
Parse.CoreManager.setRESTController(RESTController);
parseServer.expressApp.use('/1', err => {
console.error(err);
fail('should not call next');
});
server.on('connection', connection => {
parseServer.liveQueryServer?.server?.on('connection', connection => {
const key = `${connection.remoteAddress}:${connection.remotePort}`;
openConnections[key] = connection;
connection.on('close', () => {
delete openConnections[key];
});
});
parseServer.server.on('connection', connection => {
const key = `${connection.remoteAddress}:${connection.remotePort}`;
openConnections[key] = connection;
connection.on('close', () => {
Expand Down Expand Up @@ -214,16 +225,12 @@ beforeAll(async () => {
Parse.serverURL = 'http://localhost:' + port + '/1';
});

beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
});

afterEach(function (done) {
const afterLogOut = async () => {
if (Object.keys(openConnections).length > 0) {
console.warn('There were open connections to the server left after the test finished');
// Jasmine process uses one connection
if (Object.keys(openConnections).length > 1) {
console.warn(`There were ${Object.keys(openConnections).length} open connections to the server left after the test finished`);
}
destroyAliveConnections();
await TestUtils.destroyAllDataPermanently(true);
SchemaCache.clear();
if (didChangeConfiguration) {
Expand Down
2 changes: 1 addition & 1 deletion spec/support/jasmine.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"spec_dir": "spec",
"spec_files": ["*spec.js"],
"helpers": ["helper.js"],
"random": true
"random": false
}
17 changes: 17 additions & 0 deletions src/Adapters/AdapterLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ export function loadAdapter<T>(adapter, defaultAdapter, options): T {
return adapter;
}

export async function loadModule(modulePath) {
let module;
try {
module = require(modulePath);
} catch (err) {
if (err.code === 'ERR_REQUIRE_ESM') {
module = await import(modulePath);
if (module.default) {
module = module.default;
}
} else {
throw err;
}
}
return module;
}

export default loadAdapter;
18 changes: 3 additions & 15 deletions src/Controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import authDataManager from '../Adapters/Auth';
import { ParseServerOptions } from '../Options';
import { loadAdapter } from '../Adapters/AdapterLoader';
import { loadAdapter, loadModule } from '../Adapters/AdapterLoader';
import defaults from '../defaults';
// Controllers
import { LoggerController } from './LoggerController';
Expand All @@ -22,21 +22,13 @@ import { InMemoryCacheAdapter } from '../Adapters/Cache/InMemoryCacheAdapter';
import { AnalyticsAdapter } from '../Adapters/Analytics/AnalyticsAdapter';
import MongoStorageAdapter from '../Adapters/Storage/Mongo/MongoStorageAdapter';
import PostgresStorageAdapter from '../Adapters/Storage/Postgres/PostgresStorageAdapter';
import ParsePushAdapter from '@parse/push-adapter';
import ParseGraphQLController from './ParseGraphQLController';
import SchemaCache from '../Adapters/Cache/SchemaCache';

export function getControllers(options: ParseServerOptions) {
const loggerController = getLoggerController(options);
const filesController = getFilesController(options);
const userController = getUserController(options);
const {
pushController,
hasPushScheduledSupport,
hasPushSupport,
pushControllerQueue,
pushWorker,
} = getPushController(options);
const cacheController = getCacheController(options);
const analyticsController = getAnalyticsController(options);
const liveQueryController = getLiveQueryController(options);
Expand All @@ -51,11 +43,6 @@ export function getControllers(options: ParseServerOptions) {
loggerController,
filesController,
userController,
pushController,
hasPushScheduledSupport,
hasPushSupport,
pushWorker,
pushControllerQueue,
analyticsController,
cacheController,
parseGraphQLController,
Expand Down Expand Up @@ -182,7 +169,7 @@ interface PushControlling {
pushWorker: PushWorker;
}

export function getPushController(options: ParseServerOptions): PushControlling {
export async function getPushController(options: ParseServerOptions): PushControlling {
const { scheduledPush, push } = options;

const pushOptions = Object.assign({}, push);
Expand All @@ -192,6 +179,7 @@ export function getPushController(options: ParseServerOptions): PushControlling
}

// Pass the push options too as it works with the default
const ParsePushAdapter = await loadModule('@parse/push-adapter');
const pushAdapter = loadAdapter(
pushOptions && pushOptions.adapter,
ParsePushAdapter,
Expand Down
2 changes: 2 additions & 0 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class ParseServer {
throw e;
}
}
const pushController = await controllers.getPushController(this.config);
await hooksController.load();
const startupPromises = [];
if (schema) {
Expand Down Expand Up @@ -196,6 +197,7 @@ class ParseServer {
new CheckRunner(security).run();
}
this.config.state = 'ok';
this.config = { ...this.config, ...pushController };
Config.put(this.config);
return this;
} catch (error) {
Expand Down

0 comments on commit 70f63f7

Please sign in to comment.