Make the server proxy's properties visible to static analysis (#5345)

Currently, all properties of the server proxy object are created using
`Object.defineProperties` in the constructor, which means that IDEs like
VS Code can't analyze the file's static structure to determine what
properties there are and what types they have. Consequently, things like
autocomplete and go-to-definition don't work.

Fix that by removing the `ServerProxy` class altogether and exporting an
anonymous object with all properties defined statically.
main
Roman Donchenko 3 years ago committed by GitHub
parent 968b575ac3
commit 85b5547541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -205,8 +205,6 @@ class WorkerWrappedAxios {
} }
} }
class ServerProxy {
constructor() {
Axios.defaults.withCredentials = true; Axios.defaults.withCredentials = true;
Axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN'; Axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN';
Axios.defaults.xsrfCookieName = 'csrftoken'; Axios.defaults.xsrfCookieName = 'csrftoken';
@ -2216,11 +2214,8 @@ class ServerProxy {
} }
} }
Object.defineProperties( export default Object.freeze({
this, server: Object.freeze({
Object.freeze({
server: {
value: Object.freeze({
about, about,
share, share,
formats, formats,
@ -2237,11 +2232,8 @@ class ServerProxy {
userAgreements, userAgreements,
installedApps, installedApps,
}), }),
writable: false,
},
projects: { projects: Object.freeze({
value: Object.freeze({
get: getProjects, get: getProjects,
searchNames: searchProjectNames, searchNames: searchProjectNames,
save: saveProject, save: saveProject,
@ -2252,11 +2244,8 @@ class ServerProxy {
restore: restoreProject, restore: restoreProject,
importDataset, importDataset,
}), }),
writable: false,
},
tasks: { tasks: Object.freeze({
value: Object.freeze({
get: getTasks, get: getTasks,
save: saveTask, save: saveTask,
create: createTask, create: createTask,
@ -2265,56 +2254,38 @@ class ServerProxy {
backup: backupTask, backup: backupTask,
restore: restoreTask, restore: restoreTask,
}), }),
writable: false,
},
jobs: { jobs: Object.freeze({
value: Object.freeze({
get: getJobs, get: getJobs,
save: saveJob, save: saveJob,
exportDataset: exportDataset('jobs'), exportDataset: exportDataset('jobs'),
}), }),
writable: false,
},
users: { users: Object.freeze({
value: Object.freeze({
get: getUsers, get: getUsers,
self: getSelf, self: getSelf,
}), }),
writable: false,
},
frames: { frames: Object.freeze({
value: Object.freeze({
getData, getData,
getMeta, getMeta,
saveMeta, saveMeta,
getPreview, getPreview,
getImageContext, getImageContext,
}), }),
writable: false,
},
annotations: { annotations: Object.freeze({
value: Object.freeze({
updateAnnotations, updateAnnotations,
getAnnotations, getAnnotations,
dumpAnnotations, dumpAnnotations,
uploadAnnotations, uploadAnnotations,
}), }),
writable: false,
},
logs: { logs: Object.freeze({
value: Object.freeze({
save: saveLogs, save: saveLogs,
}), }),
writable: false,
},
lambda: { lambda: Object.freeze({
value: Object.freeze({
list: getLambdaFunctions, list: getLambdaFunctions,
status: getRequestStatus, status: getRequestStatus,
requests: getLambdaRequests, requests: getLambdaRequests,
@ -2322,36 +2293,24 @@ class ServerProxy {
call: callLambdaFunction, call: callLambdaFunction,
cancel: cancelLambdaRequest, cancel: cancelLambdaRequest,
}), }),
writable: false,
},
issues: { issues: Object.freeze({
value: Object.freeze({
create: createIssue, create: createIssue,
update: updateIssue, update: updateIssue,
get: getJobIssues, get: getJobIssues,
delete: deleteIssue, delete: deleteIssue,
}), }),
writable: false,
},
comments: { comments: Object.freeze({
value: Object.freeze({
create: createComment, create: createComment,
}), }),
writable: false,
},
predictor: { predictor: Object.freeze({
value: Object.freeze({
status: predictorStatus, status: predictorStatus,
predict: predictAnnotations, predict: predictAnnotations,
}), }),
writable: false,
},
cloudStorages: { cloudStorages: Object.freeze({
value: Object.freeze({
get: getCloudStorages, get: getCloudStorages,
getContent: getCloudStorageContent, getContent: getCloudStorageContent,
getPreview: getCloudStoragePreview, getPreview: getCloudStoragePreview,
@ -2360,11 +2319,8 @@ class ServerProxy {
delete: deleteCloudStorage, delete: deleteCloudStorage,
update: updateCloudStorage, update: updateCloudStorage,
}), }),
writable: false,
},
organizations: { organizations: Object.freeze({
value: Object.freeze({
get: getOrganizations, get: getOrganizations,
create: createOrganization, create: createOrganization,
update: updateOrganization, update: updateOrganization,
@ -2375,11 +2331,8 @@ class ServerProxy {
updateMembership: updateOrganizationMembership, updateMembership: updateOrganizationMembership,
deleteMembership: deleteOrganizationMembership, deleteMembership: deleteOrganizationMembership,
}), }),
writable: false,
},
webhooks: { webhooks: Object.freeze({
value: Object.freeze({
get: getWebhooks, get: getWebhooks,
create: createWebhook, create: createWebhook,
update: updateWebhook, update: updateWebhook,
@ -2387,12 +2340,4 @@ class ServerProxy {
ping: pingWebhook, ping: pingWebhook,
events: receiveWebhookEvents, events: receiveWebhookEvents,
}), }),
writable: false, });
},
}),
);
}
}
const serverProxy = new ServerProxy();
export default serverProxy;

Loading…
Cancel
Save