Skip to content

Commit

Permalink
feat: Add Support for Parse Server v7 (noodlapp#20)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
erictuvesson authored and Richard Osborne committed Aug 14, 2024
1 parent 297022e commit f178d1c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
25 changes: 25 additions & 0 deletions packages/noodl-editor/src/editor/src/utils/schemahandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class SchemaHandler {
public dbCollections: TSFixme[];
public systemCollections: TSFixme[];
public configSchema: TSFixme;
public parseServerVersion: string;

constructor() {
EventDispatcher.instance.on(
Expand Down Expand Up @@ -119,6 +120,20 @@ export default class SchemaHandler {
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;
});
});
});
}
Expand All @@ -129,10 +144,20 @@ export default class SchemaHandler {
ProjectModel.instance.setMetaData('dbCollections', this.dbCollections);
ProjectModel.instance.setMetaData('systemCollections', this.systemCollections);
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 {
ProjectModel.instance.setMetaData('dbCollections', undefined);
ProjectModel.instance.setMetaData('systemCollections', undefined);
ProjectModel.instance.setMetaData('dbConfigSchema', undefined);
ProjectModel.instance.setMetaData('dbVersionMajor', undefined);
}
}
}
Expand Down
25 changes: 19 additions & 6 deletions packages/noodl-runtime/src/api/cloudstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ class CloudStore {

_initCloudServices() {
_collections = undefined; // clear collection cache, so it's refetched
const cloudServices = NoodlRuntime.instance.getMetaData('cloudservices');

const cloudServices = NoodlRuntime.instance.getMetaData('cloudservices');
if (cloudServices) {
this.appId = cloudServices.appId;
this.endpoint = cloudServices.endpoint;
}

const dbVersionMajor = NoodlRuntime.instance.getMetaData('dbVersionMajor');
this.dbVersionMajor = dbVersionMajor;
}

on() {
Expand Down Expand Up @@ -168,13 +171,10 @@ class CloudStore {
return;
}

if (options.where) args.push('match=' + encodeURIComponent(JSON.stringify(options.where)));
if (options.limit) args.push('limit=' + options.limit);
if (options.skip) args.push('skip=' + options.skip);

const grouping = {
objectId: null
};
const grouping = {};

Object.keys(options.group).forEach((k) => {
const _g = {};
Expand All @@ -188,7 +188,20 @@ class CloudStore {
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('&') : ''), {
success: function (response) {
Expand Down

0 comments on commit f178d1c

Please sign in to comment.