@speckle/objectloader 2.4.0 → 2.4.2-alpha.0

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/.eslintrc.cjs ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Extends repo root config, only put changes here that are scoped to this specific package
3
+ * (if you already are - evaluate whether you really need package scoped linting rules)
4
+ */
5
+
6
+ /** @type {import("eslint").Linter.Config} */
7
+ const config = {
8
+ env: {
9
+ browser: true
10
+ },
11
+ parserOptions: {
12
+ sourceType: 'module'
13
+ }
14
+ }
15
+
16
+ module.exports = config
package/LICENSE ADDED
@@ -0,0 +1,208 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2020 AEC Systems
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
203
+ NOTICE: Unless otherwise described, the code in this repository is
204
+ licensed under the license above. Some modules, extensions or code herein
205
+ might be otherwise licensed. This is indicated either in the root of the
206
+ containing folder under a different license file, or in the respective
207
+ file's header. If you have any questions, don't hesitate to get in touch
208
+ with us via [email](mailto:hello@speckle.systems).
@@ -1,19 +1,21 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en" class="no-js">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width" />
3
6
 
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta name="viewport" content="width=device-width">
7
+ <title>Object Loader Test</title>
8
+ </head>
7
9
 
8
- <title>Object Loader Test</title>
9
- </head>
10
+ <body>
11
+ <h1>This is a test.</h1>
12
+ <p>All the magic is in the console.</p>
13
+ <p>
14
+ To ensure this example runs correctly, please serve this file from a local http
15
+ server - if you manually open the file in a browser, it might not work.
16
+ </p>
17
+ <button onclick="loadData()">PRESS ME</button>
18
+ </body>
10
19
 
11
- <body>
12
- <h1>This is a test.</h1>
13
- <p>All the magic is in the console.</p>
14
- <p>To ensure this example runs correctly, please serve this file from a local http server - if you manually open the file in a browser, it might not work.</p>
15
- <button onclick="loadData()">PRESS ME</button>
16
- </body>
17
-
18
20
  <script src="script.js" type="module"></script>
19
- </html>
21
+ </html>
@@ -9,25 +9,23 @@ window.ObjectLoader = ObjectLoader
9
9
 
10
10
  // https://latest.speckle.dev/streams/92b620fb17/objects/7cd9d41b5b5f3c8908536aec2a05f1a1
11
11
  // let loader = new ObjectLoader({
12
- // serverUrl:"https://latest.speckle.dev",
13
- // streamId:"92b620fb17",
12
+ // serverUrl:"https://latest.speckle.dev",
13
+ // streamId:"92b620fb17",
14
14
  // objectId:"878c426bb213ddb4d580da74922a2b16"
15
15
  // })
16
16
 
17
17
  // https://latest.speckle.dev/streams/3ed8357f29/objects/0408ab9caaa2ebefb2dd7f1f671e7555
