@speckle/objectloader 2.4.2-alpha.2 → 2.4.2

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/.babelrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "useBuiltIns": "entry",
7
+ "corejs": "3"
8
+ }
9
+ ]
10
+ ],
11
+ "ignore": ["node_modules/**/*"]
12
+ }
@@ -0,0 +1 @@
1
+ since 2019
package/.eslintrc.cjs CHANGED
@@ -10,7 +10,8 @@ const config = {
10
10
  },
11
11
  parserOptions: {
12
12
  sourceType: 'module'
13
- }
13
+ },
14
+ ignorePatterns: ['examples/browser/objectloader.web.js']
14
15
  }
15
16
 
16
17
  module.exports = config
@@ -14,8 +14,8 @@
14
14
  To ensure this example runs correctly, please serve this file from a local http
15
15
  server - if you manually open the file in a browser, it might not work.
16
16
  </p>
17
- <button onclick="loadData()">PRESS ME</button>
17
+ <button type="button" onclick="loadData()">PRESS ME</button>
18
18
  </body>
19
19
 
20
- <script src="script.js" type="module"></script>
20
+ <script src="./script.js" type="module"></script>
21
21
  </html>
@@ -1,4 +1,4 @@
1
- import ObjectLoader from '../../index.js'
1
+ import ObjectLoader from './objectloader.web.js'
2
2
  window.ObjectLoader = ObjectLoader
3
3
 
4
4
  // let loader = new ObjectLoader({serverUrl:"https://latest.speckle.dev", streamId:"16d73b756a", objectId:"99b20746460c4369f25e08e92c988a9d"})
@@ -1,7 +1,6 @@
1
1
  // 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.
2
-
3
2
  import { fetch } from 'undici'
4
- import ObjectLoader from '../../index.js'
3
+ import ObjectLoader from '../../dist/objectloader.js'
5
4
 
6
5
  const loader = new ObjectLoader({
7
6
  serverUrl: 'https://latest.speckle.dev',
package/jsconfig.json CHANGED
@@ -3,5 +3,5 @@
3
3
  "compilerOptions": {
4
4
  "module": "es2020"
5
5
  },
6
- "include": ["index.js", "examples"]
6
+ "include": ["src/**", "examples"]
7
7
  }
package/package.json CHANGED
@@ -1,18 +1,24 @@
1
1
  {
2
2
  "name": "@speckle/objectloader",
3
- "version": "2.4.2-alpha.2",
3
+ "version": "2.4.2",
4
4
  "description": "Simple API helper to stream in objects from the Speckle Server.",
5
- "main": "index.js",
5
+ "main": "dist/objectloader.js",
6
+ "module": "dist/objectloader.esm.js",
6
7
  "homepage": "https://speckle.systems",
7
- "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/specklesystems/speckle-server.git",
11
11
  "directory": "packages/objectloader"
12
12
  },
13
+ "engines": {
14
+ "node": "^16.0.0"
15
+ },
13
16
  "scripts": {
14
- "test": "echo \"Error: no test specified\" && exit 1",
15
- "lint": "eslint . --ext .js,.ts"
17
+ "lint": "eslint . --ext .js,.ts",
18
+ "build:dev": "rollup --config",
19
+ "build": "NODE_ENV=production rollup --config",
20
+ "dev": "rollup --config --watch",
21
+ "example": "EXAMPLE_BUILD=1 rollup --config && http-server ./examples/browser -p 3031 -o"
16
22
  },
17
23
  "keywords": [
18
24
  "speckle",
@@ -21,11 +27,24 @@
21
27
  ],
22
28
  "author": "AEC Systems",
23
29
  "license": "Apache-2.0",
30
+ "dependencies": {
31
+ "@babel/core": "^7.17.9",
32
+ "core-js": "^3.21.1",
33
+ "regenerator-runtime": "^0.13.7"
34
+ },
24
35
  "devDependencies": {
36
+ "@babel/preset-env": "^7.16.11",
37
+ "@rollup/plugin-babel": "^5.3.1",
38
+ "@rollup/plugin-commonjs": "^21.0.3",
39
+ "@rollup/plugin-node-resolve": "^13.1.3",
25
40
  "eslint": "^8.11.0",
26
41
  "eslint-config-prettier": "^8.5.0",
42
+ "http-server": "^14.1.0",
27
43
  "prettier": "^2.5.1",
44
+ "rollup": "^2.70.1",
45
+ "rollup-plugin-delete": "^2.0.0",
46
+ "rollup-plugin-terser": "^7.0.2",
28
47
  "undici": "^4.14.1"
29
48
  },
30
- "gitHead": "9227228667897643190b839b1172349807e8ac65"
49
+ "gitHead": "5627e490f9a3ecadf19cc4686ad15f344d9ad2d3"
31
50
  }
package/readme.md CHANGED
@@ -12,12 +12,18 @@ Comprehensive developer and user documentation can be found in our:
12
12
 
13
13
  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.
14
14
 
15
+ ### Examples
16
+
17
+ If you've got this repo checked out locally, you can run `npm run example` to run an example web page running ObjectLoader in the browser at 'http://127.0.0.1:3031/'. This will run the example HTML found under ./examples/browser/'.
18
+
19
+ To test ObjectLoader in a node environment, just run `node ./examples/node/script.mjs`
20
+
15
21
  ### In the browser
16
22
 
