@sjcrh/proteinpaint-shared 2.169.0 → 2.170.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/common.js +4 -6
- package/src/fetch-helpers.js +52 -4
- package/src/index.js +1 -0
- package/src/manhattan.js +3 -0
- package/src/termdb.usecase.js +2 -1
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -1323,9 +1323,7 @@ const dtTerms_temp = [
|
|
|
1323
1323
|
isleaf: true,
|
|
1324
1324
|
type: 'dtsnvindel',
|
|
1325
1325
|
dt: dtsnvindel,
|
|
1326
|
-
values:
|
|
1327
|
-
mutationClasses.filter(key => key != 'Blank' && key != 'WT').map(key => [key, { label: mclass[key].label }])
|
|
1328
|
-
)
|
|
1326
|
+
values: {}
|
|
1329
1327
|
},
|
|
1330
1328
|
{
|
|
1331
1329
|
id: 'cnv',
|
|
@@ -1335,7 +1333,7 @@ const dtTerms_temp = [
|
|
|
1335
1333
|
isleaf: true,
|
|
1336
1334
|
type: 'dtcnv',
|
|
1337
1335
|
dt: dtcnv,
|
|
1338
|
-
values:
|
|
1336
|
+
values: {}
|
|
1339
1337
|
},
|
|
1340
1338
|
{
|
|
1341
1339
|
id: 'fusion',
|
|
@@ -1345,7 +1343,7 @@ const dtTerms_temp = [
|
|
|
1345
1343
|
isleaf: true,
|
|
1346
1344
|
type: 'dtfusion',
|
|
1347
1345
|
dt: dtfusionrna,
|
|
1348
|
-
values: {
|
|
1346
|
+
values: {}
|
|
1349
1347
|
},
|
|
1350
1348
|
{
|
|
1351
1349
|
id: 'sv',
|
|
@@ -1355,7 +1353,7 @@ const dtTerms_temp = [
|
|
|
1355
1353
|
isleaf: true,
|
|
1356
1354
|
type: 'dtsv',
|
|
1357
1355
|
dt: dtsv,
|
|
1358
|
-
values: {
|
|
1356
|
+
values: {}
|
|
1359
1357
|
}
|
|
1360
1358
|
]
|
|
1361
1359
|
// add origin annotations to dt terms
|
package/src/fetch-helpers.js
CHANGED
|
@@ -15,8 +15,9 @@ import { encode } from './urljson.js'
|
|
|
15
15
|
init{headers?, body?}
|
|
16
16
|
- first two arguments are same as native fetch
|
|
17
17
|
*/
|
|
18
|
-
export async function ezFetch(_url, init = {}) {
|
|
19
|
-
const url = mayAdjustRequest(_url, init)
|
|
18
|
+
export async function ezFetch(_url, init = {}, opts = {}) {
|
|
19
|
+
const url = opts.autoMethod ? mayAdjustRequest(_url, init) : _url
|
|
20
|
+
if (typeof init.body === 'object') init.body = JSON.stringify(init.body)
|
|
20
21
|
|
|
21
22
|
return fetch(url, init).then(async r => {
|
|
22
23
|
const response = await processResponse(r)
|
|
@@ -73,6 +74,9 @@ export async function processResponse(r) {
|
|
|
73
74
|
if (ct.startsWith('multipart/form-data')) return processFormData(r)
|
|
74
75
|
else throw `cannot handle response content-type: '${ct}'`
|
|
75
76
|
}
|
|
77
|
+
if (ct == 'application/x-ndjson-nestedkey') {
|
|
78
|
+
return processNDJSON_nestedKey(r)
|
|
79
|
+
}
|
|
76
80
|
// call blob() as catch-all
|
|
77
81
|
// https://developer.mozilla.org/en-US/docs/Web/API/Response
|
|
78
82
|
return r.blob()
|
|
@@ -115,6 +119,44 @@ export async function processFormData(res) {
|
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
|
|
122
|
+
async function processNDJSON_nestedKey(r) {
|
|
123
|
+
// 1. Pipe through TextDecoder to convert bytes to text
|
|
124
|
+
const stream = r.body.pipeThrough(new TextDecoderStream())
|
|
125
|
+
const reader = stream.getReader()
|
|
126
|
+
let rootObj = {}
|
|
127
|
+
|
|
128
|
+
let buffer = ''
|
|
129
|
+
|
|
130
|
+
while (true) {
|
|
131
|
+
const { value, done } = await reader.read()
|
|
132
|
+
if (done) break
|
|
133
|
+
|
|
134
|
+
// 2. Add new chunk to buffer
|
|
135
|
+
buffer += value
|
|
136
|
+
|
|
137
|
+
// 3. Split by newline
|
|
138
|
+
let parts = buffer.split('\n')
|
|
139
|
+
|
|
140
|
+
// 4. Keep the last partial line in the buffer
|
|
141
|
+
buffer = parts.pop()
|
|
142
|
+
|
|
143
|
+
// 5. Process complete lines
|
|
144
|
+
for (const line of parts) {
|
|
145
|
+
if (line.trim()) {
|
|
146
|
+
const [keys, data] = JSON.parse(line) //; console.log(143, keys, data) // Process JSON data
|
|
147
|
+
if (!keys.length) rootObj = data
|
|
148
|
+
else {
|
|
149
|
+
const lastKey = keys.pop()
|
|
150
|
+
let target = rootObj
|
|
151
|
+
for (const k of keys) target = target[k]
|
|
152
|
+
target[lastKey] = data
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return rootObj
|
|
158
|
+
}
|
|
159
|
+
|
|
118
160
|
// key: request object reference or conputed string dataName
|
|
119
161
|
// value: fetch promise or response
|
|
120
162
|
const dataCache = new Map()
|
|
@@ -145,6 +187,7 @@ const maxNumOfDataKeys = 360
|
|
|
145
187
|
- if not provided, then a string cache data key will be computed from the request url, body, headers
|
|
146
188
|
*/
|
|
147
189
|
export async function memFetch(url, init, opts = {}) {
|
|
190
|
+
if (typeof init.body === 'object') init.body = JSON.stringify(init.body)
|
|
148
191
|
const dataKey = opts.q || (await getDataName(url, init))
|
|
149
192
|
let result = dataCache.get(dataKey)
|
|
150
193
|
|
|
@@ -161,8 +204,13 @@ export async function memFetch(url, init, opts = {}) {
|
|
|
161
204
|
fetch(url, init).then(async r => {
|
|
162
205
|
const response = await processResponse(r)
|
|
163
206
|
if (!r.ok) {
|
|
164
|
-
console.
|
|
165
|
-
throw
|
|
207
|
+
console.trace(response)
|
|
208
|
+
throw (
|
|
209
|
+
'memFetch error ' +
|
|
210
|
+
r.status +
|
|
211
|
+
': ' +
|
|
212
|
+
(typeof response == 'object' ? response.message || response.error : response)
|
|
213
|
+
)
|
|
166
214
|
}
|
|
167
215
|
// to-do: support opt.freeze to enforce deep freeze of data.json()
|
|
168
216
|
dataCache.set(dataKey, response)
|
package/src/index.js
CHANGED
package/src/manhattan.js
ADDED
package/src/termdb.usecase.js
CHANGED