Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Asynchronous initialization of Parse Server #8232

Merged
merged 115 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
abe43a0
feat: Parse Server async initialization
dblythy Oct 14, 2022
0505f83
Update DefinedSchemas.js
dblythy Oct 14, 2022
b7e9d74
add state
dblythy Oct 14, 2022
3134010
Update index.spec.js
dblythy Oct 14, 2022
aefbeef
Update index.spec.js
dblythy Oct 14, 2022
81413a4
remove silent
dblythy Oct 14, 2022
b5965a5
fix tests
dblythy Oct 14, 2022
52d5c89
Update helper.js
dblythy Oct 14, 2022
12f7889
Update ParseServer.js
dblythy Oct 16, 2022
4284b8d
Update ParseServer.js
dblythy Oct 16, 2022
ac4ee2b
Update ParseServer.js
dblythy Oct 16, 2022
315bbf1
Update middlewares.js
dblythy Oct 16, 2022
2d27b7b
add state
dblythy Oct 16, 2022
1df0e7e
Merge branch 'alpha' into server-start
mtrezza Oct 23, 2022
d7eefa9
Merge branch 'alpha' into server-start
mtrezza Nov 2, 2022
4ba3d68
refactor
dblythy Nov 8, 2022
64f6eae
Update helper.js
dblythy Nov 8, 2022
c592345
Update helper.js
dblythy Nov 8, 2022
de2a4fd
Merge branch 'alpha' into server-start
dblythy Nov 8, 2022
25d1180
tests
dblythy Nov 8, 2022
72c7b56
prettier
dblythy Nov 8, 2022
73b0eb9
tests
dblythy Nov 8, 2022
fc2473b
tests
dblythy Nov 8, 2022
1e72a89
Update ParseServer.spec.js
dblythy Nov 8, 2022
69466b4
Update ParseServer.spec.js
dblythy Nov 8, 2022
b27f0ad
Update helper.js
dblythy Nov 8, 2022
48cb44f
failing server
dblythy Nov 8, 2022
f6331fc
refactor
dblythy Nov 8, 2022
59a4741
Merge branch 'alpha' into server-start
dblythy Nov 18, 2022
8dc3615
fix lint
dblythy Nov 18, 2022
89828ed
Update CLI.spec.js
dblythy Nov 18, 2022
7800b41
Update index.spec.js
dblythy Nov 18, 2022
84c0440
Update CLI.spec.js
dblythy Nov 19, 2022
c1cd6e0
Update CLI.spec.js
dblythy Nov 19, 2022
73391f1
tests
dblythy Nov 20, 2022
e033ff7
test
dblythy Nov 20, 2022
f2759e0
Update CLI.spec.js
dblythy Nov 20, 2022
72093ed
Update ParseServer.js
dblythy Nov 20, 2022
513ca5a
tests
dblythy Nov 20, 2022
f53dd45
Merge branch 'alpha' into server-start
dblythy Nov 20, 2022
cd4fa9b
Update CLI.spec.js
dblythy Nov 20, 2022
7f6c8df
Merge branch 'server-start' of https://github.com/dblythy/parse-serve…
dblythy Nov 20, 2022
6845970
test
dblythy Nov 20, 2022
e1cca15
test
dblythy Nov 20, 2022
0724733
test wip
dblythy Nov 20, 2022
95b96d8
fix
dblythy Nov 20, 2022
4d654a8
wip
dblythy Nov 20, 2022
dc56ccb
Update CLI.spec.js
dblythy Nov 20, 2022
3fe14f4
Update MongoStorageAdapter.js
dblythy Nov 20, 2022
c582da6
Update CLI.spec.js
dblythy Nov 20, 2022
9d1a67f
Update DatabaseController.js
dblythy Nov 20, 2022
2ac1a13
test
dblythy Nov 20, 2022
3b74aa4
wip
dblythy Nov 20, 2022
66798bf
Update CLI.spec.js
dblythy Nov 20, 2022
73e8f30
wip
dblythy Nov 20, 2022
536bc6f
Update CLI.spec.js
dblythy Nov 20, 2022
75e534d
Update CLI.spec.js
dblythy Nov 20, 2022
6341429
Update ParseServer.js
dblythy Nov 20, 2022
86cb20a
Update CLI.spec.js
dblythy Nov 20, 2022
acf77f9
Update CLI.spec.js
dblythy Nov 20, 2022
70ea8da
Update MongoStorageAdapter.js
dblythy Nov 20, 2022
2bad679
Update MongoStorageAdapter.js
dblythy Nov 20, 2022
4573cb1
Update MongoStorageAdapter.js
dblythy Nov 20, 2022
0535b25
Update MongoStorageAdapter.js
dblythy Nov 20, 2022
a4816a2
Update CLI.spec.js
dblythy Nov 20, 2022
4b76898
Update CLI.spec.js
dblythy Nov 20, 2022
c4967af
revert to spawn
dblythy Nov 20, 2022
7f20278
Update CLI.spec.js
dblythy Nov 20, 2022
53a8c4a
Update CLI.spec.js
dblythy Nov 20, 2022
e952c41
wip
dblythy Nov 20, 2022
9161f78
Update MongoStorageAdapter.js
dblythy Nov 20, 2022
85cee10
Update CLI.spec.js
dblythy Nov 21, 2022
148363a
revert
dblythy Nov 21, 2022
e665838
test
dblythy Nov 21, 2022
465a8ba
fix tests
dblythy Nov 21, 2022
273a532
Update index.js
dblythy Nov 21, 2022
a6ba538
Update CLI.spec.js
dblythy Nov 21, 2022
1a41153
Update CLI.spec.js
dblythy Nov 21, 2022
b307dad
Update index.spec.js
dblythy Nov 22, 2022
816b5e7
readme
dblythy Nov 22, 2022
fb5a835
add databaseURI
dblythy Nov 22, 2022
d5b4e8b
Merge branch 'alpha' into server-start
dblythy Nov 27, 2022
c002500
Update src/ParseServer.js
dblythy Nov 27, 2022
126e6a9
changes
dblythy Nov 27, 2022
0f83fdd
wip
dblythy Nov 27, 2022
7966601
lint
dblythy Nov 27, 2022
6546087
Update README.md
dblythy Nov 27, 2022
147966b
Update README.md
dblythy Nov 27, 2022
1ec6b51
push
dblythy Nov 27, 2022
8c5d223
Update README.md
dblythy Nov 27, 2022
26c87f9
Update README.md
dblythy Nov 27, 2022
5623ff4
Update README.md
dblythy Nov 27, 2022
4d30eda
add readme docs
mtrezza Nov 28, 2022
9641217
Update ParseServer.js
dblythy Nov 28, 2022
8bc8290
Update ParseServer.js
dblythy Nov 28, 2022
90cc616
Update ParseServer.js
dblythy Nov 28, 2022
f9adde8
test
dblythy Nov 28, 2022
0471e60
wip
dblythy Nov 28, 2022
c5bcc2b
wip
dblythy Nov 28, 2022
840e667
change
dblythy Nov 28, 2022
f8019db
wip
dblythy Nov 28, 2022
7d7a77a
module file
dblythy Nov 28, 2022
10ee837
Update ParseServer.js
dblythy Nov 28, 2022
b94de0e
Merge branch 'alpha' into server-start
mtrezza Dec 8, 2022
a3f481f
add migration guide
mtrezza Dec 8, 2022
1645b07
improve migration guide
mtrezza Dec 8, 2022
24d493e
fix migration guide typo
mtrezza Dec 8, 2022
fcde184
migration typo fix
mtrezza Dec 8, 2022
ef739db
Update 6.0.0.md
dblythy Dec 9, 2022
6de7d89
Update 6.0.0.md
mtrezza Dec 9, 2022
66286b2
add import statement to migration
mtrezza Dec 10, 2022
69e4b90
add retry
dblythy Dec 15, 2022
2740590
Merge branch 'alpha' into server-start
mtrezza Dec 16, 2022
91c4ccd
Merge branch 'alpha' into server-start
mtrezza Dec 20, 2022
f9b2eee
Merge branch 'alpha' into server-start
mtrezza Dec 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
["@babel/preset-env", {
"targets": {
"node": "12"
}
},
"exclude": ["proposal-dynamic-import"]
}]
],
"sourceMaps": "inline"
Expand Down
41 changes: 41 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const Config = require('../lib/Config');
const Parse = require('parse/node');
const ParseServer = require('../lib/index').ParseServer;
const request = require('../lib/request');
const InMemoryCacheAdapter = require('../lib/Adapters/Cache/InMemoryCacheAdapter')
.InMemoryCacheAdapter;
Expand Down Expand Up @@ -39,6 +40,46 @@ describe('Cloud Code', () => {
});
});

