mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-11 14:52:54 +01:00
feat: Add Support for Parse Server v7 (#20)
* feat: Upgrade Aggregate queries to latest Parse API * feat: Save parse server major version in metadata This can be used to determine which version of the Parse API that will be used. * fix: Add support for both versions of aggregate queries
This commit is contained in:
@@ -13,6 +13,7 @@ export default class SchemaHandler {
|
|||||||
public dbCollections: TSFixme[];
|
public dbCollections: TSFixme[];
|
||||||
public systemCollections: TSFixme[];
|
public systemCollections: TSFixme[];
|
||||||
public configSchema: TSFixme;
|
public configSchema: TSFixme;
|
||||||
|
public parseServerVersion: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
EventDispatcher.instance.on(
|
EventDispatcher.instance.on(
|
||||||
@@ -119,6 +120,20 @@ export default class SchemaHandler {
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Get Parse Server Version & Supported features
|
||||||
|
fetch(environment.url + '/serverInfo', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
"_method": "GET",
|
||||||
|
"_ApplicationId": environment.appId,
|
||||||
|
"_MasterKey": environment.masterKey,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((json) => {
|
||||||
|
this.parseServerVersion = json.parseServerVersion;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -129,10 +144,20 @@ export default class SchemaHandler {
|
|||||||
ProjectModel.instance.setMetaData('dbCollections', this.dbCollections);
|
ProjectModel.instance.setMetaData('dbCollections', this.dbCollections);
|
||||||
ProjectModel.instance.setMetaData('systemCollections', this.systemCollections);
|
ProjectModel.instance.setMetaData('systemCollections', this.systemCollections);
|
||||||
ProjectModel.instance.setMetaData('dbConfigSchema', this.configSchema);
|
ProjectModel.instance.setMetaData('dbConfigSchema', this.configSchema);
|
||||||
|
|
||||||
|
const versionNumbers = this.parseServerVersion?.split(".")
|
||||||
|
if (versionNumbers && versionNumbers.length > 0) {
|
||||||
|
// Let's only save the major version number,
|
||||||
|
// since this will be used to determine which verison of the API to use.
|
||||||
|
ProjectModel.instance.setMetaData('dbVersionMajor', versionNumbers[0]);
|
||||||
|
} else {
|
||||||
|
ProjectModel.instance.setMetaData('dbVersionMajor', undefined);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ProjectModel.instance.setMetaData('dbCollections', undefined);
|
ProjectModel.instance.setMetaData('dbCollections', undefined);
|
||||||
ProjectModel.instance.setMetaData('systemCollections', undefined);
|
ProjectModel.instance.setMetaData('systemCollections', undefined);
|
||||||
ProjectModel.instance.setMetaData('dbConfigSchema', undefined);
|
ProjectModel.instance.setMetaData('dbConfigSchema', undefined);
|
||||||
|
ProjectModel.instance.setMetaData('dbVersionMajor', undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,15 @@ class CloudStore {
|
|||||||
|
|
||||||
_initCloudServices() {
|
_initCloudServices() {
|
||||||
_collections = undefined; // clear collection cache, so it's refetched
|
_collections = undefined; // clear collection cache, so it's refetched
|
||||||
const cloudServices = NoodlRuntime.instance.getMetaData('cloudservices');
|
|
||||||
|
|
||||||
|
const cloudServices = NoodlRuntime.instance.getMetaData('cloudservices');
|
||||||
if (cloudServices) {
|
if (cloudServices) {
|
||||||
this.appId = cloudServices.appId;
|
this.appId = cloudServices.appId;
|
||||||
this.endpoint = cloudServices.endpoint;
|
this.endpoint = cloudServices.endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dbVersionMajor = NoodlRuntime.instance.getMetaData('dbVersionMajor');
|
||||||
|
this.dbVersionMajor = dbVersionMajor;
|
||||||
}
|
}
|
||||||
|
|
||||||
on() {
|
on() {
|
||||||
@@ -168,13 +171,10 @@ class CloudStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.where) args.push('match=' + encodeURIComponent(JSON.stringify(options.where)));
|
|
||||||
if (options.limit) args.push('limit=' + options.limit);
|
if (options.limit) args.push('limit=' + options.limit);
|
||||||
if (options.skip) args.push('skip=' + options.skip);
|
if (options.skip) args.push('skip=' + options.skip);
|
||||||
|
|
||||||
const grouping = {
|
const grouping = {};
|
||||||
objectId: null
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.keys(options.group).forEach((k) => {
|
Object.keys(options.group).forEach((k) => {
|
||||||
const _g = {};
|
const _g = {};
|
||||||
@@ -188,7 +188,20 @@ class CloudStore {
|
|||||||
grouping[k] = _g;
|
grouping[k] = _g;
|
||||||
});
|
});
|
||||||
|
|
||||||
args.push('group=' + JSON.stringify(grouping));
|
// I don't know which version the API was changed, lets just say above 4 for now.
|
||||||
|
if (this.dbVersionMajor && this.dbVersionMajor > 4) {
|
||||||
|
grouping._id = null;
|
||||||
|
|
||||||
|
if (options.where) args.push('$match=' + encodeURIComponent(JSON.stringify(options.where)));
|
||||||
|
|
||||||
|
args.push('$group=' + JSON.stringify(grouping));
|
||||||
|
} else {
|
||||||
|
grouping.objectId = null;
|
||||||
|
|
||||||
|
if (options.where) args.push('match=' + encodeURIComponent(JSON.stringify(options.where)));
|
||||||
|
|
||||||
|
args.push('group=' + JSON.stringify(grouping));
|
||||||
|
}
|
||||||
|
|
||||||
this._makeRequest('/aggregate/' + options.collection + (args.length > 0 ? '?' + args.join('&') : ''), {
|
this._makeRequest('/aggregate/' + options.collection + (args.length > 0 ? '?' + args.join('&') : ''), {
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
|
|||||||
Reference in New Issue
Block a user