UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

704 lines (703 loc) 18.8 kB
import { removeTrailingUndefinedElements as o } from "../utils/functions/ArrayUtils.js"; import { parseEntityIdFromSqlStatement as h } from "../utils/functions/SqlFunctions.js"; import { hashCode as c, normalizeNumericId as K } from "../utils/functions/StringUtils.js"; import { USER_BUNDLE_MASK_IS_AR_REVIEWER as Q, USER_BUNDLE_MASK_IS_ACT_MEMBER as d, USER_BUNDLE_MASK_IS_VERIFIED as m, USER_BUNDLE_MASK_IS_CERTIFIED as A, USER_BUNDLE_MASK_VERIFICATION_SUBMISSION as b, USER_BUNDLE_MASK_ORCID as S, USER_BUNDLE_MASK_USER_PROFILE as p } from "../utils/SynapseConstants.js"; import "../synapse-client/SynapseClient.js"; import "@sage-bionetworks/synapse-client/generated/models/ErrorResponseCode"; import "@sage-bionetworks/synapse-client/generated/models/TwoFactorAuthErrorResponse"; import "@sage-bionetworks/synapse-client/util/SynapseClientError"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "lodash-es"; const r = { /* Query key for all entities */ all: { objectType: "entity" }, // Data for an entity entity: (s, e) => { const t = { ...r.all, id: s }; return e && (t.version = e), t; }, // List of Entity Versions versions: (s) => [r.entity(s), "versions"], versionsQuery: (s, e, t) => [ ...r.versions(s), { limit: e, offset: t } ], // JSON Representation of an entity json: (s, e) => [ r.entity(s, e), "json" ], // actions required for all entities allActionsRequired: () => [r.all, "actionsRequired"], // entity actions required actionsRequired: (s) => [ r.entity(s), "actionsRequired" ], entityForum: (s) => [ r.entity(s), "entityForum" ], entityChallenge: (s) => [ r.entity(s), "entityChallenge" ], activity: (s, e) => [ r.entity(s, e), "activity" ], // Entity path path: (s) => [r.entity(s), "path"], // Entity bundle bundle: (s, e, t) => [ r.entity(s, e), "entityBundle", t ], children: (s, e) => [ r.entity(s.parentId ?? "root"), "children", { isInfinite: e, entityChildrenRequest: s } ], tableQueryResult: (s, e) => [ r.entity(s.entityId), { type: "tableQueryResult" }, { isInfinite: e, tableQueryBundleRequest: s } ], tableQueryResultWithAsyncStatus: (s, e) => [ r.entity(s.entityId), { type: "tableQueryResult", withAsyncStatus: !0 }, { isInfinite: e, tableQueryBundleRequest: s } ], fullTableQueryResult: (s) => [ r.entity(s.entityId), { type: "tableQueryResult", allResults: !0 }, { tableQueryBundleRequest: s } ], boundJSONSchema: (s) => [ r.entity(s), "boundJSONSchema" ], schemaValidationResults: (s) => [ r.entity(s), "schemaValidationResults" ], header: (s, e) => [ r.entity(s, e), "entityHeaders" ], headers: (s) => [ r.all, "entityHeaders", s ], accessRequirements: (s) => [ r.entity(s), "accessRequirements" ] }, n = { /* Key used to invalidate all download list queries */ base: "downloadList", availableFiles: (s) => [ n.base, "availableFiles", s ], availableFilesInfinite: (s) => [ ...n.availableFiles(s), "infinite" ], getActionsRequired: () => [n.base, "actionsRequired"], getActionsRequiredInfinite: () => [ ...n.getActionsRequired(), "infinite" ], getStatistics: () => [n.base, "statistics"] }, y = "accessRequirement", R = "rootWikiPageKey", l = "wikiPage", g = "dataAccessSubmission"; class D { accessToken = void 0; constructor(e) { this.accessToken = e; } /** * Returns a react-query Query Key. Prepends the key with the access token, so that the key is unique per-session. * Also removes trailing undefined elements from the passed args, so a key can be generated for query invalidation. * @param args * @private */ getKey(...e) { return [ this.accessToken == null ? "anonymous" : btoa(String(c(this.accessToken))), ...o(e) ]; } getKeyAnonymous(...e) { return ["anonymous", ...o(e)]; } getFeatureFlagQueryKey() { return this.getKey("featureflag"); } getAllEntityDataQueryKey() { return this.getKey(r.all); } getEntityQueryKey(e) { return this.getKey(r.entity(e)); } getEntityActivityQueryKey(e, t) { return this.getKey(...r.activity(e, t)); } getAllEntityActionsRequiredQueryKey() { return this.getKey(...r.allActionsRequired()); } getEntityActionsRequiredQueryKey(e) { return this.getKey(...r.actionsRequired(e)); } getEntityChallengeQueryKey(e) { return this.getKey(...r.entityChallenge(e)); } getForumQueryKey(e) { return this.getKey(...r.entityForum(e)); } getEntityVersionQueryKey(e, t) { return this.getKey(r.entity(e, t)); } getEntityLookupQueryKey(e) { return this.getKey( r.all, "entityLookup", e ); } getPaginatedEntityVersionsQueryKey(e, t, i) { return this.getKey( ...r.versionsQuery(e, t, i) ); } getEntityVersionsQueryKey(e) { return this.getKey(...r.versions(e)); } getEntityChildrenQueryKey(e, t) { return this.getKey(...r.children(e, t)); } getEntityJsonQueryKey(e, t, i) { return this.getKey(...r.json(e, t), { includeDerivedAnnotations: i }); } getEntityBundleQueryKey(e, t, i) { return this.getKey( ...r.bundle(e, t, i) ); } getEntityPathQueryKey(e) { return this.getKey(...r.path(e)); } getEntityACLQueryKey(e) { return this.getKey(r.entity(e), "acl"); } getEntityAliasQueryKey(e) { return this.getKey(r.all, "alias", e); } getEntityEvaluationsQueryKey(e) { return this.getKey(r.entity(e), "evaluations"); } getEntityPermissionsQueryKey(e) { return this.getKey(r.entity(e), "permissions"); } getEntityBoundJsonSchemaQueryKey(e) { return this.getKey(...r.boundJSONSchema(e)); } getEntitySchemaValidationResultsQueryKey(e) { return this.getKey(...r.schemaValidationResults(e)); } getEntityHeaderQueryKey(e, t) { return this.getKey(...r.header(e, t)); } getEntityAccessRequirementsQueryKey(e) { return this.getKey(...r.accessRequirements(e)); } getEntityHeadersQueryKey(e) { return this.getKey(...r.headers(e)); } getAllTableQueryResultsKey() { return this.getKey(r.all, { type: "tableQueryResult" }); } getEntityTableQueryResultQueryKey(e, t) { return this.getKey( ...r.tableQueryResult(e, t) ); } getEntityTableQueryResultWithAsyncStatusQueryKey(e, t) { return this.getKey( ...r.tableQueryResultWithAsyncStatus( e, t ) ); } getRootWikiPageKeyQueryKey(e, t) { return this.getKey( R, e, t ); } getWikiPageQueryKey(e) { return this.getKey( l, e.ownerObjectType, e.ownerObjectId, e.wikiPageId ); } getWikiPageKey(e, t) { return this.getKey("ownerId", e, "wikiPageId", t); } getWikiAttachmentsQueryKey(e) { return this.getKey( l, e.ownerObjectType, e.ownerObjectId, e.wikiPageId, "attachments" ); } getFullTableQueryResultQueryKey(e, t) { return t ? this.getKeyAnonymous( ...r.fullTableQueryResult(e) ) : this.getKey( ...r.fullTableQueryResult(e) ); } getDownloadListBaseQueryKey() { return this.getKey(n.base); } getDownloadListAvailableFilesQueryKey(e) { return this.getKey(...n.availableFiles(e)); } getDownloadListAvailableFilesInfiniteQueryKey(e) { return this.getKey(...n.availableFilesInfinite(e)); } getDownloadListActionsRequiredQueryKey() { return this.getKey(...n.getActionsRequired()); } getDownloadListActionsRequiredInfiniteQueryKey() { return this.getKey(...n.getActionsRequiredInfinite()); } getDownloadListStatisticsQueryKey() { return this.getKey(...n.getStatistics()); } searchAccessApprovalsQueryKey(e) { return this.getKey("accessApprovalSearch", e); } getUserAccessApprovalQueryKey(e) { return this.getKey("accessApproval", e); } getAccessRequirementQueryKey(e) { return this.getKey(y, e); } getAccessRequirementAclQueryKey(e) { return this.getKey(y, e, "acl"); } searchAccessRequirementsQueryKey(e) { return this.getKey(y, "search", e); } getAccessRequirementWikiPageKey(e) { return this.getKey(y, e, "wikiPageKey"); } getRestrictionInformationQueryKey(e) { return this.getKey(y, "restrictionInformation", { ...e, // The ID may be a number, or a stringified number, or a synID. Transform to just a number to normalize the cache. objectId: K(e.objectId) }); } getRestrictionInformationBatchQueryKey(e) { const t = { ...e, // The IDs may be number, or stringified numbers, or synIDs. Transform to normalize the cache. objectIds: e.objectIds.map(K).map(String) }; return this.getKey( y, "restrictionInformationBatch", t ); } getAllAccessRequirementStatusesQueryKey() { return this.getKey(y, "status"); } getAccessRequirementStatusQueryKey(e) { return this.getKey(y, "status", e); } getDataAccessRequestForUpdateQueryKey(e) { return this.getKey( y, e, "dataAccessRequestForUpdate" ); } getAccessRequirementResearchProjectQueryKey(e) { return this.getKey( y, e, "researchProject" ); } getSortedAccessRequirementsAndStatusQueryKey(e) { return this.getKey( y, "sortedByStatus", e ); } // Returns key that can be used to invalidate all data access submission queries getDataAccessSubmissionQueryKey() { return this.getKey(g); } getDataAccessSubmissionByIdQueryKey(e) { return this.getKey(g, "byId", e); } searchDataAccessSubmissionQueryKey(e) { return this.getKey( g, "search", "reviewer", e ); } searchDataAccessSubmissionUserRequestsQueryKey(e) { return this.getKey( g, "search", "user", e ); } getApprovedSubmissionInfoQueryKey(e) { return this.getKey("approvedSubmissionInfo", e); } getValidationSchemaQueryKey(e) { return this.getKey("validationSchema", e); } getPresignedUrlContentQueryKey(e, t, i) { return this.getKey("presignedUrlContent", e, t, i); } getPresignedUrlFromFHAContentQueryKey(e, t) { return t ? this.getKeyAnonymous( "presignedUrlContentFromFHA", e ) : this.getKey("presignedUrlContentFromFHA", e); } getStablePresignedUrlFromFHAQueryKey(e, t) { return t ? this.getKeyAnonymous( "stablePresignedUrlFromFHA", e ) : this.getKey("stablePresignedUrlFromFHA", e); } getProfileImageQueryKey(e) { return this.getKey("profileImageData", e); } getDefaultUploadDestinationQueryKey(e) { return this.getKey("uploadDestination", "default", e); } getUploadDestinationForStorageLocationQueryKey(e, t) { return this.getKey("uploadDestination", e, t); } getForumModeratorsQueryKey(e) { return this.getKey("moderators", e); } getForumMetadataQueryKey(e) { return this.getKey("forumThread", e, "metadata"); } getAllForumThreadsQueryKey(e) { return this.getKey("forumthread", e); } getForumThreadsQueryKey(e, t, i, u, a) { return this.getKey("forumthread", e, { limit: t, filter: a, sort: i, ascending: u }); } getForumSearchQueryKey(e, t) { return this.getKey( "forumthread", "search", e, t ); } getAllRepliesQueryKey(e) { return this.getKey("reply", e); } getRepliesQueryKey(e, t, i, u, a) { return this.getKey("reply", e, { limit: i, filter: a, sort: u, ascending: t }); } getReplyQueryKey(e, t, i) { return this.getKey("reply", e, { replyId: t, messageKey: i }); } getThreadQueryKey(e) { return this.getKey("thread", e); } getThreadBodyQueryKey(e, t) { return this.getKey("thread", e, t); } getMyOAuthClientsQueryKey() { return this.getKey("oauthClient"); } getOAuthClientQueryKey(e) { return this.getKey("oauthClient", e); } getOAuthClientAclQueryKey(e) { return this.getKey("oauthClient", e, "acl"); } getHasCurrentUserAuthorizedOAuthClientQueryKey(e) { return this.getKey("currentUserHasAuthorizedClient", e); } getDOIAssociationQueryKey(e) { return this.getKey(["doi", e, "association"]); } getDOIQueryKey(e) { return this.getKey(["doi", e]); } getAllSubscribersQueryKey() { return this.getKey("subscribers"); } getSubscribersQueryKey(e, t) { return this.getKey("subscribers", e, t); } getBaseSubscriptionQueryKey() { return this.getKey("subscription"); } getAllSubscriptionsQueryKey(e) { return this.getKey("subscription", "all", e); } getSubscriptionQueryKey(e, t) { return this.getKey("subscription", e, t); } getSearchEntitiesQueryKey(e) { return this.getKey("searchEntities", e); } getSuggestionQueryKey(e) { return this.getKey("suggestion", e); } getTeamQueryKey(e) { return this.getKey("team", e); } getTeamListQueryKey(e) { return this.getKey("team", e, "teamList"); } getChallengeTeamListQueryKey(e) { return this.getKey("challenge", e, "teamList"); } getTeamMembersQueryKey(e) { return this.getKey("team", e, "membersList"); } getTeamMemberCountQueryKey(e) { return this.getKey("team", e, "memberCount"); } getIsUserMemberOfTeamQueryKey(e, t) { return this.getKey("team", e, "member", t); } getMembershipStatusQueryKey(e, t) { return this.getKey("team", e, "membershipStatus", t); } getAllOpenMembershipInvitationsForUserQueryKey(e) { return this.getKey("openMembershipInvitations", e); } getTeamAccessRequirementsQueryKey(e) { return this.getKey("team", e, "accessRequirements"); } getFavoritesQueryKey() { return this.getKey("favorites"); } getUserFavoritesQueryKey(e, t) { return this.getKey("favorites", e, t); } getUserFavoritesInfiniteQueryKey(e, t) { return this.getKey("favorites", "infinite", e, t); } getTrashCanItemsQueryKey() { return this.getKey("trashCan", "list"); } getUserChallengesQueryKey(e) { return this.getKey("userChallenges", e); } getPassingRecordQueryKey(e) { return this.getKey("passingRecord", e); } getAllSubmissionTeamsQueryKeys() { return this.getKey("submissionTeams"); } getSubmissionTeamsQueryKey(e, t, i) { return this.getKey("submissionTeams", e, { limit: t, offset: i }); } getUserProjectsQueryKey(e, t) { return this.getKey("userProjects", e, t); } getAllUserTeamsQueryKey() { return this.getKey("userTeams"); } getUserTeamsQueryKey(e) { return this.getKey("userTeams", e); } getPersonalAccessTokensQueryKey() { return this.getKey("personalAccessTokens"); } getMyProjectsQueryKey(e) { return this.getKey("myProjects", e); } getNotificationEmailQueryKey() { return this.getKey("notificationEmail"); } getCurrentUserProfileQueryKey() { return this.getKey("user", "current", "profile"); } getUserBundleQueryKey(e, t) { const i = { ...(t & p) !== 0 ? { isUserProfile: !0 } : void 0, ...(t & S) !== 0 ? { isOrcId: !0 } : void 0, ...(t & b) !== 0 ? { isVerificationSubmission: !0 } : void 0, ...(t & A) !== 0 ? { isCertified: !0 } : void 0, ...(t & m) !== 0 ? { isVerified: !0 } : void 0, ...(t & d) !== 0 ? { isACT: !0 } : void 0, ...(t & Q) !== 0 ? { isARReviewer: !0 } : void 0 }; return this.getKey("user", e, "bundle", i); } getUserProfileQueryKey(e) { return this.getKey("user", e, "profile"); } getPrincipalAliasQueryKey(e) { return this.getKey("principalAlias", e); } getUserGroupHeaderQueryKey(e) { return this.getKey("userGroupHeader", e); } getUserGroupHeaderBatchQueryKey(e) { return this.getKey("userGroupHeaderBatch", e); } getUserGroupHeaderWithAliasQueryKey(e) { return this.getKey("userGroupHeader", e); } getUserGroupHeaderSearchQueryKey(e, t) { return this.getKey("userGroupHeader", "search", e, t); } getTwoFactorAuthStatusQueryKey() { return this.getKey("twoFactorAuthStatus"); } getBatchOfFiles(e) { return this.getKey("fileBatch", e); } getChatAgentTraceKey(e) { return this.getKey("chatbotTraceEvents", e); } getTermsOfServiceInfoKey() { return this.getKey("termsOfServiceInfo"); } getTermsOfServiceStatus() { return this.getKey("termsOfServiceStatus"); } getRealmPrincipalsQueryKey() { return this.getKey("realmPrincipals"); } getCurrentRealmQueryKey() { return this.getKey("currentRealm"); } getRealmByIdQueryKey(e) { return this.getKey("realm", e); } getProjectStorageUsageKey(e) { return this.getKey("projectstorageusage", e); } getPaginatedDockerTagQueryKey(e, t, i, u, a) { return this.getKey("dockerTag", e, t, i, u, a); } getDefaultColumnModelsQueryKey(e, t) { return this.getKey("defaultColumnModels", e, t); } getAnnotationColumnModelsQueryKey(e) { return this.getKey("annotationColumnModels", e); } getEvaluationByIdQueryKey(e) { return this.getKey("evaluation", e); } getEvaluationsQueryKey(e) { return this.getKey("evaluation", "paginated", e); } getEvaluationRoundsQueryKey(e) { return this.getKey("evaluation", e, "rounds"); } chatAgentSessionHistoryQueryKey(e) { return this.getKey("chatHistory", e); } getWebhooksQueryKey() { return this.getKey("webhooks"); } getGithubLatestTagKey(e, t) { return this.getKey("githubLatestTag", e, t); } getFileContentKey(e) { return this.getKey("fileContent", e); } getPortalKey(e) { return this.getKey("portal", e); } getPortalPermissionsKey(e) { return this.getKey("portal", e, "permissions"); } getPortalAclQueryKey(e) { return this.getKey("portal", e, "acl"); } getListPortalsQueryKey() { return this.getKey("portal", "list"); } getGridSessionKey(e) { return this.getKey("gridSession", e); } getGridSessionListKey(e) { return this.getKey("gridSession", "list", e); } getCurationTaskKey(e) { return this.getKey("curationTask", e); } getCurationTaskListKey(e) { return this.getKey("curationTask", "list", e); } getCsvPreviewQueryKey(e) { return this.getKey("csvPreview", e); } getAddToDownloadListStatsQueryKey(e) { const t = e.request?.parentId ?? h( e?.request?.query?.sql ?? "" ); return this.getKey( r.entity(t), "addToDownloadListStats", e ); } getAsyncJobStatusQueryKey(e) { return this.getKey("asyncJobStatus", e); } } export { D as KeyFactory }; //# sourceMappingURL=KeyFactory.js.map