it('can load cloud code as a module', async () => {
process.env.npm_package_type = 'module';
await reconfigureServer({ cloud: './spec/cloud/cloudCodeModuleFile.js' });
const result = await Parse.Cloud.run('cloudCodeInFile');
expect(result).toEqual('It is possible to define cloud code in a file.');
delete process.env.npm_package_type;
});

it('cloud code must be valid type', async () => {
await expectAsync(reconfigureServer({ cloud: true })).toBeRejectedWith(
"argument 'cloud' must either be a string or a function"
);
});

it('should wait for cloud code to load', async () => {
const initiated = new Date();
const parseServer = await new ParseServer({
appId: 'test2',
masterKey: 'abc',
serverURL: 'http://localhost:12668/parse',
async cloud() {
await new Promise(resolve => setTimeout(resolve, 1000));
Parse.Cloud.beforeSave('Test', () => {
throw 'Cannot save.';
});
},
}).start();
const express = require('express');
const app = express();
app.use('/parse', parseServer);
const server = app.listen(12668);

const now = new Date();
expect(now.getTime() - initiated.getTime() > 1000).toBeTrue();
await expectAsync(new Parse.Object('Test').save()).toBeRejectedWith(
new Parse.Error(141, 'Cannot save.')
);
await new Promise(resolve => server.close(resolve));
});

