2.21.2 • Published 3 months ago

@speckle/objectloader v2.21.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 months ago

The Speckle Object Loader

Twitter Follow Community forum users website docs npm version

Documentation

Comprehensive developer and user documentation can be found in our:

📚 Speckle Docs website

Getting started

This is a small utility class that helps you stream an object and all its sub-components from the Speckle Server API. It is intended to be used in contexts where you want to "download" the whole object, or iteratively traverse its whole tree.

In the browser

Here's a sample way on how to use it, pilfered from the 3d viewer package:

async load( { serverUrl, token, streamId, objectId } ) {

  const loader = new ObjectLoader( { serverUrl, token, streamId, objectId } )

  let total = null
  let count = 0

  for await ( let obj of loader.getObjectIterator() ) {

    if( !total ) total = obj.totalChildrenCount

    console.log( obj, `Progress: ${count++}/${total}` )

  }

}

If you do not want to process the objects one by one as they are streamed to you, you can use the getAndConstructObject() method. Here's an example:

let loader = new ObjectLoader( {
  serverUrl: "https://latest.speckle.dev",
  streamId: "3ed8357f29",
  objectId: "0408ab9caaa2ebefb2dd7f1f671e7555",
  options: {
    fullyTraverseArrays: false, // Default: false. By default, if an array starts with a primitive type, it will not be traversed. Set it to true if you want to capture scenarios in which lists can have intersped objects and primitives, e.g. [ 1, 2, "a", { important object } ]
    excludeProps: [ 'displayValue', 'displayMesh', '__closure' ] // Default: []. Any prop names that you pass in here will be ignored from object construction traversal.
  }
} )

let obj = await loader.getAndConstructObject( ( e ) => console.log( 'Progress', e ) )

### On the server

Since Node.js does not yet support the [`fetch API`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch), you'll need to provide your own `fetch` function in the options object. Note that `fetch` must return a [Web Stream](https://nodejs.org/api/webstreams.html), so [node-fetch](https://github.com/node-fetch/node-fetch) won't work, but [node/undici's](https://undici.nodejs.org/) implementation will.

```js
import { fetch } from 'undici'

let loader = new ObjectLoader({
  serverUrl: 'https://latest.speckle.dev',
  streamId: '3ed8357f29',
  objectId: '0408ab9caaa2ebefb2dd7f1f671e7555',
  options: { enableCaching: false, excludeProps: [], fetch },
})

Community

If in trouble, the Speckle Community hangs out on the forum. Do join and introduce yourself! We're happy to help.

License

Unless otherwise described, the code in this repository is licensed under the Apache-2.0 License. If you have any questions, don't hesitate to get in touch with us via email.

2.21.2

3 months ago

2.21.1

3 months ago

2.19.6

5 months ago

2.19.4

6 months ago

2.19.5

5 months ago

2.19.2

6 months ago

2.19.3

6 months ago

2.19.0

6 months ago

2.21.0

4 months ago

2.20.0-alpha4

6 months ago

2.20.0-alpha3

6 months ago

2.20.0-alpha2

6 months ago

2.20.0-alpha1

6 months ago

2.20.0-alpha5

6 months ago

2.20.2

4 months ago

2.20.3

4 months ago

2.20.1

5 months ago

2.20.6

4 months ago

2.20.4

4 months ago

2.20.5

4 months ago

2.18.16

8 months ago

2.18.15

8 months ago

2.18.14

9 months ago

2.18.12

9 months ago

2.18.13

9 months ago

2.18.11

9 months ago

2.18.10

9 months ago

2.18.9

9 months ago

2.18.8

10 months ago

2.18.7

10 months ago

2.18.6

10 months ago

2.18.3

10 months ago

2.18.4

10 months ago

2.18.2

10 months ago

2.18.1

11 months ago

2.18.0

11 months ago

2.17.16

11 months ago

2.17.15

11 months ago

2.17.14

11 months ago

2.17.12

11 months ago

2.17.11

11 months ago

2.17.13

11 months ago

2.17.10

11 months ago

2.17.9

12 months ago

2.17.8

12 months ago

2.17.7

1 year ago

2.17.6

1 year ago

2.17.5

1 year ago

2.17.4

1 year ago

2.17.2

1 year ago

2.17.3

1 year ago

2.17.0

1 year ago

2.17.1

1 year ago

2.15.0

1 year ago

2.15.1

1 year ago

2.16.0

1 year ago

2.12.666

2 years ago

2.14.7

2 years ago

2.14.5

2 years ago

2.14.6

2 years ago

2.14.3

2 years ago

2.14.4

2 years ago

2.14.1

2 years ago

2.14.0

2 years ago

2.13.2

2 years ago

2.13.3

2 years ago

2.13.0

2 years ago

2.13.1

2 years ago

2.12.5

2 years ago

2.12.3

2 years ago

2.12.4

2 years ago

2.12.1

2 years ago

2.12.2

2 years ago

2.12.0

2 years ago

2.11.0

2 years ago

2.11.1

2 years ago

2.11.4

2 years ago

2.11.2

2 years ago

2.11.3

2 years ago

2.9.2

2 years ago

2.9.1

2 years ago

2.10.1

2 years ago

2.10.2

2 years ago

2.10.0

2 years ago

2.9.0

2 years ago

2.10.3

2 years ago

2.8.1

2 years ago

2.7.2

2 years ago

2.8.0

2 years ago

2.8.3

2 years ago

2.8.2

2 years ago

2.7.0

2 years ago

2.6.3

2 years ago

2.7.1

2 years ago

2.5.5-alpha.3733

3 years ago

2.6.1

3 years ago

2.5.4

3 years ago

2.6.2

3 years ago

2.5.3

3 years ago

2.5.5

3 years ago

2.4.2-alpha.0

3 years ago

2.5.1-alpha.14

3 years ago

2.4.2-alpha.2

3 years ago

2.4.2-alpha.4

3 years ago

2.5.2

3 years ago

2.5.1-alpha.11

3 years ago

2.5.1

3 years ago

2.5.1-alpha.10

3 years ago

2.4.2

3 years ago

2.4.2-alpha.20

3 years ago

2.5.1-alpha.7

3 years ago

2.5.1-alpha.9

3 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.3

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago