feat(runtime): Add "keys" and "excludeKeys" to fetch record api (#79)

Adding support for some more options when fetching a record.
91f9aca25b/src/Routers/ClassesRouter.js (L60-L68)
This commit is contained in:
Eric Tuvesson
2024-11-12 15:50:49 +01:00
committed by GitHub
parent fff03c05bf
commit 016837f466
4 changed files with 23 additions and 1 deletions

View File

@@ -263,7 +263,9 @@ class CloudStore {
* @param {{
* objectId: string;
* collection: string;
* keys?: string[] | string;
* include?: string[] | string;
* excludeKeys?: string[] | string;
* success: (data: unknown) => void;
* error: (error: unknown) => void;
* }} options
@@ -275,6 +277,16 @@ class CloudStore {
args.push('include=' + (Array.isArray(options.include) ? options.include.join(',') : options.include));
}
if (options.keys) {
args.push('keys=' + (Array.isArray(options.keys) ? options.keys.join(',') : options.keys));
}
if (options.excludeKeys) {
args.push(
'excludeKeys=' + (Array.isArray(options.excludeKeys) ? options.excludeKeys.join(',') : options.excludeKeys)
);
}
this._makeRequest(
'/classes/' + options.collection + '/' + options.objectId + (args.length > 0 ? '?' + args.join('&') : ''),
{

View File

@@ -112,7 +112,9 @@ function createRecordsAPI(modelScope) {
* @param {string | { getId(): string; }} objectOrId
* @param {{
* className: string;
* keys?: string[] | string;
* include?: string[] | string;
* excludeKeys?: string[] | string;
* }} options
* @returns {Promise<unknown>}
*/
@@ -129,7 +131,9 @@ function createRecordsAPI(modelScope) {
cloudstore().fetch({
collection: className,
objectId: objectOrId,
include: options ? options.include : undefined,
keys: options?.keys,
include: options?.include,
excludeKeys: options?.excludeKeys,
success: function (response) {
const record = cloudstore()._fromJSON(response, className);
resolve(record);

View File

@@ -227,6 +227,9 @@ declare namespace Noodl {
objectOrId: string | { getId(): string; },
options?: {
className?: RecordClassName;
keys?: string[] | string;
include?: string[] | string;
excludeKeys?: string[] | string;
}
): Promise<any>;

View File

@@ -274,6 +274,9 @@ declare namespace Noodl {
objectOrId: string | { getId(): string; },
options?: {
className?: RecordClassName;
keys?: string[] | string;
include?: string[] | string;
excludeKeys?: string[] | string;
}
): Promise<any>;