it('can create functions', done => {
Parse.Cloud.define('hello', () => {
return 'Hello world!';
Expand Down
2 changes: 1 addition & 1 deletion spec/DefinedSchemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ describe('DefinedSchemas', () => {
const logger = require('../lib/logger').logger;
spyOn(DefinedSchemas.prototype, 'wait').and.resolveTo();
spyOn(logger, 'error').and.callThrough();
spyOn(Parse.Schema, 'all').and.callFake(() => {
spyOn(DefinedSchemas.prototype, 'createDeleteSession').and.callFake(() => {
throw error;
});

Expand Down
32 changes: 10 additions & 22 deletions spec/ParseLiveQueryServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ describe('ParseLiveQueryServer', function () {
});

describe_only_db('mongo')('initialization', () => {
it('can be initialized through ParseServer without liveQueryServerOptions', function (done) {
const parseServer = ParseServer.start({
it('can be initialized through ParseServer without liveQueryServerOptions', async () => {
const parseServer = await ParseServer.start({
appId: 'hello',
masterKey: 'world',
port: 22345,
Expand All @@ -126,19 +126,14 @@ describe('ParseLiveQueryServer', function () {
classNames: ['Yolo'],
},
startLiveQueryServer: true,
serverStartComplete: () => {
expect(parseServer.liveQueryServer).not.toBeUndefined();
expect(parseServer.liveQueryServer.server).toBe(parseServer.server);
parseServer.server.close(async () => {
await reconfigureServer();
done();
});
},
});
expect(parseServer.liveQueryServer).not.toBeUndefined();
expect(parseServer.liveQueryServer.server).toBe(parseServer.server);
await new Promise(resolve => parseServer.server.close(resolve));
});

it('can be initialized through ParseServer with liveQueryServerOptions', function (done) {
const parseServer = ParseServer.start({
it('can be initialized through ParseServer with liveQueryServerOptions', async () => {
const parseServer = await ParseServer.start({
appId: 'hello',
masterKey: 'world',
port: 22346,
Expand All @@ -150,17 +145,10 @@ describe('ParseLiveQueryServer', function () {
liveQueryServerOptions: {
port: 22347,
},
serverStartComplete: () => {
expect(parseServer.liveQueryServer).not.toBeUndefined();
expect(parseServer.liveQueryServer.server).not.toBe(parseServer.server);
parseServer.liveQueryServer.server.close(
parseServer.server.close.bind(parseServer.server, async () => {
await reconfigureServer();
done();
})
);
},
});
expect(parseServer.liveQueryServer).not.toBeUndefined();
expect(parseServer.liveQueryServer.server).not.toBe(parseServer.server);
await new Promise(resolve => parseServer.server.close(resolve));
});
});

Expand Down
3 changes: 3 additions & 0 deletions spec/cloud/cloudCodeModuleFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Parse.Cloud.define('cloudCodeInFile', () => {
return 'It is possible to define cloud code in a file.';
});
70 changes: 30 additions & 40 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,47 +148,37 @@ let server;
let didChangeConfiguration = false;

// Allows testing specific configurations of Parse Server
const reconfigureServer = (changedConfiguration = {}) => {
return new Promise((resolve, reject) => {
if (server) {
return server.close(() => {
server = undefined;
reconfigureServer(changedConfiguration).then(resolve, reject);
});
}
try {
let parseServer = undefined;
didChangeConfiguration = Object.keys(changedConfiguration).length !== 0;
const newConfiguration = Object.assign({}, defaultConfiguration, changedConfiguration, {
serverStartComplete: error => {
if (error) {
reject(error);
} else {
Parse.CoreManager.setRESTController(RESTController);
resolve(parseServer);
}
},
mountPath: '/1',
port,
});
cache.clear();
parseServer = ParseServer.start(newConfiguration);
parseServer.expressApp.use('/1', err => {
console.error(err);
fail('should not call next');
});
server = parseServer.server;
server.on('connection', connection => {
const key = `${connection.remoteAddress}:${connection.remotePort}`;
openConnections[key] = connection;
connection.on('close', () => {
delete openConnections[key];
});
});
} catch (error) {
reject(error);
}
const reconfigureServer = async (changedConfiguration = {}) => {
if (server) {
await new Promise(resolve => server.close(resolve));
server = undefined;
return reconfigureServer(changedConfiguration);
}
didChangeConfiguration = Object.keys(changedConfiguration).length !== 0;
const newConfiguration = Object.assign({}, defaultConfiguration, changedConfiguration, {
mountPath: '/1',
port,
});
cache.clear();
const { parseServer, error } = await ParseServer.start(newConfiguration);
server = parseServer.server;
if (error) {
throw error;
}

Parse.CoreManager.setRESTController(RESTController);
parseServer.expressApp.use('/1', err => {
console.error(err);
fail('should not call next');
});
server.on('connection', connection => {
const key = `${connection.remoteAddress}:${connection.remotePort}`;
openConnections[key] = connection;
connection.on('close', () => {
delete openConnections[key];
});
});
return parseServer;
};

// Set up a Parse client to talk to our test API server
Expand Down
Loading