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

83 lines (82 loc) 2.72 kB
import { http as n, HttpResponse as e } from "msw"; function c() { return crypto.getRandomValues(new Uint32Array(1))[0]; } const u = () => `grid-session-${c() * 1e5}`, r = /* @__PURE__ */ new Map(); function l(o) { return [ // Handler for starting a grid session n.post( `${o}/repo/v1/grid/session/async/start`, async ({ request: t }) => { const s = `job-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, a = await t.json(); return r.set(s, { status: "PROCESSING", startTime: Date.now(), sessionId: u() }), e.json(a, { status: 201 }); } ), // Handler for retrieving async job results n.get( `${o}/repo/v1/grid/session/async/get/:token`, ({ params: t }) => { const s = r.get(t.token); return s ? (s.status = "COMPLETE", e.json( { concreteType: "org.sagebionetworks.repo.model.grid.GridSession", gridSession: { sessionId: s.sessionId, startedBy: "mockUser", startedOn: (/* @__PURE__ */ new Date()).toISOString(), etag: `etag-${Date.now()}`, modifiedOn: (/* @__PURE__ */ new Date()).toISOString(), lastReplicaIdClient: 1, lastReplicaIdService: 1 } }, { status: 200 } )) : e.text("Job not found", { status: 404 }); } ), // Handler for GridSessionReplica n.post( `${o}/repo/v1/grid/:sessionId/replica`, async ({ request: t }) => { const { gridSessionId: s } = await t.json(); if (!Array.from(r.values()).find( (p) => p.sessionId === s )) return e.text("Grid session not found", { status: 404 }); const i = c() % 1e3, d = { concreteType: "org.sagebionetworks.repo.model.grid.GridReplica", replica: { gridSessionId: s, replicaId: i, createdBy: "mockUser", isAgentReplica: !1, createdOn: (/* @__PURE__ */ new Date()).toISOString() } }; return e.json(d, { status: 201 }); } ), // Handler for Grid presigned URL n.get( `${o}/repo/v1/grid/:sessionId/presignedUrl`, ({ params: t }) => { const { sessionId: s } = t; if (!Array.from(r.values()).find( (d) => d.sessionId === s )) return e.text("Grid session not found", { status: 404 }); const i = `https://mock-s3-bucket/${s}/data.csv?presigned=true`; return e.json({ presignedUrl: i }, { status: 200 }); } ) ]; } export { l as getGridHandlers }; //# sourceMappingURL=gridHandlers.js.map