Allow to inject fetch to objectloader constructor

This commit is contained in:
Felix Deiters
2022-02-28 11:53:20 +01:00
parent 2f19961a6a
commit 28aff364a3
2 changed files with 29 additions and 4 deletions
+24 -1
View File
@@ -1 +1,24 @@
// NOTE: This lib is not working in node, because node-fetch returns node-native readable streams - we need a workaround first.
// Since Node v<18 does not provide fetch, we need to pass it in the options object. Note that fetch must return a WHATWG compliant stream, so cross-fetch won't work, but node/undici's implementation will.
import { fetch } from 'undici'
import ObjectLoader from '../../index.js'
let loader = new ObjectLoader({
serverUrl:"https://latest.speckle.dev",
streamId:"3ed8357f29",
objectId:"0408ab9caaa2ebefb2dd7f1f671e7555",
options:{ enableCaching: false, excludeProps:[], fetch }
})
let loadData = async function loadData() {
let obj = await loader.getAndConstructObject((e) =>{
console.log(e) // log progress!
})
console.log('Done!')
console.log( obj )
}
loadData()