17
23
  Here's a sample way on how to use it, pilfered from the [3d viewer package](../viewer):
18
24
 
19
25
  ```js
20
-
26
+ import ObjectLoader from '@speckle/objectloader';
21
27
 
22
28
  async load( { serverUrl, token, streamId, objectId } ) {
23
29
 
@@ -40,34 +46,41 @@ async load( { serverUrl, token, streamId, objectId } ) {
40
46
 
41
47
  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:
42
48
 
43
- ````js
49
+ ```js
50
+ import ObjectLoader from '@speckle/objectloader'
44
51
 
45
- let loader = new ObjectLoader( {
46
- serverUrl: "https://latest.speckle.dev",
47
- streamId: "3ed8357f29",
48
- objectId: "0408ab9caaa2ebefb2dd7f1f671e7555",
52
+ let loader = new ObjectLoader({
53
+ serverUrl: 'https://latest.speckle.dev',
54
+ streamId: '3ed8357f29',
55
+ objectId: '0408ab9caaa2ebefb2dd7f1f671e7555',
49
56
  options: {
50
57
  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 } ]
51
- excludeProps: [ 'displayValue', 'displayMesh', '__closure' ] // Default: []. Any prop names that you pass in here will be ignored from object construction traversal.
58
+ excludeProps: ['displayValue', 'displayMesh', '__closure'] // Default: []. Any prop names that you pass in here will be ignored from object construction traversal.
52
59
  }
53
- } )
60
+ })
54
61
 
55
- let obj = await loader.getAndConstructObject( ( e ) => console.log( 'Progress', e ) )
62
+ let obj = await loader.getAndConstructObject((e) => console.log('Progress', e))
63
+ ```
56
64
 
57
65
  ### On the server
58
66
 
59
67
  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.
60
68
 
61
69
  ```js
70
+ import ObjectLoader from '@speckle/objectloader'
62
71
  import { fetch } from 'undici'
63
72
 
64
73
  let loader = new ObjectLoader({
65
74
  serverUrl: 'https://latest.speckle.dev',
66
75
  streamId: '3ed8357f29',
67
76
  objectId: '0408ab9caaa2ebefb2dd7f1f671e7555',
68
- options: { enableCaching: false, excludeProps: [], fetch },
77
+ options: { enableCaching: false, excludeProps: [], fetch }
69
78
  })
70
- ````
79
+ ```
80
+
81
+ ## Development
82
+
83
+ Run `npm run build` to build prod release, run `npm run build:dev` to build dev release. Or run `npm run dev` to run the build in `watch` mode.
71
84
 
72
85
  ## Community
73
86
 
@@ -0,0 +1,66 @@
1
+ import commonjs from '@rollup/plugin-commonjs'
2
+ import nodeResolve from '@rollup/plugin-node-resolve'
3
+ import { terser } from 'rollup-plugin-terser'
4
+ import { babel } from '@rollup/plugin-babel'
5
+ import clean from 'rollup-plugin-delete'
6
+ import pkg from './package.json'
7
+
8
+ const isProd = process.env.NODE_ENV === 'production'
9
+ const isExample = !!process.env.EXAMPLE_BUILD
10
+
11
+ const sourcemap = isProd ? false : 'inline'
12
+
13
+ /**
14
+ * Build config
15
+ * @param {boolean} isWebBuild If set to true will generate a web-ready config with everything bundled into a single file
16
+ * @returns {import('rollup').RollupOptions}
17
+ */
18
+ function buildConfig(isWebBuild = false) {
19
+ /** @type {import('rollup').RollupOptions} */
20
+ const config = {
21
+ input: 'src/index.js',
22
+ output: [
23
+ {
24
+ file: isWebBuild
25
+ ? 'examples/browser/objectloader.web.js'
26
+ : 'dist/objectloader.esm.js',
27
+ format: 'esm',
28
+ sourcemap,
29
+ exports: 'default'
30
+ },
31
+ ...(isWebBuild
32
+ ? []
33
+ : [
34
+ {
35
+ file: 'dist/objectloader.js',
36
+ format: 'cjs',
37
+ sourcemap,
38
+ exports: 'default'
39
+ }
40
+ ])
41
+ ],
42
+ plugins: [
43
+ ...(isWebBuild
44
+ ? [
45
+ // Bundling in all deps in web build
46
+ commonjs(),
47
+ nodeResolve()
48
+ ]
49
+ : [
50
+ // Cleaning dir only inside 'dist'
51
+ clean({ targets: 'dist/*' })
52
+ ]),
53
+ babel({ babelHelpers: 'bundled' }),
54
+ ...(isProd ? [terser()] : [])
55
+ ],
56
+ external: isWebBuild
57
+ ? undefined
58
+ : // In non web build we don't want to bundle in any deps
59
+ Object.keys(pkg.dependencies || {}).map((d) => new RegExp(`^${d}(\\/.*)?$`))
60
+ }
61
+
62
+ return config
63
+ }
64
+
65
+ const config = isExample ? buildConfig(true) : buildConfig()
66
+ export default config
@@ -1,3 +1,7 @@
1
+ // POLYFILLS
2
+ import 'core-js'
3
+ import 'regenerator-runtime/runtime'
4
+
1
5
  /**
2
6
  * Simple client that streams object info from a Speckle Server.
3
7
  * TODO: Object construction progress reporting is weird.