18
- let loader = new ObjectLoader({
19
- serverUrl:"https://latest.speckle.dev",
20
- streamId:"3ed8357f29",
21
- objectId:"0408ab9caaa2ebefb2dd7f1f671e7555"
18
+ const loader = new ObjectLoader({
19
+ serverUrl: 'https://latest.speckle.dev',
20
+ streamId: '3ed8357f29',
21
+ objectId: '0408ab9caaa2ebefb2dd7f1f671e7555'
22
22
  })
23
23
 
24
-
25
24
  window.loadData = async function loadData() {
26
-
27
- let obj = await loader.getAndConstructObject((e) =>{
25
+ const obj = await loader.getAndConstructObject((e) => {
28
26
  console.log(e) // log progress!
29
27
  })
30
28
 
31
29
  console.log('Done!')
32
- console.log( obj )
33
- }
30
+ console.log(obj)
31
+ }
@@ -3,22 +3,20 @@
3
3
  import { fetch } from 'undici'
4
4
  import ObjectLoader from '../../index.js'
5
5
 
6
- let loader = new ObjectLoader({
7
- serverUrl:"https://latest.speckle.dev",
8
- streamId:"3ed8357f29",
9
- objectId:"0408ab9caaa2ebefb2dd7f1f671e7555",
10
- options:{ enableCaching: false, excludeProps:[], fetch }
6
+ const loader = new ObjectLoader({
7
+ serverUrl: 'https://latest.speckle.dev',
8
+ streamId: '3ed8357f29',
9
+ objectId: '0408ab9caaa2ebefb2dd7f1f671e7555',
10
+ options: { enableCaching: false, excludeProps: [], fetch }
11
11
  })
12
12
 
13
-
14
- let loadData = async function loadData() {
15
-
16
- let obj = await loader.getAndConstructObject((e) =>{
13
+ const loadData = async function loadData() {
14
+ const obj = await loader.getAndConstructObject((e) => {
17
15
  console.log(e) // log progress!
18
16
  })
19
17
 
20
18
  console.log('Done!')
21
- console.log( obj )
19
+ console.log(obj)
22
20
  }
23
21
 
24
22
  loadData()
package/index.js CHANGED
@@ -3,14 +3,23 @@
3
3
  * TODO: Object construction progress reporting is weird.
4
4
  */
5
5
 
6
-
7
6
  export default class ObjectLoader {
8
-
9
7
  /**
10
8
  * Creates a new object loader instance.
11
9
  * @param {*} param0
12
10
  */
13
- constructor( { serverUrl, streamId, token, objectId, options = { enableCaching: true, fullyTraverseArrays: false, excludeProps: [ ], fetch:null } } ) {
11
+ constructor({
12
+ serverUrl,
13
+ streamId,
14
+ token,
15
+ objectId,
16
+ options = {
17
+ enableCaching: true,
18
+ fullyTraverseArrays: false,
19
+ excludeProps: [],
20
+ fetch: null
21
+ }
22
+ }) {
14
23
  this.INTERVAL_MS = 20
15
24
  this.TIMEOUT_MS = 180000 // three mins
16
25
 
@@ -19,16 +28,16 @@ export default class ObjectLoader {
19
28
  this.objectId = objectId
20
29
  console.log('Object loader constructor called!')
21
30
  try {
22
- this.token = token || localStorage.getItem( 'AuthToken' )
31
+ this.token = token || localStorage.getItem('AuthToken')
23
32
  } catch (error) {
24
- // Accessing localStorage may throw when executing on sandboxed document, ignore.
33
+ // Accessing localStorage may throw when executing on sandboxed document, ignore.
25
34
  }
26
35
 
27
36
  this.headers = {
28
- 'Accept': 'text/plain'
37
+ Accept: 'text/plain'
29
38
  }
30
39
 
31
- if( this.token ) {
40
+ if (this.token) {
32
41
  this.headers['Authorization'] = `Bearer ${this.token}`
33
42
  }
34
43
 
@@ -48,13 +57,13 @@ export default class ObjectLoader {
48
57
  this.lastAsyncPause = Date.now()
49
58
  this.existingAsyncPause = null
50
59
 
51
- // we can't simply bind fetch to this.fetch, so instead we have to do some acrobatics: https://stackoverflow.com/questions/69337187/uncaught-in-promise-typeerror-failed-to-execute-fetch-on-workerglobalscope#comment124731316_69337187
60
+ // we can't simply bind fetch to this.fetch, so instead we have to do some acrobatics:
61
+ // https://stackoverflow.com/questions/69337187/uncaught-in-promise-typeerror-failed-to-execute-fetch-on-workerglobalscope#comment124731316_69337187
52
62
  this.preferredFetch = options.fetch
53
- this.fetch = function(...args) {
54
- let currentFetch = this.preferredFetch || fetch
63
+ this.fetch = function (...args) {
64
+ const currentFetch = this.preferredFetch || fetch
55
65
  return currentFetch(...args)
56
66
  }
57
-
58
67
  }
59
68
 
60
69
  async asyncPause() {
@@ -62,19 +71,19 @@ export default class ObjectLoader {
62
71
  // while ( this.existingAsyncPause ) {
63
72
  // await this.existingAsyncPause
64
73
  // }
65
- if ( Date.now() - this.lastAsyncPause >= 100 ) {
74
+ if (Date.now() - this.lastAsyncPause >= 100) {
66
75
  this.lastAsyncPause = Date.now()
67
- this.existingAsyncPause = new Promise( resolve => setTimeout( resolve, 0 ) )
76
+ this.existingAsyncPause = new Promise((resolve) => setTimeout(resolve, 0))
68
77
  await this.existingAsyncPause
69
78
  this.existingAsyncPause = null
70
- if (Date.now() - this.lastAsyncPause > 500) console.log("Loader Event loop lag: ", Date.now() - this.lastAsyncPause)
79
+ if (Date.now() - this.lastAsyncPause > 500)
80
+ console.log('Loader Event loop lag: ', Date.now() - this.lastAsyncPause)
71
81
  }
72
-
73
82
  }
74
83
 
75
84
  dispose() {
76
85
  this.buffer = []
77
- this.intervals.forEach( i => clearInterval( i.interval ) )
86
+ this.intervals.forEach((i) => clearInterval(i.interval))
78
87
  }
79
88
 
80
89
  /**
@@ -82,30 +91,34 @@ export default class ObjectLoader {
82
91
  * @param {*} onProgress
83
92
  * @returns
84
93
  */
85
- async getAndConstructObject( onProgress ) {
86
-
87
- ;( await this.downloadObjectsInBuffer( onProgress ) ) // Fire and forget; PS: semicolon of doom
94
+ async getAndConstructObject(onProgress) {
95
+ await this.downloadObjectsInBuffer(onProgress) // Fire and forget; PS: semicolon of doom
88
96
 
89
- let rootObject = await this.getObject( this.objectId )
90
- return this.traverseAndConstruct( rootObject, onProgress )
97
+ const rootObject = await this.getObject(this.objectId)
98
+ return this.traverseAndConstruct(rootObject, onProgress)
91
99
  }
92
100
 
93
101
  /**
94
102
  * Internal function used to download all the objects in a local buffer.
95
103
  * @param {*} onProgress
96
104
  */
97
- async downloadObjectsInBuffer( onProgress ) {
105
+ async downloadObjectsInBuffer(onProgress) {
98
106
  let first = true
99
107
  let downloadNum = 0
100
108
 
101
- for await ( let obj of this.getObjectIterator() ) {
102
- if( first ) {
109
+ for await (const obj of this.getObjectIterator()) {
110
+ if (first) {
103
111
  this.totalChildrenCount = obj.totalChildrenCount
104
112
  first = false
105
113
  this.isLoading = true
106
114
  }
107
115
  downloadNum++
108
- if( onProgress ) onProgress( { stage: 'download', current: downloadNum, total: this.totalChildrenCount } )
116
+ if (onProgress)
117
+ onProgress({
118
+ stage: 'download',
119
+ current: downloadNum,
120
+ total: this.totalChildrenCount
121
+ })
109
122
  }
110
123
  this.isLoading = false
111
124
  }
@@ -116,51 +129,69 @@ export default class ObjectLoader {
116
129
  * @param {*} onProgress
117
130
  * @returns
118
131
  */
119
- async traverseAndConstruct( obj, onProgress ) {
120
- if( !obj ) return
121
- if ( typeof obj !== 'object' ) return obj
132
+ async traverseAndConstruct(obj, onProgress) {
133
+ if (!obj) return
134
+ if (typeof obj !== 'object') return obj
122
135
 
123
136
  // Handle arrays
124
- if ( Array.isArray( obj ) && obj.length !== 0 ) {
125
- let arr = []
126
- for ( let element of obj ) {
127
- if ( typeof element !== 'object' && ! this.options.fullyTraverseArrays ) return obj
137
+ if (Array.isArray(obj) && obj.length !== 0) {
138
+ const arr = []
139
+ for (const element of obj) {
140
+ if (typeof element !== 'object' && !this.options.fullyTraverseArrays) return obj
128
141
 
129
142
  // Dereference element if needed
130
- let deRef = element.referencedId ? await this.getObject( element.referencedId ) : element
131
- if( element.referencedId && onProgress ) onProgress( { stage: 'construction', current: ++this.traversedReferencesCount > this.totalChildrenCount ? this.totalChildrenCount : this.traversedReferencesCount, total: this.totalChildrenCount } )
143
+ const deRef = element.referencedId
144
+ ? await this.getObject(element.referencedId)
145
+ : element
146
+ if (element.referencedId && onProgress)
147
+ onProgress({
148
+ stage: 'construction',
149
+ current:
150
+ ++this.traversedReferencesCount > this.totalChildrenCount
151
+ ? this.totalChildrenCount
152
+ : this.traversedReferencesCount,
153
+ total: this.totalChildrenCount
154
+ })
132
155
 
133
156
  // Push the traversed object in the array
134
- arr.push( await this.traverseAndConstruct( deRef, onProgress ) )
157
+ arr.push(await this.traverseAndConstruct(deRef, onProgress))
135
158
  }
136
159
 
137
160
  // De-chunk
138
- if( arr[0]?.speckle_type?.toLowerCase().includes('datachunk') ) {
139
- return arr.reduce( ( prev, curr ) => prev.concat( curr.data ), [] )
161
+ if (arr[0]?.speckle_type?.toLowerCase().includes('datachunk')) {
162
+ return arr.reduce((prev, curr) => prev.concat(curr.data), [])
140
163
  }
141
164
 
142
165
  return arr
143
- }
166
+ }
144
167
 
145
168
  // Handle objects
146
169
  // 1) Purge ignored props
147
- for( let ignoredProp of this.options.excludeProps ) {
148
- delete obj[ ignoredProp ]
170
+ for (const ignoredProp of this.options.excludeProps) {
171
+ delete obj[ignoredProp]
149
172
  }
150
173
 
151
174
  // 2) Iterate through obj
152
- for( let prop in obj ) {
153
- if( typeof obj[prop] !== 'object' || obj[prop] === null ) continue // leave alone primitive props
154
-
155
- if( obj[prop].referencedId ) {
156
- obj[prop] = await this.getObject( obj[prop].referencedId )
157
- if( onProgress ) onProgress( { stage: 'construction', current: ++this.traversedReferencesCount > this.totalChildrenCount ? this.totalChildrenCount : this.traversedReferencesCount, total: this.totalChildrenCount } )
175
+ for (const prop in obj) {
176
+ if (typeof obj[prop] !== 'object' || obj[prop] === null) continue // leave alone primitive props
177
+
178
+ if (obj[prop].referencedId) {
179
+ obj[prop] = await this.getObject(obj[prop].referencedId)
180
+ if (onProgress)
181
+ onProgress({
182
+ stage: 'construction',
183
+ current:
184
+ ++this.traversedReferencesCount > this.totalChildrenCount
185
+ ? this.totalChildrenCount
186
+ : this.traversedReferencesCount,
187
+ total: this.totalChildrenCount
188
+ })
158
189
  }
159
190
 
160
- obj[prop] = await this.traverseAndConstruct( obj[prop], onProgress )
191
+ obj[prop] = await this.traverseAndConstruct(obj[prop], onProgress)
161
192
  }
162
193
 
163
- return obj
194
+ return obj
164
195
  }
165
196
 
166
197
  /**
@@ -168,68 +199,71 @@ export default class ObjectLoader {
168
199
  * @param {*} id
169
200
  * @returns
170
201
  */
171
- async getObject( id ){
172
- if ( this.buffer[id] ) return this.buffer[id]
202
+ async getObject(id) {
203
+ if (this.buffer[id]) return this.buffer[id]
173
204
 
174
- let promise = new Promise( ( resolve, reject ) => {
175
- this.promises.push( { id, resolve, reject } )
205
+ const promise = new Promise((resolve, reject) => {
206
+ this.promises.push({ id, resolve, reject })
176
207
  // Only create a new interval checker if none is already present!
177
- if ( this.intervals[id] ) {
208
+ if (this.intervals[id]) {
178
209
  this.intervals[id].elapsed = 0 // reset elapsed
179
210
  } else {
180
- let intervalId = setInterval( this.tryResolvePromise.bind( this ), this.INTERVAL_MS, id )
211
+ const intervalId = setInterval(
212
+ this.tryResolvePromise.bind(this),
213
+ this.INTERVAL_MS,
214
+ id
215
+ )
181
216
  this.intervals[id] = { interval: intervalId, elapsed: 0 }
182
217
  }
183
- } )
218
+ })
184
219
  return promise
185
220
  }
186
221
 
187
- tryResolvePromise( id ) {
222
+ tryResolvePromise(id) {
188
223
  this.intervals[id].elapsed += this.INTERVAL_MS
189
- if ( this.buffer[id] ) {
190
- for ( let p of this.promises.filter( p => p.id === id ) ) {
191
- p.resolve( this.buffer[id] )
224
+ if (this.buffer[id]) {
225
+ for (const p of this.promises.filter((p) => p.id === id)) {
226
+ p.resolve(this.buffer[id])
192
227
  }
193
228
 
194
- clearInterval( this.intervals[id].interval )
229
+ clearInterval(this.intervals[id].interval)
195
230
  delete this.intervals[id]
196
231
  // this.promises = this.promises.filter( p => p.id !== p.id ) // clearing out promises too early seems to nuke loading
197
232
  return
198
233
  }
199
234
 
200
- if ( this.intervals[id].elapsed > this.TIMEOUT_MS ) {
201
- console.warn( `Timeout resolving ${id}. HIC SVNT DRACONES.` )
202
- clearInterval( this.intervals[id].interval )
203
- this.promises.filter( p => p.id === id ).forEach( p => p.reject() )
204
- this.promises = this.promises.filter( p => p.id !== p.id ) // clear out
235
+ if (this.intervals[id].elapsed > this.TIMEOUT_MS) {
236
+ console.warn(`Timeout resolving ${id}. HIC SVNT DRACONES.`)
237
+ clearInterval(this.intervals[id].interval)
238
+ this.promises.filter((p) => p.id === id).forEach((p) => p.reject())
239
+ this.promises = this.promises.filter((p) => p.id !== p.id) // clear out
205
240
  }
206
241
  }
207
242
 
208
- async * getObjectIterator( ) {
209
- let t0 = Date.now()
243
+ async *getObjectIterator() {
244
+ const t0 = Date.now()
210
245
  let count = 0
211
- for await ( let line of this.getRawObjectIterator() ) {
212
- let { id, obj } = this.processLine( line )
213
- this.buffer[ id ] = obj
246
+ for await (const line of this.getRawObjectIterator()) {
247
+ const { id, obj } = this.processLine(line)
248
+ this.buffer[id] = obj
214
249
  count += 1
215
250
  yield obj
216
251
  }
217
252
  console.log(`Loaded ${count} objects in: ${(Date.now() - t0) / 1000}`)
218
253
  }
219
254
 
220
- processLine( chunk ) {
221
- var pieces = chunk.split( '\t' )
222
- return { id: pieces[0], obj: JSON.parse( pieces[1] ) }
255
+ processLine(chunk) {
256
+ const pieces = chunk.split('\t')
257
+ return { id: pieces[0], obj: JSON.parse(pieces[1]) }
223
258
  }
224
259
 
225
- async * getRawObjectIterator() {
226
- let tSTART = Date.now()
227
-
228
- if ( this.options.enableCaching && window.indexedDB && this.cacheDB === null) {
260
+ async *getRawObjectIterator() {
261
+ if (this.options.enableCaching && window.indexedDB && this.cacheDB === null) {
229
262
  await safariFix()
230
- let idbOpenRequest = indexedDB.open('speckle-object-cache', 1)
231
- idbOpenRequest.onupgradeneeded = () => idbOpenRequest.result.createObjectStore('objects');
232
- this.cacheDB = await this.promisifyIdbRequest( idbOpenRequest )
263
+ const idbOpenRequest = indexedDB.open('speckle-object-cache', 1)
264
+ idbOpenRequest.onupgradeneeded = () =>
265
+ idbOpenRequest.result.createObjectStore('objects')
266
+ this.cacheDB = await this.promisifyIdbRequest(idbOpenRequest)
233
267
  }
234
268
 
235
269
  const rootObjJson = await this.getRawRootObject()
@@ -238,162 +272,171 @@ export default class ObjectLoader {
238
272
  yield `${this.objectId}\t${rootObjJson}`
239
273
 
240
274
  const rootObj = JSON.parse(rootObjJson)
241
- if ( !rootObj.__closure ) return
275
+ if (!rootObj.__closure) return
242
276
 
243
- let childrenIds = Object.keys(rootObj.__closure).sort( (a, b) => rootObj.__closure[a] - rootObj.__closure[b] )
244
- if ( childrenIds.length === 0 ) return
277
+ let childrenIds = Object.keys(rootObj.__closure).sort(
278
+ (a, b) => rootObj.__closure[a] - rootObj.__closure[b]
279
+ )
280
+ if (childrenIds.length === 0) return
245
281
 
246
282
  let splitHttpRequests = []
247
283
 
248
- if ( childrenIds.length > 50 ) {
284
+ if (childrenIds.length > 50) {
249
285
  // split into 5%, 15%, 40%, 40% (5% for the high priority children: the ones with lower minDepth)
250
- let splitBeforeCacheCheck = [ [], [], [], [] ]
286
+ const splitBeforeCacheCheck = [[], [], [], []]
251
287
  let crtChildIndex = 0
252
288
 
253
- for ( ; crtChildIndex < 0.05 * childrenIds.length; crtChildIndex++ ) {
254
- splitBeforeCacheCheck[0].push( childrenIds[ crtChildIndex ] )
289
+ for (; crtChildIndex < 0.05 * childrenIds.length; crtChildIndex++) {
290
+ splitBeforeCacheCheck[0].push(childrenIds[crtChildIndex])
255
291
  }
256
- for ( ; crtChildIndex < 0.2 * childrenIds.length; crtChildIndex++ ) {
257
- splitBeforeCacheCheck[1].push( childrenIds[ crtChildIndex ] )
292
+ for (; crtChildIndex < 0.2 * childrenIds.length; crtChildIndex++) {
293
+ splitBeforeCacheCheck[1].push(childrenIds[crtChildIndex])
258
294
  }
259
- for ( ; crtChildIndex < 0.6 * childrenIds.length; crtChildIndex++ ) {
260
- splitBeforeCacheCheck[2].push( childrenIds[ crtChildIndex ] )
295
+ for (; crtChildIndex < 0.6 * childrenIds.length; crtChildIndex++) {
296
+ splitBeforeCacheCheck[2].push(childrenIds[crtChildIndex])
261
297
  }
262
- for ( ; crtChildIndex < childrenIds.length; crtChildIndex++ ) {
263
- splitBeforeCacheCheck[3].push( childrenIds[ crtChildIndex ] )
298
+ for (; crtChildIndex < childrenIds.length; crtChildIndex++) {
299
+ splitBeforeCacheCheck[3].push(childrenIds[crtChildIndex])
264
300
  }
265
301
 
302
+ console.log('Cache check for: ', splitBeforeCacheCheck)
266
303
 
267
- console.log("Cache check for: ", splitBeforeCacheCheck)
304
+ const newChildren = []
305
+ let nextCachePromise = this.cacheGetObjects(splitBeforeCacheCheck[0])
268
306
 
269
- let newChildren = []
270
- let nextCachePromise = this.cacheGetObjects( splitBeforeCacheCheck[ 0 ] )
307
+ for (let i = 0; i < 4; i++) {
308
+ const cachedObjects = await nextCachePromise
309
+ if (i < 3) nextCachePromise = this.cacheGetObjects(splitBeforeCacheCheck[i + 1])
271
310
 
272
- for ( let i = 0; i < 4; i++ ) {
273
- let cachedObjects = await nextCachePromise
274
- if ( i < 3 ) nextCachePromise = this.cacheGetObjects( splitBeforeCacheCheck[ i + 1 ] )
275
-
276
- let sortedCachedKeys = Object.keys(cachedObjects).sort( (a, b) => rootObj.__closure[a] - rootObj.__closure[b] )
277
- for ( let id of sortedCachedKeys ) {
278
- yield `${id}\t${cachedObjects[ id ]}`
311
+ const sortedCachedKeys = Object.keys(cachedObjects).sort(
312
+ (a, b) => rootObj.__closure[a] - rootObj.__closure[b]
313
+ )
314
+ for (const id of sortedCachedKeys) {
315
+ yield `${id}\t${cachedObjects[id]}`
279
316
  }
280
- let newChildrenForBatch = splitBeforeCacheCheck[i].filter( id => !( id in cachedObjects ) )
281
- newChildren.push( ...newChildrenForBatch )
317
+ const newChildrenForBatch = splitBeforeCacheCheck[i].filter(
318
+ (id) => !(id in cachedObjects)
319
+ )
320
+ newChildren.push(...newChildrenForBatch)
282
321
  }
283
322
 
284
- if ( newChildren.length === 0 ) return
323
+ if (newChildren.length === 0) return
285
324
 
286
- if ( newChildren.length <= 50 ) {
325
+ if (newChildren.length <= 50) {
287
326
  // we have almost all of children in the cache. do only 1 requests for the remaining new children
288
- splitHttpRequests.push( newChildren )
327
+ splitHttpRequests.push(newChildren)
289
328
  } else {
290
329
  // we now set up the batches for 4 http requests, starting from `newChildren` (already sorted by priority)
291
- splitHttpRequests = [ [], [], [], [] ]
330
+ splitHttpRequests = [[], [], [], []]
292
331
  crtChildIndex = 0
293
332
 
294
- for ( ; crtChildIndex < 0.05 * newChildren.length; crtChildIndex++ ) {
295
- splitHttpRequests[0].push( newChildren[ crtChildIndex ] )
333
+ for (; crtChildIndex < 0.05 * newChildren.length; crtChildIndex++) {
334
+ splitHttpRequests[0].push(newChildren[crtChildIndex])
296
335
  }
297
- for ( ; crtChildIndex < 0.2 * newChildren.length; crtChildIndex++ ) {
298
- splitHttpRequests[1].push( newChildren[ crtChildIndex ] )
336
+ for (; crtChildIndex < 0.2 * newChildren.length; crtChildIndex++) {
337
+ splitHttpRequests[1].push(newChildren[crtChildIndex])
299
338
  }
300
- for ( ; crtChildIndex < 0.6 * newChildren.length; crtChildIndex++ ) {
301
- splitHttpRequests[2].push( newChildren[ crtChildIndex ] )
339
+ for (; crtChildIndex < 0.6 * newChildren.length; crtChildIndex++) {
340
+ splitHttpRequests[2].push(newChildren[crtChildIndex])
302
341
  }
303
- for ( ; crtChildIndex < newChildren.length; crtChildIndex++ ) {
304
- splitHttpRequests[3].push( newChildren[ crtChildIndex ] )
342
+ for (; crtChildIndex < newChildren.length; crtChildIndex++) {
343
+ splitHttpRequests[3].push(newChildren[crtChildIndex])
305
344
  }
306
345
  }
307
-
308
346
  } else {
309
347
  // small object with <= 50 children. check cache and make only 1 request
310
- const cachedObjects = await this.cacheGetObjects( childrenIds )
311
- let sortedCachedKeys = Object.keys(cachedObjects).sort( (a, b) => rootObj.__closure[a] - rootObj.__closure[b] )
312
- for ( let id of sortedCachedKeys ) {
313
- yield `${id}\t${cachedObjects[ id ]}`
348
+ const cachedObjects = await this.cacheGetObjects(childrenIds)
349
+ const sortedCachedKeys = Object.keys(cachedObjects).sort(
350
+ (a, b) => rootObj.__closure[a] - rootObj.__closure[b]
351
+ )
352
+ for (const id of sortedCachedKeys) {
353
+ yield `${id}\t${cachedObjects[id]}`
314
354
  }
315
- childrenIds = childrenIds.filter(id => !( id in cachedObjects ) )
316
- if ( childrenIds.length === 0 ) return
355
+ childrenIds = childrenIds.filter((id) => !(id in cachedObjects))
356
+ if (childrenIds.length === 0) return
317
357
 
318
358
  // only 1 http request with the remaining children ( <= 50 )
319
- splitHttpRequests.push( childrenIds )
359
+ splitHttpRequests.push(childrenIds)
320
360
  }
321
361
 
322
362
  // Starting http requests for batches in `splitHttpRequests`
323
363
 
324
364
  const decoders = []
325
365
  const readers = []
326
- const readPromisses = []
366
+ const readPromises = []
327
367
  const startIndexes = []
328
368
  const readBuffers = []
329
369
  const finishedRequests = []
330
370
 
331
371
  for (let i = 0; i < splitHttpRequests.length; i++) {
332
372
  decoders.push(new TextDecoder())
333
- readers.push( null )
334
- readPromisses.push( null )
335
- startIndexes.push( 0 )
336
- readBuffers.push( '' )
337
- finishedRequests.push( false )
338
-
339
- this.fetch(
340
- this.requestUrlChildren,
341
- {
342
- method: 'POST',
343
- headers: { ...this.headers, 'Content-Type': 'application/json' },
344
- body: JSON.stringify( { objects: JSON.stringify( splitHttpRequests[i] ) } )
345
- }
346
- ).then( crtResponse => {
347
- let crtReader = crtResponse.body.getReader()
373
+ readers.push(null)
374
+ readPromises.push(null)
375
+ startIndexes.push(0)
376
+ readBuffers.push('')
377
+ finishedRequests.push(false)
378
+
379
+ this.fetch(this.requestUrlChildren, {
380
+ method: 'POST',
381
+ headers: { ...this.headers, 'Content-Type': 'application/json' },
382
+ body: JSON.stringify({ objects: JSON.stringify(splitHttpRequests[i]) })
383
+ }).then((crtResponse) => {
384
+ const crtReader = crtResponse.body.getReader()
348
385
  readers[i] = crtReader
349
- let crtReadPromise = crtReader.read().then(x => { x.reqId = i; return x })
350
- readPromisses[i] = crtReadPromise
386
+ const crtReadPromise = crtReader.read().then((x) => {
387
+ x.reqId = i
388
+ return x
389
+ })
390
+ readPromises[i] = crtReadPromise
351
391
  })
352
392
  }
353
393
 
354
- while ( true ) {
355
- let validReadPromises = readPromisses.filter(x => x != null)
356
- if ( validReadPromises.length === 0 ) {
394
+ while (true) {
395
+ const validReadPromises = readPromises.filter((x) => !!x)
396
+ if (validReadPromises.length === 0) {
357
397
  // Check if all requests finished
358
- if ( finishedRequests.every(x => x) ) {
398
+ if (finishedRequests.every((x) => x)) {
359
399
  break
360
400
  }
361
401
  // Sleep 10 ms
362
- await new Promise( ( resolve ) => {
363
- setTimeout( resolve, 10 )
364
- } )
402
+ await new Promise((resolve) => {
403
+ setTimeout(resolve, 10)
404
+ })
365
405
  continue
366
406
  }
367
407
 
368
408
  // Wait for data on any running request
369
- let data = await Promise.any( validReadPromises )
409
+ const data = await Promise.any(validReadPromises)
410
+ // eslint-disable-next-line prefer-const
370
411
  let { value: crtDataChunk, done: readerDone, reqId } = data
371
- finishedRequests[ reqId ] = readerDone
412
+ finishedRequests[reqId] = readerDone
372
413
 
373
414
  // Replace read promise on this request with a new `read` call
374
- if ( !readerDone ) {
375
- let crtReadPromise = readers[ reqId ].read().then(x => { x.reqId = reqId; return x })
376
- readPromisses[ reqId ] = crtReadPromise
415
+ if (!readerDone) {
416
+ const crtReadPromise = readers[reqId].read().then((x) => {
417
+ x.reqId = reqId
418
+ return x
419
+ })
420
+ readPromises[reqId] = crtReadPromise
377
421
  } else {
378
422
  // This request finished. "Flush any non-newline-terminated text"
379
- if ( readBuffers[ reqId ].length > 0 ) {
380
- yield readBuffers[ reqId ]
381
- readBuffers[ reqId ] = ''
423
+ if (readBuffers[reqId].length > 0) {
424
+ yield readBuffers[reqId]
425
+ readBuffers[reqId] = ''
382
426
  }
383
427
  // no other read calls for this request
384
- readPromisses[ reqId ] = null
428
+ readPromises[reqId] = null
385
429
  }
386
430
 
387
- if ( !crtDataChunk )
388
- continue
431
+ if (!crtDataChunk) continue
389
432
 
390
- crtDataChunk = decoders[ reqId ].decode( crtDataChunk )
391
- let unprocessedText = readBuffers[ reqId ] + crtDataChunk
392
- let unprocessedLines = unprocessedText.split(/\r\n|\n|\r/)
393
- let remainderText = unprocessedLines.pop()
394
- readBuffers[ reqId ] = remainderText
433
+ crtDataChunk = decoders[reqId].decode(crtDataChunk)
434
+ const unprocessedText = readBuffers[reqId] + crtDataChunk
435
+ const unprocessedLines = unprocessedText.split(/\r\n|\n|\r/)
436
+ const remainderText = unprocessedLines.pop()
437
+ readBuffers[reqId] = remainderText
395
438
 
396
- for ( let line of unprocessedLines ) {
439
+ for (const line of unprocessedLines) {
397
440
  yield line
398
441
  }
399
442
  this.cacheStoreObjects(unprocessedLines)
@@ -401,43 +444,46 @@ export default class ObjectLoader {
401
444
  }
402
445
 
403
446
  async getRawRootObject() {
404
- const cachedRootObject = await this.cacheGetObjects( [ this.objectId ] )
405
- if ( cachedRootObject[ this.objectId ] )
406
- return cachedRootObject[ this.objectId ]
407
- const response = await this.fetch( this.requestUrlRootObj, { headers: this.headers } )
447
+ const cachedRootObject = await this.cacheGetObjects([this.objectId])
448
+ if (cachedRootObject[this.objectId]) return cachedRootObject[this.objectId]
449
+ const response = await this.fetch(this.requestUrlRootObj, { headers: this.headers })
408
450
  const responseText = await response.text()
409
- this.cacheStoreObjects( [ `${this.objectId}\t${responseText}` ] )
451
+ this.cacheStoreObjects([`${this.objectId}\t${responseText}`])
410
452
  return responseText
411
453
  }
412
454
 
413
455
  promisifyIdbRequest(request) {
414
456
  return new Promise((resolve, reject) => {
415
- request.oncomplete = request.onsuccess = () => resolve(request.result);
416
- request.onabort = request.onerror = () => reject(request.error);
457
+ request.oncomplete = request.onsuccess = () => resolve(request.result)
458
+ request.onabort = request.onerror = () => reject(request.error)
417
459
  })
418
460
  }
419
461
 
420
462
  async cacheGetObjects(ids) {
421
- if ( !this.options.enableCaching || !window.indexedDB ) {
463
+ if (!this.options.enableCaching || !window.indexedDB) {
422
464
  return {}
423
465
  }
424
466
 
425
- let ret = {}
467
+ const ret = {}
426
468
 
427
469
  for (let i = 0; i < ids.length; i += 500) {
428
- let idsChunk = ids.slice(i, i + 500)
429
- let t0 = Date.now()
470
+ const idsChunk = ids.slice(i, i + 500)
430
471
 
431
- let store = this.cacheDB.transaction('objects', 'readonly').objectStore('objects')
432
- let idbChildrenPromises = idsChunk.map( id => this.promisifyIdbRequest( store.get( id ) ).then( data => ( { id, data } ) ) )
433
- let cachedData = await Promise.all(idbChildrenPromises)
472
+ const store = this.cacheDB
473
+ .transaction('objects', 'readonly')
474
+ .objectStore('objects')
475
+ const idbChildrenPromises = idsChunk.map((id) =>
476
+ this.promisifyIdbRequest(store.get(id)).then((data) => ({ id, data }))
477
+ )
478
+ const cachedData = await Promise.all(idbChildrenPromises)
434
479
 
435
480
  // console.log("Cache check for : ", idsChunk.length, Date.now() - t0)
436
481
 
437
- for ( let cachedObj of cachedData ) {
438
- if ( !cachedObj.data ) // non-existent objects are retrieved with `undefined` data
482
+ for (const cachedObj of cachedData) {
483
+ if (!cachedObj.data)
484
+ // non-existent objects are retrieved with `undefined` data
439
485
  continue
440
- ret[ cachedObj.id ] = cachedObj.data
486
+ ret[cachedObj.id] = cachedObj.data
441
487
  }
442
488
  }
443
489
 
@@ -445,21 +491,22 @@ export default class ObjectLoader {
445
491
  }
446
492
 
447
493
  cacheStoreObjects(objects) {
448
- if ( !this.options.enableCaching || !window.indexedDB ) {
494
+ if (!this.options.enableCaching || !window.indexedDB) {
449
495
  return {}
450
496
  }
451
497
 
452
- let store = this.cacheDB.transaction('objects', 'readwrite').objectStore('objects')
453
- for ( let obj of objects ) {
454
- let idAndData = obj.split( '\t' )
498
+ const store = this.cacheDB
499
+ .transaction('objects', 'readwrite')
500
+ .objectStore('objects')
501
+ for (const obj of objects) {
502
+ const idAndData = obj.split('\t')
455
503
  store.put(idAndData[1], idAndData[0])
456
504
  }
457
505
 
458
- return this.promisifyIdbRequest( store.transaction )
506
+ return this.promisifyIdbRequest(store.transaction)
459
507
  }
460
508
  }
461
509
 
462
-
463
510
  // Credits and more info: https://github.com/jakearchibald/safari-14-idb-fix
464
511
  function safariFix() {
465
512
  const isSafari =
@@ -472,9 +519,9 @@ function safariFix() {
472
519
 
473
520
  let intervalId
474
521
 
475
- return new Promise( ( resolve ) => {
522
+ return new Promise((resolve) => {
476
523
  const tryIdb = () => indexedDB.databases().finally(resolve)
477
524
  intervalId = setInterval(tryIdb, 100)
478
525
  tryIdb()
479
- }).finally( () => clearInterval(intervalId) )
526
+ }).finally(() => clearInterval(intervalId))
480
527
  }
package/jsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../jsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "es2020"
5
+ },
6
+ "include": ["index.js", "examples"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speckle/objectloader",
3
- "version": "2.4.0",
3
+ "version": "2.4.2-alpha.0+668c96bc",
4
4
  "description": "Simple API helper to stream in objects from the Speckle Server.",
5
5
  "main": "index.js",
6
6
  "homepage": "https://speckle.systems",
@@ -11,12 +11,21 @@
11
11
  "directory": "packages/objectloader"
12
12
  },
13
13
  "scripts": {
14
- "test": "echo \"Error: no test specified\" && exit 1"
14
+ "test": "echo \"Error: no test specified\" && exit 1",
15
+ "lint": "eslint . --ext .js,.ts"
15
16
  },
16
- "keywords": ["speckle", "aec", "speckle api"],
17
+ "keywords": [
18
+ "speckle",
19
+ "aec",
20
+ "speckle api"
21
+ ],
17
22
  "author": "AEC Systems",
18
23
  "license": "Apache-2.0",
19
24
  "devDependencies": {
25
+ "eslint": "^8.11.0",
26
+ "eslint-config-prettier": "^8.5.0",
27
+ "prettier": "^2.5.1",
20
28
  "undici": "^4.14.1"
21
- }
29
+ },
30
+ "gitHead": "668c96bc6f505aae8388723cff78006667a6d327"
22
31
  }
package/readme.md CHANGED
@@ -38,17 +38,17 @@ async load( { serverUrl, token, streamId, objectId } ) {
38
38
 
39
39
  ```
40
40
 
41
- 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:
41
+ 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
42
 
43
- ```js
43
+ ````js
44
44
 
45
45
  let loader = new ObjectLoader( {
46
- serverUrl: "https://latest.speckle.dev",
47
- streamId: "3ed8357f29",
46
+ serverUrl: "https://latest.speckle.dev",
47
+ streamId: "3ed8357f29",
48
48
  objectId: "0408ab9caaa2ebefb2dd7f1f671e7555",
49
49
  options: {
50
50
  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.
51
+ excludeProps: [ 'displayValue', 'displayMesh', '__closure' ] // Default: []. Any prop names that you pass in here will be ignored from object construction traversal.
52
52
  }
53
53
  } )
54
54
 
@@ -67,7 +67,7 @@ let loader = new ObjectLoader({
67
67
  objectId: '0408ab9caaa2ebefb2dd7f1f671e7555',
68
68
  options: { enableCaching: false, excludeProps: [], fetch },
69
69
  })
70
- ```
70
+ ````
71
71
 
72
72
  ## Community
73
73