diff --git a/package-lock.json b/package-lock.json index 7767047..b4a1339 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3539,6 +3539,15 @@ "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", "dev": true }, + "isomorphic-unfetch": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/isomorphic-unfetch/-/isomorphic-unfetch-3.1.0.tgz", + "integrity": "sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==", + "requires": { + "node-fetch": "^2.6.1", + "unfetch": "^4.2.0" + } + }, "isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -4679,6 +4688,11 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -6380,6 +6394,11 @@ "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==", "dev": true }, + "unfetch": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-4.2.0.tgz", + "integrity": "sha512-F9p7yYCn6cIW9El1zi0HI6vqpeIvBsr3dSuRO6Xuppb1u5rXpCPmMvLSyECLhybr9isec8Ohl0hPekMVrEinDA==" + }, "union-value": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", diff --git a/package.json b/package.json index 249b491..0e97907 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "module": "dist/index.esm.js", "dependencies": { "husky": "^4.3.7", + "isomorphic-unfetch": "^3.1.0", "lint-staged": "^10.5.3" }, "devDependencies": { diff --git a/src/internal/index.ts b/src/internal/index.ts index bfd4d2f..b3ec76f 100644 --- a/src/internal/index.ts +++ b/src/internal/index.ts @@ -1,5 +1,5 @@ import { CheckParametersTypes, RequestObjectParametersTypes, RequestObjectTypes } from './internal.types'; -import { outputTypes, inputTypes, genomicModalities } from './internal.config'; +import { HANDLE, outputTypes, inputTypes, genomicModalities } from './internal.config'; class Client { baseUrl: string; @@ -57,8 +57,24 @@ class Client { requestObject.logical_operator = 'and'; return requestObject; } + + async hubmapQuery({ inputType, outputType, inputSet, genomicModality, /* limit = 1000, */ pValue }) { + this.checkParameters(inputType, outputType, genomicModality, pValue); + + const requestUrl = `${this.base_url + outputType}/`; + + const requestObject = this.fillRequestObject(inputType, outputType, inputSet, genomicModality, pValue); + + const response = await fetch(requestUrl, { + method: 'POST', + body: JSON.stringify(requestObject), + }); + + const { results } = response.json(); + // Returns the key to be used in future computations + return results[0][HANDLE]; + } /* - hubmapQuery() {} setIntersection() {} diff --git a/src/internal/internal.config.ts b/src/internal/internal.config.ts index 0abd1a4..e6846ea 100644 --- a/src/internal/internal.config.ts +++ b/src/internal/internal.config.ts @@ -1,5 +1,7 @@ import { InputTypes } from './internal.types'; +const HANDLE = 'query_pickle_hash'; + const outputTypes: string[] = ['cell', 'organ', 'gene', 'cluster']; const inputTypes: InputTypes = { @@ -12,4 +14,4 @@ const inputTypes: InputTypes = { const genomicModalities: string[] = ['rna', 'atac']; // Used for quantitative gene->cell queries -export { outputTypes, inputTypes, genomicModalities }; +export { HANDLE, outputTypes, inputTypes, genomicModalities }; diff --git a/src/internal/internal.types.ts b/src/internal/internal.types.ts index 1ed95ad..9672bbc 100644 --- a/src/internal/internal.types.ts +++ b/src/internal/internal.types.ts @@ -30,4 +30,8 @@ interface RequestObjectTypes { /* eslint-enable camelcase */ } -export { InputTypes, CheckParametersTypes, RequestObjectParametersTypes, RequestObjectTypes }; +interface HubmapQueryParameters extends RequestObjectParametersTypes { + limit?: number; +} + +export { InputTypes, CheckParametersTypes, RequestObjectParametersTypes, RequestObjectTypes, HubmapQueryParameters };