@speckle/objectsender 2.19.3 → 2.19.4
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/dist/objectsender.cjs +2 -2
- package/dist/objectsender.js +261 -240
- package/package.json +4 -3
- package/src/examples/browser/main.ts +41 -2
- package/src/examples/browser/utils.ts +38 -0
- package/src/index.ts +2 -0
- package/src/utils/Decorators.ts +28 -0
- package/src/utils/Serializer.ts +20 -4
- package/tsconfig.json +4 -0
package/dist/objectsender.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);let _="";for(let A=0;A<O.length;A++){const m=O.charCodeAt(A);m<128?_+=String.fromCharCode(m):m>127&&m<2048?(_+=String.fromCharCode(m>>6|192),_+=String.fromCharCode(m&63|128)):(_+=String.fromCharCode(m>>12|224),_+=String.fromCharCode(m>>6&63|128),_+=String.fromCharCode(m&63|128))}return _}let a,n,g;const f=new Array(80);let j=1732584193,$=4023233417,h=2562383102,u=271733878,v=3285377520,l,s,o,c,p,w;t=i(t);const C=t.length,z=[];for(n=0;n<C-3;n+=4)g=t.charCodeAt(n)<<24|t.charCodeAt(n+1)<<16|t.charCodeAt(n+2)<<8|t.charCodeAt(n+3),z.push(g);switch(C%4){case 0:n=2147483648;break;case 1:n=t.charCodeAt(C-1)<<24|8388608;break;case 2:n=t.charCodeAt(C-2)<<24|t.charCodeAt(C-1)<<16|32768;break;case 3:n=t.charCodeAt(C-3)<<24|t.charCodeAt(C-2)<<16|t.charCodeAt(C-1)<<8|128;break}for(z.push(n);z.length%16!==14;)z.push(0);for(z.push(C>>>29),z.push(C<<3&4294967295),a=0;a<z.length;a+=16){for(n=0;n<16;n++)f[n]=z[a+n];for(n=16;n<=79;n++)f[n]=e(f[n-3]^f[n-8]^f[n-14]^f[n-16],1);for(l=j,s=$,o=h,c=u,p=v,n=0;n<=19;n++)w=e(l,5)+(s&o|~s&c)+p+f[n]+1518500249&4294967295,p=c,c=o,o=e(s,30),s=l,l=w;for(n=20;n<=39;n++)w=e(l,5)+(s^o^c)+p+f[n]+1859775393&4294967295,p=c,c=o,o=e(s,30),s=l,l=w;for(n=40;n<=59;n++)w=e(l,5)+(s&o|s&c|o&c)+p+f[n]+2400959708&4294967295,p=c,c=o,o=e(s,30),s=l,l=w;for(n=60;n<=79;n++)w=e(l,5)+(s^o^c)+p+f[n]+3395469782&4294967295,p=c,c=o,o=e(s,30),s=l,l=w;j=j+l&4294967295,$=$+s&4294967295,h=h+o&4294967295,u=u+c&4294967295,v=v+p&4294967295}return(r(j)+r($)+r(h)+r(u)+r(v)).toLowerCase().substring(0,40)}var Tt=typeof global=="object"&&global&&global.Object===Object&&global,vt=typeof self=="object"&&self&&self.Object===Object&&self,it=Tt||vt||Function("return this")(),L=it.Symbol,dt=Object.prototype,jt=dt.hasOwnProperty,Ot=dt.toString,H=L?L.toStringTag:void 0;function At(t){var e=jt.call(t,H),r=t[H];try{t[H]=void 0;var i=!0}catch{}var a=Ot.call(t);return i&&(e?t[H]=r:delete t[H]),a}var Pt=Object.prototype,$t=Pt.toString;function zt(t){return $t.call(t)}var kt="[object Null]",It="[object Undefined]",ht=L?L.toStringTag:void 0;function yt(t){return t==null?t===void 0?It:kt:ht&&ht in Object(t)?At(t):zt(t)}function gt(t){return t!=null&&typeof t=="object"}var xt="[object Symbol]";function at(t){return typeof t=="symbol"||gt(t)&&yt(t)==xt}function Et(t,e){for(var r=-1,i=t==null?0:t.length,a=Array(i);++r<i;)a[r]=e(t[r],r,t);return a}var st=Array.isArray,Ft=1/0,ut=L?L.prototype:void 0,lt=ut?ut.toString:void 0;function _t(t){if(typeof t=="string")return t;if(st(t))return Et(t,_t)+"";if(at(t))return lt?lt.call(t):"";var e=t+"";return e=="0"&&1/t==-Ft?"-0":e}function bt(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var Dt="[object AsyncFunction]",Lt="[object Function]",Nt="[object GeneratorFunction]",Ht="[object Proxy]";function Mt(t){if(!bt(t))return!1;var e=yt(t);return e==Lt||e==Nt||e==Dt||e==Ht}var rt=it["__core-js_shared__"],ft=function(){var t=/[^.]+$/.exec(rt&&rt.keys&&rt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Rt(t){return!!ft&&ft in t}var Ut=Function.prototype,Gt=Ut.toString;function Bt(t){if(t!=null){try{return Gt.call(t)}catch{}try{return t+""}catch{}}return""}var qt=/[\\^$.*+?()[\]{}|]/g,Kt=/^\[object .+?Constructor\]$/,Wt=Function.prototype,Jt=Object.prototype,Vt=Wt.toString,Xt=Jt.hasOwnProperty,Yt=RegExp("^"+Vt.call(Xt).replace(qt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Zt(t){if(!bt(t)||Rt(t))return!1;var e=Mt(t)?Yt:Kt;return e.test(Bt(t))}function Qt(t,e){return t==null?void 0:t[e]}function wt(t,e){var r=Qt(t,e);return Zt(r)?r:void 0}function te(t,e){return t===e||t!==t&&e!==e}var ee=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,re=/^\w*$/;function ne(t,e){if(st(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||at(t)?!0:re.test(t)||!ee.test(t)||e!=null&&t in Object(e)}var U=wt(Object,"create");function ie(){this.__data__=U?U(null):{},this.size=0}function ae(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var se="__lodash_hash_undefined__",oe=Object.prototype,ce=oe.hasOwnProperty;function he(t){var e=this.__data__;if(U){var r=e[t];return r===se?void 0:r}return ce.call(e,t)?e[t]:void 0}var ue=Object.prototype,le=ue.hasOwnProperty;function fe(t){var e=this.__data__;return U?e[t]!==void 0:le.call(e,t)}var pe="__lodash_hash_undefined__";function de(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=U&&e===void 0?pe:e,this}function E(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var i=t[e];this.set(i[0],i[1])}}E.prototype.clear=ie;E.prototype.delete=ae;E.prototype.get=he;E.prototype.has=fe;E.prototype.set=de;function ye(){this.__data__=[],this.size=0}function Z(t,e){for(var r=t.length;r--;)if(te(t[r][0],e))return r;return-1}var ge=Array.prototype,_e=ge.splice;function be(t){var e=this.__data__,r=Z(e,t);if(r<0)return!1;var i=e.length-1;return r==i?e.pop():_e.call(e,r,1),--this.size,!0}function we(t){var e=this.__data__,r=Z(e,t);return r<0?void 0:e[r][1]}function Ce(t){return Z(this.__data__,t)>-1}function me(t,e){var r=this.__data__,i=Z(r,t);return i<0?(++this.size,r.push([t,e])):r[i][1]=e,this}function N(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var i=t[e];this.set(i[0],i[1])}}N.prototype.clear=ye;N.prototype.delete=be;N.prototype.get=we;N.prototype.has=Ce;N.prototype.set=me;var Se=wt(it,"Map");function Te(){this.size=0,this.__data__={hash:new E,map:new(Se||N),string:new E}}function ve(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Q(t,e){var r=t.__data__;return ve(e)?r[typeof e=="string"?"string":"hash"]:r.map}function je(t){var e=Q(this,t).delete(t);return this.size-=e?1:0,e}function Oe(t){return Q(this,t).get(t)}function Ae(t){return Q(this,t).has(t)}function Pe(t,e){var r=Q(this,t),i=r.size;return r.set(t,e),this.size+=r.size==i?0:1,this}function F(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var i=t[e];this.set(i[0],i[1])}}F.prototype.clear=Te;F.prototype.delete=je;F.prototype.get=Oe;F.prototype.has=Ae;F.prototype.set=Pe;var $e="Expected a function";function ot(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError($e);var r=function(){var i=arguments,a=e?e.apply(this,i):i[0],n=r.cache;if(n.has(a))return n.get(a);var g=t.apply(this,i);return r.cache=n.set(a,g)||n,g};return r.cache=new(ot.Cache||F),r}ot.Cache=F;var ze=500;function ke(t){var e=ot(t,function(i){return r.size===ze&&r.clear(),i}),r=e.cache;return e}var Ie=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,xe=/\\(\\)?/g,Ee=ke(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(Ie,function(r,i,a,n){e.push(a?n.replace(xe,"$1"):i||r)}),e});function Fe(t){return t==null?"":_t(t)}function De(t,e){return st(t)?t:ne(t,e)?[t]:Ee(Fe(t))}var Le=1/0;function Ne(t){if(typeof t=="string"||at(t))return t;var e=t+"";return e=="0"&&1/t==-Le?"-0":e}function He(t,e){e=De(e,t);for(var r=0,i=e.length;t!=null&&r<i;)t=t[Ne(e[r++])];return r&&r==i?t:void 0}function Me(t,e,r){var i=t==null?void 0:He(t,e);return i===void 0?r:i}const Re=t=>gt(t)&&!!Me(t,"speckle_type");var k,M,I,R,D,X,G,nt,Y,Ct;class Ue{constructor(e,r=1e3,i=et){y(this,k);y(this,I);y(this,D);y(this,G);y(this,Y);S(this,"chunkSize");S(this,"detachLineage");S(this,"lineage");S(this,"familyTree");S(this,"closureTable");S(this,"transport");S(this,"uniqueId");S(this,"hashingFunction");this.chunkSize=r,this.detachLineage=[!0],this.lineage=[],this.familyTree={},this.closureTable={},this.transport=e,this.uniqueId=0,this.hashingFunction=i||et}async write(e){return await d(this,k,M).call(this,e,!0)}dispose(){this.detachLineage=[],this.lineage=[],this.familyTree={},this.closureTable={},this.transport=null}}k=new WeakSet,M=async function(e,r){const i=`${this.uniqueId++}-obj`;this.lineage.push(i);const a={speckle_type:e.speckle_type||"Base"};for(const h in e){const u=e[h];if(u===void 0||h==="id"||h.startsWith("_"))continue;if(typeof u!="object"){a[h]=u;continue}const v=h.startsWith("@"),l=Array.isArray(u),s=l?h.match(/^@\((\d*)\)/):!1;if(l&&s&&u.length!==0&&typeof u[0]!="object"){const o=s[1]!==""?parseInt(s[1]):this.chunkSize,c=[];let p=new pt,w=0;for(const C of u)w===o&&(c.push(await d(this,G,nt).call(this,p)),p=new pt,w=0),p.data.push(C),w++;p.data.length!==0&&c.push(await d(this,G,nt).call(this,p)),a[h.replace(s[0],"")]=c;continue}if(u.speckle_type){const o=await d(this,I,R).call(this,{value:u,isDetached:v});a[h]=v?d(this,D,X).call(this,o.id):o;continue}a[h]=await d(this,I,R).call(this,{value:u,isDetached:v})}const n=this.detachLineage.pop(),g=this.lineage.pop();if(this.familyTree[g]){const h={};Object.entries(this.familyTree[g]).forEach(([u,v])=>{h[u]=v-this.detachLineage.length}),a.totalChildrenCount=Object.keys(h).length,a.totalChildrenCount&&(a.__closure=h)}const{hash:f,serializedObject:j,size:$}=d(this,Y,Ct).call(this,a);return a.id=f,(n||r)&&this.transport&&await this.transport.write(j,$),r&&this.transport&&await this.transport.flush(),{hash:f,traversed:a}},I=new WeakSet,R=async function({value:e,isDetached:r=!1}){if(typeof e!="object")return e;if(Array.isArray(e)){const i=e;if(i.length===0)return e;if(typeof i[0]!="object")return i;if(!r)return Promise.all(e.map(async n=>await d(this,I,R).call(this,{value:n})));const a=[];for(const n of e)if(Re(n)){this.detachLineage.push(r);const{hash:g}=await d(this,k,M).call(this,n,!1);a.push(d(this,D,X).call(this,g))}else a.push(await d(this,I,R).call(this,{value:n,isDetached:r}));return a}if(!e.speckle_type)return e;if(e.speckle_type)return this.detachLineage.push(r),(await d(this,k,M).call(this,e,!1)).traversed;throw new Error(`Unsupported type '${typeof e}': ${e}.`)},D=new WeakSet,X=function(e){return this.lineage.forEach(r=>{this.familyTree[r]||(this.familyTree[r]={}),(!this.familyTree[r][e]||this.familyTree[r][e]>this.detachLineage.length)&&(this.familyTree[r][e]=this.detachLineage.length)}),{referencedId:e,speckle_type:"reference"}},G=new WeakSet,nt=async function(e){this.detachLineage.push(!0);const{hash:r}=await d(this,k,M).call(this,e,!1);return d(this,D,X).call(this,r)},Y=new WeakSet,Ct=function(e){const r=JSON.stringify(e),i=this.hashingFunction(r),a=r.substring(0,1)+`"id":"${i}",`+r.substring(1);return{hash:et(r),serializedObject:a,size:r.length}};class pt{constructor(){S(this,"speckle_type");S(this,"data");this.data=[],this.speckle_type="Speckle.Core.Models.DataChunk"}}var P,B,x,q,K,W,J,V;class Ge{constructor(e,r,i,a){y(this,P,void 0);y(this,B,void 0);y(this,x,void 0);y(this,q,void 0);y(this,K,void 0);y(this,W,void 0);y(this,J,void 0);y(this,V,void 0);b(this,B,(a==null?void 0:a.maxSize)||2e5),b(this,J,(a==null?void 0:a.flushRetryCount)||3),b(this,V,(a==null?void 0:a.flushTimeout)||2*60*1e3),b(this,x,0),b(this,q,e),b(this,K,r),b(this,W,i),b(this,P,[])}async write(e,r){T(this,P).push(e),b(this,x,T(this,x)+r),!(T(this,x)<T(this,B))&&await this.flush()}async flush(){if(T(this,P).length===0)return;const e=new FormData,r="["+T(this,P).join(",")+"]";e.append("object-batch",new Blob([r],{type:"application/json"}));const i=new URL(`/objects/${T(this,K)}`,T(this,q)),a=await ct.retry(async()=>await Promise.race([fetch(i,{method:"POST",headers:{Authorization:`Bearer ${T(this,W)}`},body:e}),ct.timeoutAt(T(this,V),"Object sender flush timed out")]),T(this,J),n=>n*1e3);if(a.status!==201)throw new Error(`Unexpected error when sending data. Expected status 200, got ${a.status}`);b(this,P,[]),b(this,x,0)}dispose(){b(this,P,[])}}P=new WeakMap,B=new WeakMap,x=new WeakMap,q=new WeakMap,K=new WeakMap,W=new WeakMap,J=new WeakMap,V=new WeakMap;class Be{constructor(e){S(this,"speckle_type");if(this.speckle_type=this.constructor.name,e)for(const r in e)this[r]=e[r]}}const qe=async(t,{serverUrl:e="https://app.speckle.systems",projectId:r,token:i,logger:a=console})=>{const n=performance.now();a==null||a.log("Starting to send");const g=new Ge(e,r,i),f=new Ue(g);let j;try{j=await f.write(t)}finally{g.dispose(),f.dispose()}const $=performance.now();return a.log(`Finished sending in ${($-n)/1e3}s.`),j};exports.Base=Be;exports.send=qe;
|
|
1
|
+
"use strict";var Tt=Object.defineProperty;var vt=(t,e,r)=>e in t?Tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var S=(t,e,r)=>(vt(t,typeof e!="symbol"?e+"":e,r),r),tt=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)};var T=(t,e,r)=>(tt(t,e,"read from private field"),r?r.call(t):e.get(t)),y=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},b=(t,e,r,a)=>(tt(t,e,"write to private field"),a?a.call(t,r):e.set(t,r),r);var p=(t,e,r)=>(tt(t,e,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("reflect-metadata");const ht=require("@speckle/shared");function et(t){function e(O,_){return O<<_|O>>>32-_}function r(O){let _="",k,w;for(k=7;k>=0;k--)w=O>>>k*4&15,_+=w.toString(16);return _}function a(O){O=O.replace(/\r\n/g,`
|
|
2
|
+
`);let _="";for(let k=0;k<O.length;k++){const w=O.charCodeAt(k);w<128?_+=String.fromCharCode(w):w>127&&w<2048?(_+=String.fromCharCode(w>>6|192),_+=String.fromCharCode(w&63|128)):(_+=String.fromCharCode(w>>12|224),_+=String.fromCharCode(w>>6&63|128),_+=String.fromCharCode(w&63|128))}return _}let i,n,g;const f=new Array(80);let j=1732584193,A=4023233417,o=2562383102,u=271733878,v=3285377520,l,s,c,h,d,C;t=a(t);const m=t.length,P=[];for(n=0;n<m-3;n+=4)g=t.charCodeAt(n)<<24|t.charCodeAt(n+1)<<16|t.charCodeAt(n+2)<<8|t.charCodeAt(n+3),P.push(g);switch(m%4){case 0:n=2147483648;break;case 1:n=t.charCodeAt(m-1)<<24|8388608;break;case 2:n=t.charCodeAt(m-2)<<24|t.charCodeAt(m-1)<<16|32768;break;case 3:n=t.charCodeAt(m-3)<<24|t.charCodeAt(m-2)<<16|t.charCodeAt(m-1)<<8|128;break}for(P.push(n);P.length%16!==14;)P.push(0);for(P.push(m>>>29),P.push(m<<3&4294967295),i=0;i<P.length;i+=16){for(n=0;n<16;n++)f[n]=P[i+n];for(n=16;n<=79;n++)f[n]=e(f[n-3]^f[n-8]^f[n-14]^f[n-16],1);for(l=j,s=A,c=o,h=u,d=v,n=0;n<=19;n++)C=e(l,5)+(s&c|~s&h)+d+f[n]+1518500249&4294967295,d=h,h=c,c=e(s,30),s=l,l=C;for(n=20;n<=39;n++)C=e(l,5)+(s^c^h)+d+f[n]+1859775393&4294967295,d=h,h=c,c=e(s,30),s=l,l=C;for(n=40;n<=59;n++)C=e(l,5)+(s&c|s&h|c&h)+d+f[n]+2400959708&4294967295,d=h,h=c,c=e(s,30),s=l,l=C;for(n=60;n<=79;n++)C=e(l,5)+(s^c^h)+d+f[n]+3395469782&4294967295,d=h,h=c,c=e(s,30),s=l,l=C;j=j+l&4294967295,A=A+s&4294967295,o=o+c&4294967295,u=u+h&4294967295,v=v+d&4294967295}return(r(j)+r(A)+r(o)+r(u)+r(v)).toLowerCase().substring(0,40)}var jt=typeof global=="object"&&global&&global.Object===Object&&global,Ot=typeof self=="object"&&self&&self.Object===Object&&self,at=jt||Ot||Function("return this")(),M=at.Symbol,yt=Object.prototype,kt=yt.hasOwnProperty,zt=yt.toString,L=M?M.toStringTag:void 0;function At(t){var e=kt.call(t,L),r=t[L];try{t[L]=void 0;var a=!0}catch{}var i=zt.call(t);return a&&(e?t[L]=r:delete t[L]),i}var Pt=Object.prototype,$t=Pt.toString;function It(t){return $t.call(t)}var xt="[object Null]",Et="[object Undefined]",ut=M?M.toStringTag:void 0;function gt(t){return t==null?t===void 0?Et:xt:ut&&ut in Object(t)?At(t):It(t)}function _t(t){return t!=null&&typeof t=="object"}var Dt="[object Symbol]";function it(t){return typeof t=="symbol"||_t(t)&>(t)==Dt}function Ft(t,e){for(var r=-1,a=t==null?0:t.length,i=Array(a);++r<a;)i[r]=e(t[r],r,t);return i}var st=Array.isArray,Mt=1/0,lt=M?M.prototype:void 0,ft=lt?lt.toString:void 0;function bt(t){if(typeof t=="string")return t;if(st(t))return Ft(t,bt)+"";if(it(t))return ft?ft.call(t):"";var e=t+"";return e=="0"&&1/t==-Mt?"-0":e}function Ct(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var Rt="[object AsyncFunction]",Lt="[object Function]",Nt="[object GeneratorFunction]",Ht="[object Proxy]";function Ut(t){if(!Ct(t))return!1;var e=gt(t);return e==Lt||e==Nt||e==Rt||e==Ht}var rt=at["__core-js_shared__"],dt=function(){var t=/[^.]+$/.exec(rt&&rt.keys&&rt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Gt(t){return!!dt&&dt in t}var Kt=Function.prototype,qt=Kt.toString;function Bt(t){if(t!=null){try{return qt.call(t)}catch{}try{return t+""}catch{}}return""}var Wt=/[\\^$.*+?()[\]{}|]/g,Jt=/^\[object .+?Constructor\]$/,Vt=Function.prototype,Xt=Object.prototype,Yt=Vt.toString,Zt=Xt.hasOwnProperty,Qt=RegExp("^"+Yt.call(Zt).replace(Wt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function te(t){if(!Ct(t)||Gt(t))return!1;var e=Ut(t)?Qt:Jt;return e.test(Bt(t))}function ee(t,e){return t==null?void 0:t[e]}function mt(t,e){var r=ee(t,e);return te(r)?r:void 0}function re(t,e){return t===e||t!==t&&e!==e}var ne=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ae=/^\w*$/;function ie(t,e){if(st(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||it(t)?!0:ae.test(t)||!ne.test(t)||e!=null&&t in Object(e)}var U=mt(Object,"create");function se(){this.__data__=U?U(null):{},this.size=0}function oe(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var ce="__lodash_hash_undefined__",he=Object.prototype,ue=he.hasOwnProperty;function le(t){var e=this.__data__;if(U){var r=e[t];return r===ce?void 0:r}return ue.call(e,t)?e[t]:void 0}var fe=Object.prototype,de=fe.hasOwnProperty;function pe(t){var e=this.__data__;return U?e[t]!==void 0:de.call(e,t)}var ye="__lodash_hash_undefined__";function ge(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=U&&e===void 0?ye:e,this}function E(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}E.prototype.clear=se;E.prototype.delete=oe;E.prototype.get=le;E.prototype.has=pe;E.prototype.set=ge;function _e(){this.__data__=[],this.size=0}function Z(t,e){for(var r=t.length;r--;)if(re(t[r][0],e))return r;return-1}var be=Array.prototype,Ce=be.splice;function me(t){var e=this.__data__,r=Z(e,t);if(r<0)return!1;var a=e.length-1;return r==a?e.pop():Ce.call(e,r,1),--this.size,!0}function we(t){var e=this.__data__,r=Z(e,t);return r<0?void 0:e[r][1]}function Se(t){return Z(this.__data__,t)>-1}function Te(t,e){var r=this.__data__,a=Z(r,t);return a<0?(++this.size,r.push([t,e])):r[a][1]=e,this}function R(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}R.prototype.clear=_e;R.prototype.delete=me;R.prototype.get=we;R.prototype.has=Se;R.prototype.set=Te;var ve=mt(at,"Map");function je(){this.size=0,this.__data__={hash:new E,map:new(ve||R),string:new E}}function Oe(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Q(t,e){var r=t.__data__;return Oe(e)?r[typeof e=="string"?"string":"hash"]:r.map}function ke(t){var e=Q(this,t).delete(t);return this.size-=e?1:0,e}function ze(t){return Q(this,t).get(t)}function Ae(t){return Q(this,t).has(t)}function Pe(t,e){var r=Q(this,t),a=r.size;return r.set(t,e),this.size+=r.size==a?0:1,this}function D(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}D.prototype.clear=je;D.prototype.delete=ke;D.prototype.get=ze;D.prototype.has=Ae;D.prototype.set=Pe;var $e="Expected a function";function ot(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError($e);var r=function(){var a=arguments,i=e?e.apply(this,a):a[0],n=r.cache;if(n.has(i))return n.get(i);var g=t.apply(this,a);return r.cache=n.set(i,g)||n,g};return r.cache=new(ot.Cache||D),r}ot.Cache=D;var Ie=500;function xe(t){var e=ot(t,function(a){return r.size===Ie&&r.clear(),a}),r=e.cache;return e}var Ee=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,De=/\\(\\)?/g,Fe=xe(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(Ee,function(r,a,i,n){e.push(i?n.replace(De,"$1"):a||r)}),e});function Me(t){return t==null?"":bt(t)}function Re(t,e){return st(t)?t:ie(t,e)?[t]:Fe(Me(t))}var Le=1/0;function Ne(t){if(typeof t=="string"||it(t))return t;var e=t+"";return e=="0"&&1/t==-Le?"-0":e}function He(t,e){e=Re(e,t);for(var r=0,a=e.length;t!=null&&r<a;)t=t[Ne(e[r++])];return r&&r==a?t:void 0}function Ue(t,e,r){var a=t==null?void 0:He(t,e);return a===void 0?r:a}const wt=Symbol("detach"),ct=Symbol("chunkable");function Ge(){return Reflect.metadata(wt,!0)}function Ke(t){return Reflect.metadata(ct,t)}function qe(t,e){return!!Reflect.getMetadata(wt,t,e)}function Be(t,e){return!!Reflect.getMetadata(ct,t,e)}function We(t,e){return Reflect.getMetadata(ct,t,e)}const Je=t=>_t(t)&&!!Ue(t,"speckle_type");var $,N,I,H,F,X,G,nt,Y,St;class Ve{constructor(e,r=1e3,a=et){y(this,$);y(this,I);y(this,F);y(this,G);y(this,Y);S(this,"chunkSize");S(this,"detachLineage");S(this,"lineage");S(this,"familyTree");S(this,"closureTable");S(this,"transport");S(this,"uniqueId");S(this,"hashingFunction");this.chunkSize=r,this.detachLineage=[!0],this.lineage=[],this.familyTree={},this.closureTable={},this.transport=e,this.uniqueId=0,this.hashingFunction=a||et}async write(e){return await p(this,$,N).call(this,e,!0)}dispose(){this.detachLineage=[],this.lineage=[],this.familyTree={},this.closureTable={},this.transport=null}}$=new WeakSet,N=async function(e,r){const a=`${this.uniqueId++}-obj`;this.lineage.push(a);const i={speckle_type:e.speckle_type||"Base"};for(const o in e){const u=e[o];if(u===void 0||o==="id"||o.startsWith("_"))continue;if(typeof u!="object"){i[o]=u;continue}const v=o.startsWith("@")||qe(e,o),l=Array.isArray(u),s=l?Be(e,o)||o.match(/^@\((\d*)\)/):!1;if(l&&s&&u.length!==0&&typeof u[0]!="object"){let c=this.chunkSize;typeof s=="boolean"?c=We(e,o):c=s[1]!==""?parseInt(s[1]):this.chunkSize;const h=[];let d=new pt,C=0;for(const m of u)C===c&&(h.push(await p(this,G,nt).call(this,d)),d=new pt,C=0),d.data.push(m),C++;d.data.length!==0&&h.push(await p(this,G,nt).call(this,d)),typeof s=="boolean"?i[o]=h:i[o.replace(s[0],"")]=h;continue}if(u.speckle_type){const c=await p(this,I,H).call(this,{value:u,isDetached:v});i[o]=v?p(this,F,X).call(this,c.id):c;continue}i[o]=await p(this,I,H).call(this,{value:u,isDetached:v})}const n=this.detachLineage.pop(),g=this.lineage.pop();if(this.familyTree[g]){const o={};Object.entries(this.familyTree[g]).forEach(([u,v])=>{o[u]=v-this.detachLineage.length}),i.totalChildrenCount=Object.keys(o).length,i.totalChildrenCount&&(i.__closure=o)}const{hash:f,serializedObject:j,size:A}=p(this,Y,St).call(this,i);return i.id=f,(n||r)&&this.transport&&await this.transport.write(j,A),r&&this.transport&&await this.transport.flush(),{hash:f,traversed:i}},I=new WeakSet,H=async function({value:e,isDetached:r=!1}){if(typeof e!="object")return e;if(Array.isArray(e)){const a=e;if(a.length===0)return e;if(typeof a[0]!="object")return a;if(!r)return Promise.all(e.map(async n=>await p(this,I,H).call(this,{value:n})));const i=[];for(const n of e)if(Je(n)){this.detachLineage.push(r);const{hash:g}=await p(this,$,N).call(this,n,!1);i.push(p(this,F,X).call(this,g))}else i.push(await p(this,I,H).call(this,{value:n,isDetached:r}));return i}if(!e.speckle_type)return e;if(e.speckle_type)return this.detachLineage.push(r),(await p(this,$,N).call(this,e,!1)).traversed;throw new Error(`Unsupported type '${typeof e}': ${e}.`)},F=new WeakSet,X=function(e){return this.lineage.forEach(r=>{this.familyTree[r]||(this.familyTree[r]={}),(!this.familyTree[r][e]||this.familyTree[r][e]>this.detachLineage.length)&&(this.familyTree[r][e]=this.detachLineage.length)}),{referencedId:e,speckle_type:"reference"}},G=new WeakSet,nt=async function(e){this.detachLineage.push(!0);const{hash:r}=await p(this,$,N).call(this,e,!1);return p(this,F,X).call(this,r)},Y=new WeakSet,St=function(e){const r=JSON.stringify(e),a=this.hashingFunction(r),i=r.substring(0,1)+`"id":"${a}",`+r.substring(1);return{hash:et(r),serializedObject:i,size:r.length}};class pt{constructor(){S(this,"speckle_type");S(this,"data");this.data=[],this.speckle_type="Speckle.Core.Models.DataChunk"}}var z,K,x,q,B,W,J,V;class Xe{constructor(e,r,a,i){y(this,z,void 0);y(this,K,void 0);y(this,x,void 0);y(this,q,void 0);y(this,B,void 0);y(this,W,void 0);y(this,J,void 0);y(this,V,void 0);b(this,K,(i==null?void 0:i.maxSize)||2e5),b(this,J,(i==null?void 0:i.flushRetryCount)||3),b(this,V,(i==null?void 0:i.flushTimeout)||2*60*1e3),b(this,x,0),b(this,q,e),b(this,B,r),b(this,W,a),b(this,z,[])}async write(e,r){T(this,z).push(e),b(this,x,T(this,x)+r),!(T(this,x)<T(this,K))&&await this.flush()}async flush(){if(T(this,z).length===0)return;const e=new FormData,r="["+T(this,z).join(",")+"]";e.append("object-batch",new Blob([r],{type:"application/json"}));const a=new URL(`/objects/${T(this,B)}`,T(this,q)),i=await ht.retry(async()=>await Promise.race([fetch(a,{method:"POST",headers:{Authorization:`Bearer ${T(this,W)}`},body:e}),ht.timeoutAt(T(this,V),"Object sender flush timed out")]),T(this,J),n=>n*1e3);if(i.status!==201)throw new Error(`Unexpected error when sending data. Expected status 200, got ${i.status}`);b(this,z,[]),b(this,x,0)}dispose(){b(this,z,[])}}z=new WeakMap,K=new WeakMap,x=new WeakMap,q=new WeakMap,B=new WeakMap,W=new WeakMap,J=new WeakMap,V=new WeakMap;class Ye{constructor(e){S(this,"speckle_type");if(this.speckle_type=this.constructor.name,e)for(const r in e)this[r]=e[r]}}const Ze=async(t,{serverUrl:e="https://app.speckle.systems",projectId:r,token:a,logger:i=console})=>{const n=performance.now();i==null||i.log("Starting to send");const g=new Xe(e,r,a),f=new Ve(g);let j;try{j=await f.write(t)}finally{g.dispose(),f.dispose()}const A=performance.now();return i.log(`Finished sending in ${(A-n)/1e3}s.`),j};exports.Base=Ye;exports.Chunkable=Ke;exports.Detach=Ge;exports.send=Ze;
|
|
3
3
|
//# sourceMappingURL=objectsender.cjs.map
|
package/dist/objectsender.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var S = (t, e, r) => (
|
|
1
|
+
var St = Object.defineProperty;
|
|
2
|
+
var Tt = (t, e, r) => e in t ? St(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var S = (t, e, r) => (Tt(t, typeof e != "symbol" ? e + "" : e, r), r), tt = (t, e, r) => {
|
|
4
4
|
if (!e.has(t))
|
|
5
5
|
throw TypeError("Cannot " + r);
|
|
6
6
|
};
|
|
@@ -8,36 +8,37 @@ var T = (t, e, r) => (tt(t, e, "read from private field"), r ? r.call(t) : e.get
|
|
|
8
8
|
if (e.has(t))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
10
|
e instanceof WeakSet ? e.add(t) : e.set(t, r);
|
|
11
|
-
}, b = (t, e, r,
|
|
12
|
-
var
|
|
13
|
-
import
|
|
11
|
+
}, b = (t, e, r, a) => (tt(t, e, "write to private field"), a ? a.call(t, r) : e.set(t, r), r);
|
|
12
|
+
var p = (t, e, r) => (tt(t, e, "access private method"), r);
|
|
13
|
+
import "reflect-metadata";
|
|
14
|
+
import { retry as vt, timeoutAt as jt } from "@speckle/shared";
|
|
14
15
|
function et(t) {
|
|
15
16
|
function e(O, _) {
|
|
16
17
|
return O << _ | O >>> 32 - _;
|
|
17
18
|
}
|
|
18
19
|
function r(O) {
|
|
19
|
-
let _ = "",
|
|
20
|
-
for (
|
|
21
|
-
|
|
20
|
+
let _ = "", k, w;
|
|
21
|
+
for (k = 7; k >= 0; k--)
|
|
22
|
+
w = O >>> k * 4 & 15, _ += w.toString(16);
|
|
22
23
|
return _;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
+
function a(O) {
|
|
25
26
|
O = O.replace(/\r\n/g, `
|
|
26
27
|
`);
|
|
27
28
|
let _ = "";
|
|
28
|
-
for (let
|
|
29
|
-
const
|
|
30
|
-
|
|
29
|
+
for (let k = 0; k < O.length; k++) {
|
|
30
|
+
const w = O.charCodeAt(k);
|
|
31
|
+
w < 128 ? _ += String.fromCharCode(w) : w > 127 && w < 2048 ? (_ += String.fromCharCode(w >> 6 | 192), _ += String.fromCharCode(w & 63 | 128)) : (_ += String.fromCharCode(w >> 12 | 224), _ += String.fromCharCode(w >> 6 & 63 | 128), _ += String.fromCharCode(w & 63 | 128));
|
|
31
32
|
}
|
|
32
33
|
return _;
|
|
33
34
|
}
|
|
34
|
-
let
|
|
35
|
+
let i, n, g;
|
|
35
36
|
const f = new Array(80);
|
|
36
|
-
let j = 1732584193,
|
|
37
|
-
t =
|
|
38
|
-
const C = t.length,
|
|
37
|
+
let j = 1732584193, A = 4023233417, o = 2562383102, u = 271733878, v = 3285377520, l, s, c, h, d, m;
|
|
38
|
+
t = a(t);
|
|
39
|
+
const C = t.length, $ = [];
|
|
39
40
|
for (n = 0; n < C - 3; n += 4)
|
|
40
|
-
g = t.charCodeAt(n) << 24 | t.charCodeAt(n + 1) << 16 | t.charCodeAt(n + 2) << 8 | t.charCodeAt(n + 3),
|
|
41
|
+
g = t.charCodeAt(n) << 24 | t.charCodeAt(n + 1) << 16 | t.charCodeAt(n + 2) << 8 | t.charCodeAt(n + 3), $.push(g);
|
|
41
42
|
switch (C % 4) {
|
|
42
43
|
case 0:
|
|
43
44
|
n = 2147483648;
|
|
@@ -52,90 +53,90 @@ function et(t) {
|
|
|
52
53
|
n = t.charCodeAt(C - 3) << 24 | t.charCodeAt(C - 2) << 16 | t.charCodeAt(C - 1) << 8 | 128;
|
|
53
54
|
break;
|
|
54
55
|
}
|
|
55
|
-
for (
|
|
56
|
-
|
|
57
|
-
for (
|
|
56
|
+
for ($.push(n); $.length % 16 !== 14; )
|
|
57
|
+
$.push(0);
|
|
58
|
+
for ($.push(C >>> 29), $.push(C << 3 & 4294967295), i = 0; i < $.length; i += 16) {
|
|
58
59
|
for (n = 0; n < 16; n++)
|
|
59
|
-
f[n] =
|
|
60
|
+
f[n] = $[i + n];
|
|
60
61
|
for (n = 16; n <= 79; n++)
|
|
61
62
|
f[n] = e(f[n - 3] ^ f[n - 8] ^ f[n - 14] ^ f[n - 16], 1);
|
|
62
|
-
for (l = j, s =
|
|
63
|
-
|
|
63
|
+
for (l = j, s = A, c = o, h = u, d = v, n = 0; n <= 19; n++)
|
|
64
|
+
m = e(l, 5) + (s & c | ~s & h) + d + f[n] + 1518500249 & 4294967295, d = h, h = c, c = e(s, 30), s = l, l = m;
|
|
64
65
|
for (n = 20; n <= 39; n++)
|
|
65
|
-
|
|
66
|
+
m = e(l, 5) + (s ^ c ^ h) + d + f[n] + 1859775393 & 4294967295, d = h, h = c, c = e(s, 30), s = l, l = m;
|
|
66
67
|
for (n = 40; n <= 59; n++)
|
|
67
|
-
|
|
68
|
+
m = e(l, 5) + (s & c | s & h | c & h) + d + f[n] + 2400959708 & 4294967295, d = h, h = c, c = e(s, 30), s = l, l = m;
|
|
68
69
|
for (n = 60; n <= 79; n++)
|
|
69
|
-
|
|
70
|
-
j = j + l & 4294967295,
|
|
70
|
+
m = e(l, 5) + (s ^ c ^ h) + d + f[n] + 3395469782 & 4294967295, d = h, h = c, c = e(s, 30), s = l, l = m;
|
|
71
|
+
j = j + l & 4294967295, A = A + s & 4294967295, o = o + c & 4294967295, u = u + h & 4294967295, v = v + d & 4294967295;
|
|
71
72
|
}
|
|
72
|
-
return (r(j) + r(
|
|
73
|
+
return (r(j) + r(A) + r(o) + r(u) + r(v)).toLowerCase().substring(0, 40);
|
|
73
74
|
}
|
|
74
|
-
var
|
|
75
|
+
var Ot = typeof global == "object" && global && global.Object === Object && global, kt = typeof self == "object" && self && self.Object === Object && self, at = Ot || kt || Function("return this")(), R = at.Symbol, pt = Object.prototype, zt = pt.hasOwnProperty, At = pt.toString, M = R ? R.toStringTag : void 0;
|
|
75
76
|
function $t(t) {
|
|
76
|
-
var e =
|
|
77
|
+
var e = zt.call(t, M), r = t[M];
|
|
77
78
|
try {
|
|
78
|
-
t[
|
|
79
|
-
var
|
|
79
|
+
t[M] = void 0;
|
|
80
|
+
var a = !0;
|
|
80
81
|
} catch {
|
|
81
82
|
}
|
|
82
|
-
var
|
|
83
|
-
return
|
|
83
|
+
var i = At.call(t);
|
|
84
|
+
return a && (e ? t[M] = r : delete t[M]), i;
|
|
84
85
|
}
|
|
85
|
-
var
|
|
86
|
-
function
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
var It = "[object Null]", xt = "[object Undefined]", ct = L ? L.toStringTag : void 0;
|
|
90
|
-
function dt(t) {
|
|
91
|
-
return t == null ? t === void 0 ? xt : It : ct && ct in Object(t) ? $t(t) : kt(t);
|
|
86
|
+
var Pt = Object.prototype, It = Pt.toString;
|
|
87
|
+
function xt(t) {
|
|
88
|
+
return It.call(t);
|
|
92
89
|
}
|
|
90
|
+
var Et = "[object Null]", Dt = "[object Undefined]", ht = R ? R.toStringTag : void 0;
|
|
93
91
|
function yt(t) {
|
|
92
|
+
return t == null ? t === void 0 ? Dt : Et : ht && ht in Object(t) ? $t(t) : xt(t);
|
|
93
|
+
}
|
|
94
|
+
function gt(t) {
|
|
94
95
|
return t != null && typeof t == "object";
|
|
95
96
|
}
|
|
96
|
-
var
|
|
97
|
-
function
|
|
98
|
-
return typeof t == "symbol" ||
|
|
97
|
+
var Ft = "[object Symbol]";
|
|
98
|
+
function it(t) {
|
|
99
|
+
return typeof t == "symbol" || gt(t) && yt(t) == Ft;
|
|
99
100
|
}
|
|
100
|
-
function
|
|
101
|
-
for (var r = -1,
|
|
102
|
-
|
|
103
|
-
return
|
|
101
|
+
function Rt(t, e) {
|
|
102
|
+
for (var r = -1, a = t == null ? 0 : t.length, i = Array(a); ++r < a; )
|
|
103
|
+
i[r] = e(t[r], r, t);
|
|
104
|
+
return i;
|
|
104
105
|
}
|
|
105
|
-
var st = Array.isArray,
|
|
106
|
-
function
|
|
106
|
+
var st = Array.isArray, Lt = 1 / 0, ut = R ? R.prototype : void 0, lt = ut ? ut.toString : void 0;
|
|
107
|
+
function _t(t) {
|
|
107
108
|
if (typeof t == "string")
|
|
108
109
|
return t;
|
|
109
110
|
if (st(t))
|
|
110
|
-
return
|
|
111
|
-
if (
|
|
112
|
-
return
|
|
111
|
+
return Rt(t, _t) + "";
|
|
112
|
+
if (it(t))
|
|
113
|
+
return lt ? lt.call(t) : "";
|
|
113
114
|
var e = t + "";
|
|
114
|
-
return e == "0" && 1 / t == -
|
|
115
|
+
return e == "0" && 1 / t == -Lt ? "-0" : e;
|
|
115
116
|
}
|
|
116
|
-
function
|
|
117
|
+
function bt(t) {
|
|
117
118
|
var e = typeof t;
|
|
118
119
|
return t != null && (e == "object" || e == "function");
|
|
119
120
|
}
|
|
120
|
-
var
|
|
121
|
-
function
|
|
122
|
-
if (!
|
|
121
|
+
var Mt = "[object AsyncFunction]", Nt = "[object Function]", Ht = "[object GeneratorFunction]", Ut = "[object Proxy]";
|
|
122
|
+
function Gt(t) {
|
|
123
|
+
if (!bt(t))
|
|
123
124
|
return !1;
|
|
124
|
-
var e =
|
|
125
|
-
return e == Nt || e == Ht || e ==
|
|
125
|
+
var e = yt(t);
|
|
126
|
+
return e == Nt || e == Ht || e == Mt || e == Ut;
|
|
126
127
|
}
|
|
127
|
-
var rt =
|
|
128
|
+
var rt = at["__core-js_shared__"], ft = function() {
|
|
128
129
|
var t = /[^.]+$/.exec(rt && rt.keys && rt.keys.IE_PROTO || "");
|
|
129
130
|
return t ? "Symbol(src)_1." + t : "";
|
|
130
131
|
}();
|
|
131
|
-
function Ut(t) {
|
|
132
|
-
return !!lt && lt in t;
|
|
133
|
-
}
|
|
134
|
-
var Gt = Function.prototype, Bt = Gt.toString;
|
|
135
132
|
function Kt(t) {
|
|
133
|
+
return !!ft && ft in t;
|
|
134
|
+
}
|
|
135
|
+
var Bt = Function.prototype, qt = Bt.toString;
|
|
136
|
+
function Wt(t) {
|
|
136
137
|
if (t != null) {
|
|
137
138
|
try {
|
|
138
|
-
return
|
|
139
|
+
return qt.call(t);
|
|
139
140
|
} catch {
|
|
140
141
|
}
|
|
141
142
|
try {
|
|
@@ -145,128 +146,128 @@ function Kt(t) {
|
|
|
145
146
|
}
|
|
146
147
|
return "";
|
|
147
148
|
}
|
|
148
|
-
var
|
|
149
|
-
"^" +
|
|
149
|
+
var Jt = /[\\^$.*+?()[\]{}|]/g, Vt = /^\[object .+?Constructor\]$/, Xt = Function.prototype, Yt = Object.prototype, Zt = Xt.toString, Qt = Yt.hasOwnProperty, te = RegExp(
|
|
150
|
+
"^" + Zt.call(Qt).replace(Jt, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
150
151
|
);
|
|
151
|
-
function
|
|
152
|
-
if (!
|
|
152
|
+
function ee(t) {
|
|
153
|
+
if (!bt(t) || Kt(t))
|
|
153
154
|
return !1;
|
|
154
|
-
var e =
|
|
155
|
-
return e.test(
|
|
155
|
+
var e = Gt(t) ? te : Vt;
|
|
156
|
+
return e.test(Wt(t));
|
|
156
157
|
}
|
|
157
|
-
function
|
|
158
|
+
function re(t, e) {
|
|
158
159
|
return t == null ? void 0 : t[e];
|
|
159
160
|
}
|
|
160
|
-
function
|
|
161
|
-
var r =
|
|
162
|
-
return
|
|
161
|
+
function mt(t, e) {
|
|
162
|
+
var r = re(t, e);
|
|
163
|
+
return ee(r) ? r : void 0;
|
|
163
164
|
}
|
|
164
|
-
function
|
|
165
|
+
function ne(t, e) {
|
|
165
166
|
return t === e || t !== t && e !== e;
|
|
166
167
|
}
|
|
167
|
-
var
|
|
168
|
-
function
|
|
168
|
+
var ae = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, ie = /^\w*$/;
|
|
169
|
+
function se(t, e) {
|
|
169
170
|
if (st(t))
|
|
170
171
|
return !1;
|
|
171
172
|
var r = typeof t;
|
|
172
|
-
return r == "number" || r == "symbol" || r == "boolean" || t == null ||
|
|
173
|
+
return r == "number" || r == "symbol" || r == "boolean" || t == null || it(t) ? !0 : ie.test(t) || !ae.test(t) || e != null && t in Object(e);
|
|
173
174
|
}
|
|
174
|
-
var U =
|
|
175
|
-
function
|
|
175
|
+
var U = mt(Object, "create");
|
|
176
|
+
function oe() {
|
|
176
177
|
this.__data__ = U ? U(null) : {}, this.size = 0;
|
|
177
178
|
}
|
|
178
|
-
function
|
|
179
|
+
function ce(t) {
|
|
179
180
|
var e = this.has(t) && delete this.__data__[t];
|
|
180
181
|
return this.size -= e ? 1 : 0, e;
|
|
181
182
|
}
|
|
182
|
-
var
|
|
183
|
-
function
|
|
183
|
+
var he = "__lodash_hash_undefined__", ue = Object.prototype, le = ue.hasOwnProperty;
|
|
184
|
+
function fe(t) {
|
|
184
185
|
var e = this.__data__;
|
|
185
186
|
if (U) {
|
|
186
187
|
var r = e[t];
|
|
187
|
-
return r ===
|
|
188
|
+
return r === he ? void 0 : r;
|
|
188
189
|
}
|
|
189
|
-
return
|
|
190
|
+
return le.call(e, t) ? e[t] : void 0;
|
|
190
191
|
}
|
|
191
|
-
var
|
|
192
|
-
function
|
|
192
|
+
var de = Object.prototype, pe = de.hasOwnProperty;
|
|
193
|
+
function ye(t) {
|
|
193
194
|
var e = this.__data__;
|
|
194
|
-
return U ? e[t] !== void 0 :
|
|
195
|
+
return U ? e[t] !== void 0 : pe.call(e, t);
|
|
195
196
|
}
|
|
196
|
-
var
|
|
197
|
-
function
|
|
197
|
+
var ge = "__lodash_hash_undefined__";
|
|
198
|
+
function _e(t, e) {
|
|
198
199
|
var r = this.__data__;
|
|
199
|
-
return this.size += this.has(t) ? 0 : 1, r[t] = U && e === void 0 ?
|
|
200
|
+
return this.size += this.has(t) ? 0 : 1, r[t] = U && e === void 0 ? ge : e, this;
|
|
200
201
|
}
|
|
201
202
|
function E(t) {
|
|
202
203
|
var e = -1, r = t == null ? 0 : t.length;
|
|
203
204
|
for (this.clear(); ++e < r; ) {
|
|
204
|
-
var
|
|
205
|
-
this.set(
|
|
205
|
+
var a = t[e];
|
|
206
|
+
this.set(a[0], a[1]);
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
|
-
E.prototype.clear =
|
|
209
|
-
E.prototype.delete =
|
|
210
|
-
E.prototype.get =
|
|
211
|
-
E.prototype.has =
|
|
212
|
-
E.prototype.set =
|
|
213
|
-
function
|
|
209
|
+
E.prototype.clear = oe;
|
|
210
|
+
E.prototype.delete = ce;
|
|
211
|
+
E.prototype.get = fe;
|
|
212
|
+
E.prototype.has = ye;
|
|
213
|
+
E.prototype.set = _e;
|
|
214
|
+
function be() {
|
|
214
215
|
this.__data__ = [], this.size = 0;
|
|
215
216
|
}
|
|
216
217
|
function Z(t, e) {
|
|
217
218
|
for (var r = t.length; r--; )
|
|
218
|
-
if (
|
|
219
|
+
if (ne(t[r][0], e))
|
|
219
220
|
return r;
|
|
220
221
|
return -1;
|
|
221
222
|
}
|
|
222
|
-
var
|
|
223
|
+
var me = Array.prototype, Ce = me.splice;
|
|
223
224
|
function we(t) {
|
|
224
225
|
var e = this.__data__, r = Z(e, t);
|
|
225
226
|
if (r < 0)
|
|
226
227
|
return !1;
|
|
227
|
-
var
|
|
228
|
-
return r ==
|
|
228
|
+
var a = e.length - 1;
|
|
229
|
+
return r == a ? e.pop() : Ce.call(e, r, 1), --this.size, !0;
|
|
229
230
|
}
|
|
230
|
-
function
|
|
231
|
+
function Se(t) {
|
|
231
232
|
var e = this.__data__, r = Z(e, t);
|
|
232
233
|
return r < 0 ? void 0 : e[r][1];
|
|
233
234
|
}
|
|
234
|
-
function
|
|
235
|
+
function Te(t) {
|
|
235
236
|
return Z(this.__data__, t) > -1;
|
|
236
237
|
}
|
|
237
|
-
function
|
|
238
|
-
var r = this.__data__,
|
|
239
|
-
return
|
|
238
|
+
function ve(t, e) {
|
|
239
|
+
var r = this.__data__, a = Z(r, t);
|
|
240
|
+
return a < 0 ? (++this.size, r.push([t, e])) : r[a][1] = e, this;
|
|
240
241
|
}
|
|
241
|
-
function
|
|
242
|
+
function L(t) {
|
|
242
243
|
var e = -1, r = t == null ? 0 : t.length;
|
|
243
244
|
for (this.clear(); ++e < r; ) {
|
|
244
|
-
var
|
|
245
|
-
this.set(
|
|
245
|
+
var a = t[e];
|
|
246
|
+
this.set(a[0], a[1]);
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
var
|
|
254
|
-
function
|
|
249
|
+
L.prototype.clear = be;
|
|
250
|
+
L.prototype.delete = we;
|
|
251
|
+
L.prototype.get = Se;
|
|
252
|
+
L.prototype.has = Te;
|
|
253
|
+
L.prototype.set = ve;
|
|
254
|
+
var je = mt(at, "Map");
|
|
255
|
+
function Oe() {
|
|
255
256
|
this.size = 0, this.__data__ = {
|
|
256
257
|
hash: new E(),
|
|
257
|
-
map: new (
|
|
258
|
+
map: new (je || L)(),
|
|
258
259
|
string: new E()
|
|
259
260
|
};
|
|
260
261
|
}
|
|
261
|
-
function
|
|
262
|
+
function ke(t) {
|
|
262
263
|
var e = typeof t;
|
|
263
264
|
return e == "string" || e == "number" || e == "symbol" || e == "boolean" ? t !== "__proto__" : t === null;
|
|
264
265
|
}
|
|
265
266
|
function Q(t, e) {
|
|
266
267
|
var r = t.__data__;
|
|
267
|
-
return
|
|
268
|
+
return ke(e) ? r[typeof e == "string" ? "string" : "hash"] : r.map;
|
|
268
269
|
}
|
|
269
|
-
function
|
|
270
|
+
function ze(t) {
|
|
270
271
|
var e = Q(this, t).delete(t);
|
|
271
272
|
return this.size -= e ? 1 : 0, e;
|
|
272
273
|
}
|
|
@@ -276,79 +277,95 @@ function Ae(t) {
|
|
|
276
277
|
function $e(t) {
|
|
277
278
|
return Q(this, t).has(t);
|
|
278
279
|
}
|
|
279
|
-
function
|
|
280
|
-
var r = Q(this, t),
|
|
281
|
-
return r.set(t, e), this.size += r.size ==
|
|
280
|
+
function Pe(t, e) {
|
|
281
|
+
var r = Q(this, t), a = r.size;
|
|
282
|
+
return r.set(t, e), this.size += r.size == a ? 0 : 1, this;
|
|
282
283
|
}
|
|
283
|
-
function
|
|
284
|
+
function D(t) {
|
|
284
285
|
var e = -1, r = t == null ? 0 : t.length;
|
|
285
286
|
for (this.clear(); ++e < r; ) {
|
|
286
|
-
var
|
|
287
|
-
this.set(
|
|
287
|
+
var a = t[e];
|
|
288
|
+
this.set(a[0], a[1]);
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
var
|
|
291
|
+
D.prototype.clear = Oe;
|
|
292
|
+
D.prototype.delete = ze;
|
|
293
|
+
D.prototype.get = Ae;
|
|
294
|
+
D.prototype.has = $e;
|
|
295
|
+
D.prototype.set = Pe;
|
|
296
|
+
var Ie = "Expected a function";
|
|
296
297
|
function ot(t, e) {
|
|
297
298
|
if (typeof t != "function" || e != null && typeof e != "function")
|
|
298
|
-
throw new TypeError(
|
|
299
|
+
throw new TypeError(Ie);
|
|
299
300
|
var r = function() {
|
|
300
|
-
var
|
|
301
|
-
if (n.has(
|
|
302
|
-
return n.get(
|
|
303
|
-
var g = t.apply(this,
|
|
304
|
-
return r.cache = n.set(
|
|
301
|
+
var a = arguments, i = e ? e.apply(this, a) : a[0], n = r.cache;
|
|
302
|
+
if (n.has(i))
|
|
303
|
+
return n.get(i);
|
|
304
|
+
var g = t.apply(this, a);
|
|
305
|
+
return r.cache = n.set(i, g) || n, g;
|
|
305
306
|
};
|
|
306
|
-
return r.cache = new (ot.Cache ||
|
|
307
|
+
return r.cache = new (ot.Cache || D)(), r;
|
|
307
308
|
}
|
|
308
|
-
ot.Cache =
|
|
309
|
-
var
|
|
310
|
-
function
|
|
311
|
-
var e = ot(t, function(
|
|
312
|
-
return r.size ===
|
|
309
|
+
ot.Cache = D;
|
|
310
|
+
var xe = 500;
|
|
311
|
+
function Ee(t) {
|
|
312
|
+
var e = ot(t, function(a) {
|
|
313
|
+
return r.size === xe && r.clear(), a;
|
|
313
314
|
}), r = e.cache;
|
|
314
315
|
return e;
|
|
315
316
|
}
|
|
316
|
-
var
|
|
317
|
+
var De = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g, Fe = /\\(\\)?/g, Re = Ee(function(t) {
|
|
317
318
|
var e = [];
|
|
318
|
-
return t.charCodeAt(0) === 46 && e.push(""), t.replace(
|
|
319
|
-
e.push(
|
|
319
|
+
return t.charCodeAt(0) === 46 && e.push(""), t.replace(De, function(r, a, i, n) {
|
|
320
|
+
e.push(i ? n.replace(Fe, "$1") : a || r);
|
|
320
321
|
}), e;
|
|
321
322
|
});
|
|
322
|
-
function
|
|
323
|
-
return t == null ? "" :
|
|
323
|
+
function Le(t) {
|
|
324
|
+
return t == null ? "" : _t(t);
|
|
324
325
|
}
|
|
325
|
-
function
|
|
326
|
-
return st(t) ? t :
|
|
326
|
+
function Me(t, e) {
|
|
327
|
+
return st(t) ? t : se(t, e) ? [t] : Re(Le(t));
|
|
327
328
|
}
|
|
328
329
|
var Ne = 1 / 0;
|
|
329
330
|
function He(t) {
|
|
330
|
-
if (typeof t == "string" ||
|
|
331
|
+
if (typeof t == "string" || it(t))
|
|
331
332
|
return t;
|
|
332
333
|
var e = t + "";
|
|
333
334
|
return e == "0" && 1 / t == -Ne ? "-0" : e;
|
|
334
335
|
}
|
|
335
|
-
function
|
|
336
|
-
e =
|
|
337
|
-
for (var r = 0,
|
|
336
|
+
function Ue(t, e) {
|
|
337
|
+
e = Me(e, t);
|
|
338
|
+
for (var r = 0, a = e.length; t != null && r < a; )
|
|
338
339
|
t = t[He(e[r++])];
|
|
339
|
-
return r && r ==
|
|
340
|
+
return r && r == a ? t : void 0;
|
|
341
|
+
}
|
|
342
|
+
function Ge(t, e, r) {
|
|
343
|
+
var a = t == null ? void 0 : Ue(t, e);
|
|
344
|
+
return a === void 0 ? r : a;
|
|
345
|
+
}
|
|
346
|
+
const Ct = Symbol("detach"), ct = Symbol("chunkable");
|
|
347
|
+
function tr() {
|
|
348
|
+
return Reflect.metadata(Ct, !0);
|
|
340
349
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
return i === void 0 ? r : i;
|
|
350
|
+
function er(t) {
|
|
351
|
+
return Reflect.metadata(ct, t);
|
|
344
352
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
353
|
+
function Ke(t, e) {
|
|
354
|
+
return !!Reflect.getMetadata(Ct, t, e);
|
|
355
|
+
}
|
|
356
|
+
function Be(t, e) {
|
|
357
|
+
return !!Reflect.getMetadata(ct, t, e);
|
|
358
|
+
}
|
|
359
|
+
function qe(t, e) {
|
|
360
|
+
return Reflect.getMetadata(ct, t, e);
|
|
361
|
+
}
|
|
362
|
+
const We = (t) => gt(t) && !!Ge(t, "speckle_type");
|
|
363
|
+
var P, N, I, H, F, X, G, nt, Y, wt;
|
|
364
|
+
class Je {
|
|
365
|
+
constructor(e, r = 1e3, a = et) {
|
|
366
|
+
y(this, P);
|
|
350
367
|
y(this, I);
|
|
351
|
-
y(this,
|
|
368
|
+
y(this, F);
|
|
352
369
|
y(this, G);
|
|
353
370
|
y(this, Y);
|
|
354
371
|
S(this, "chunkSize");
|
|
@@ -359,90 +376,92 @@ class Ge {
|
|
|
359
376
|
S(this, "transport");
|
|
360
377
|
S(this, "uniqueId");
|
|
361
378
|
S(this, "hashingFunction");
|
|
362
|
-
this.chunkSize = r, this.detachLineage = [!0], this.lineage = [], this.familyTree = {}, this.closureTable = {}, this.transport = e, this.uniqueId = 0, this.hashingFunction =
|
|
379
|
+
this.chunkSize = r, this.detachLineage = [!0], this.lineage = [], this.familyTree = {}, this.closureTable = {}, this.transport = e, this.uniqueId = 0, this.hashingFunction = a || et;
|
|
363
380
|
}
|
|
364
381
|
async write(e) {
|
|
365
|
-
return await
|
|
382
|
+
return await p(this, P, N).call(this, e, !0);
|
|
366
383
|
}
|
|
367
384
|
dispose() {
|
|
368
385
|
this.detachLineage = [], this.lineage = [], this.familyTree = {}, this.closureTable = {}, this.transport = null;
|
|
369
386
|
}
|
|
370
387
|
}
|
|
371
|
-
|
|
372
|
-
const
|
|
373
|
-
this.lineage.push(
|
|
374
|
-
const
|
|
375
|
-
for (const
|
|
376
|
-
const u = e[
|
|
377
|
-
if (u === void 0 ||
|
|
388
|
+
P = new WeakSet(), N = async function(e, r) {
|
|
389
|
+
const a = `${this.uniqueId++}-obj`;
|
|
390
|
+
this.lineage.push(a);
|
|
391
|
+
const i = { speckle_type: e.speckle_type || "Base" };
|
|
392
|
+
for (const o in e) {
|
|
393
|
+
const u = e[o];
|
|
394
|
+
if (u === void 0 || o === "id" || o.startsWith("_"))
|
|
378
395
|
continue;
|
|
379
396
|
if (typeof u != "object") {
|
|
380
|
-
|
|
397
|
+
i[o] = u;
|
|
381
398
|
continue;
|
|
382
399
|
}
|
|
383
|
-
const v =
|
|
400
|
+
const v = o.startsWith("@") || Ke(e, o), l = Array.isArray(u), s = l ? Be(e, o) || o.match(/^@\((\d*)\)/) : !1;
|
|
384
401
|
if (l && s && u.length !== 0 && typeof u[0] != "object") {
|
|
385
|
-
|
|
386
|
-
|
|
402
|
+
let c = this.chunkSize;
|
|
403
|
+
typeof s == "boolean" ? c = qe(e, o) : c = s[1] !== "" ? parseInt(s[1]) : this.chunkSize;
|
|
404
|
+
const h = [];
|
|
405
|
+
let d = new dt(), m = 0;
|
|
387
406
|
for (const C of u)
|
|
388
|
-
|
|
389
|
-
|
|
407
|
+
m === c && (h.push(await p(this, G, nt).call(this, d)), d = new dt(), m = 0), d.data.push(C), m++;
|
|
408
|
+
d.data.length !== 0 && h.push(await p(this, G, nt).call(this, d)), typeof s == "boolean" ? i[o] = h : i[o.replace(s[0], "")] = h;
|
|
390
409
|
continue;
|
|
391
410
|
}
|
|
392
411
|
if (u.speckle_type) {
|
|
393
|
-
const
|
|
412
|
+
const c = await p(this, I, H).call(this, {
|
|
394
413
|
value: u,
|
|
395
414
|
isDetached: v
|
|
396
415
|
});
|
|
397
|
-
|
|
416
|
+
i[o] = v ? p(this, F, X).call(this, c.id) : c;
|
|
398
417
|
continue;
|
|
399
418
|
}
|
|
400
|
-
|
|
419
|
+
i[o] = await p(this, I, H).call(this, {
|
|
401
420
|
value: u,
|
|
402
421
|
isDetached: v
|
|
403
422
|
});
|
|
404
423
|
}
|
|
405
424
|
const n = this.detachLineage.pop(), g = this.lineage.pop();
|
|
406
425
|
if (this.familyTree[g]) {
|
|
407
|
-
const
|
|
426
|
+
const o = {};
|
|
408
427
|
Object.entries(this.familyTree[g]).forEach(([u, v]) => {
|
|
409
|
-
|
|
410
|
-
}),
|
|
428
|
+
o[u] = v - this.detachLineage.length;
|
|
429
|
+
}), i.totalChildrenCount = Object.keys(o).length, i.totalChildrenCount && (i.__closure = o);
|
|
411
430
|
}
|
|
412
|
-
const { hash: f, serializedObject: j, size:
|
|
413
|
-
return
|
|
414
|
-
}, I = new WeakSet(),
|
|
431
|
+
const { hash: f, serializedObject: j, size: A } = p(this, Y, wt).call(this, i);
|
|
432
|
+
return i.id = f, (n || r) && this.transport && await this.transport.write(j, A), r && this.transport && await this.transport.flush(), { hash: f, traversed: i };
|
|
433
|
+
}, I = new WeakSet(), H = async function({
|
|
415
434
|
value: e,
|
|
416
435
|
isDetached: r = !1
|
|
417
436
|
}) {
|
|
418
437
|
if (typeof e != "object")
|
|
419
438
|
return e;
|
|
420
439
|
if (Array.isArray(e)) {
|
|
421
|
-
const
|
|
422
|
-
if (
|
|
440
|
+
const a = e;
|
|
441
|
+
if (a.length === 0)
|
|
423
442
|
return e;
|
|
424
|
-
if (typeof
|
|
425
|
-
return
|
|
443
|
+
if (typeof a[0] != "object")
|
|
444
|
+
return a;
|
|
426
445
|
if (!r)
|
|
427
446
|
return Promise.all(
|
|
428
|
-
e.map(async (n) => await
|
|
447
|
+
e.map(async (n) => await p(this, I, H).call(this, { value: n }))
|
|
429
448
|
);
|
|
430
|
-
const
|
|
449
|
+
const i = [];
|
|
431
450
|
for (const n of e)
|
|
432
|
-
if (
|
|
451
|
+
if (We(n)) {
|
|
433
452
|
this.detachLineage.push(r);
|
|
434
|
-
const { hash: g } = await
|
|
435
|
-
|
|
453
|
+
const { hash: g } = await p(this, P, N).call(this, n, !1);
|
|
454
|
+
i.push(p(this, F, X).call(this, g));
|
|
436
455
|
} else
|
|
437
|
-
|
|
438
|
-
return
|
|
456
|
+
i.push(await p(this, I, H).call(this, { value: n, isDetached: r }));
|
|
457
|
+
return i;
|
|
439
458
|
}
|
|
440
459
|
if (!e.speckle_type)
|
|
441
460
|
return e;
|
|
442
461
|
if (e.speckle_type)
|
|
443
|
-
return this.detachLineage.push(r), (await
|
|
462
|
+
return this.detachLineage.push(r), (await p(this, P, N).call(this, e, !1)).traversed;
|
|
444
463
|
throw new Error(`Unsupported type '${typeof e}': ${e}.`);
|
|
445
|
-
},
|
|
464
|
+
}, F = new WeakSet(), X = function(e) {
|
|
446
465
|
return this.lineage.forEach((r) => {
|
|
447
466
|
this.familyTree[r] || (this.familyTree[r] = {}), (!this.familyTree[r][e] || this.familyTree[r][e] > this.detachLineage.length) && (this.familyTree[r][e] = this.detachLineage.length);
|
|
448
467
|
}), {
|
|
@@ -451,69 +470,69 @@ k = new WeakSet(), R = async function(e, r) {
|
|
|
451
470
|
};
|
|
452
471
|
}, G = new WeakSet(), nt = async function(e) {
|
|
453
472
|
this.detachLineage.push(!0);
|
|
454
|
-
const { hash: r } = await
|
|
455
|
-
return
|
|
473
|
+
const { hash: r } = await p(this, P, N).call(this, e, !1);
|
|
474
|
+
return p(this, F, X).call(this, r);
|
|
456
475
|
}, Y = new WeakSet(), wt = function(e) {
|
|
457
|
-
const r = JSON.stringify(e),
|
|
476
|
+
const r = JSON.stringify(e), a = this.hashingFunction(r), i = r.substring(0, 1) + `"id":"${a}",` + r.substring(1);
|
|
458
477
|
return {
|
|
459
478
|
hash: et(r),
|
|
460
|
-
serializedObject:
|
|
479
|
+
serializedObject: i,
|
|
461
480
|
size: r.length
|
|
462
481
|
// approx, good enough as we're just limiting artificially batch sizes based on this
|
|
463
482
|
};
|
|
464
483
|
};
|
|
465
|
-
class
|
|
484
|
+
class dt {
|
|
466
485
|
constructor() {
|
|
467
486
|
S(this, "speckle_type");
|
|
468
487
|
S(this, "data");
|
|
469
488
|
this.data = [], this.speckle_type = "Speckle.Core.Models.DataChunk";
|
|
470
489
|
}
|
|
471
490
|
}
|
|
472
|
-
var
|
|
473
|
-
class
|
|
474
|
-
constructor(e, r,
|
|
475
|
-
y(this,
|
|
476
|
-
y(this, B, void 0);
|
|
477
|
-
y(this, x, void 0);
|
|
491
|
+
var z, K, x, B, q, W, J, V;
|
|
492
|
+
class Ve {
|
|
493
|
+
constructor(e, r, a, i) {
|
|
494
|
+
y(this, z, void 0);
|
|
478
495
|
y(this, K, void 0);
|
|
496
|
+
y(this, x, void 0);
|
|
497
|
+
y(this, B, void 0);
|
|
479
498
|
y(this, q, void 0);
|
|
480
499
|
y(this, W, void 0);
|
|
481
500
|
y(this, J, void 0);
|
|
482
501
|
y(this, V, void 0);
|
|
483
|
-
b(this,
|
|
502
|
+
b(this, K, (i == null ? void 0 : i.maxSize) || 2e5), b(this, J, (i == null ? void 0 : i.flushRetryCount) || 3), b(this, V, (i == null ? void 0 : i.flushTimeout) || 2 * 60 * 1e3), b(this, x, 0), b(this, B, e), b(this, q, r), b(this, W, a), b(this, z, []);
|
|
484
503
|
}
|
|
485
504
|
async write(e, r) {
|
|
486
|
-
T(this,
|
|
505
|
+
T(this, z).push(e), b(this, x, T(this, x) + r), !(T(this, x) < T(this, K)) && await this.flush();
|
|
487
506
|
}
|
|
488
507
|
async flush() {
|
|
489
|
-
if (T(this,
|
|
508
|
+
if (T(this, z).length === 0)
|
|
490
509
|
return;
|
|
491
|
-
const e = new FormData(), r = "[" + T(this,
|
|
510
|
+
const e = new FormData(), r = "[" + T(this, z).join(",") + "]";
|
|
492
511
|
e.append("object-batch", new Blob([r], { type: "application/json" }));
|
|
493
|
-
const
|
|
512
|
+
const a = new URL(`/objects/${T(this, q)}`, T(this, B)), i = await vt(
|
|
494
513
|
async () => await Promise.race([
|
|
495
|
-
fetch(
|
|
514
|
+
fetch(a, {
|
|
496
515
|
method: "POST",
|
|
497
516
|
headers: { Authorization: `Bearer ${T(this, W)}` },
|
|
498
517
|
body: e
|
|
499
518
|
}),
|
|
500
|
-
|
|
519
|
+
jt(T(this, V), "Object sender flush timed out")
|
|
501
520
|
]),
|
|
502
521
|
T(this, J),
|
|
503
522
|
(n) => n * 1e3
|
|
504
523
|
);
|
|
505
|
-
if (
|
|
524
|
+
if (i.status !== 201)
|
|
506
525
|
throw new Error(
|
|
507
|
-
`Unexpected error when sending data. Expected status 200, got ${
|
|
526
|
+
`Unexpected error when sending data. Expected status 200, got ${i.status}`
|
|
508
527
|
);
|
|
509
|
-
b(this,
|
|
528
|
+
b(this, z, []), b(this, x, 0);
|
|
510
529
|
}
|
|
511
530
|
dispose() {
|
|
512
|
-
b(this,
|
|
531
|
+
b(this, z, []);
|
|
513
532
|
}
|
|
514
533
|
}
|
|
515
|
-
|
|
516
|
-
class
|
|
534
|
+
z = new WeakMap(), K = new WeakMap(), x = new WeakMap(), B = new WeakMap(), q = new WeakMap(), W = new WeakMap(), J = new WeakMap(), V = new WeakMap();
|
|
535
|
+
class rr {
|
|
517
536
|
constructor(e) {
|
|
518
537
|
S(this, "speckle_type");
|
|
519
538
|
if (this.speckle_type = this.constructor.name, e)
|
|
@@ -521,26 +540,28 @@ class Je {
|
|
|
521
540
|
this[r] = e[r];
|
|
522
541
|
}
|
|
523
542
|
}
|
|
524
|
-
const
|
|
543
|
+
const nr = async (t, {
|
|
525
544
|
serverUrl: e = "https://app.speckle.systems",
|
|
526
545
|
projectId: r,
|
|
527
|
-
token:
|
|
528
|
-
logger:
|
|
546
|
+
token: a,
|
|
547
|
+
logger: i = console
|
|
529
548
|
}) => {
|
|
530
549
|
const n = performance.now();
|
|
531
|
-
|
|
532
|
-
const g = new
|
|
550
|
+
i == null || i.log("Starting to send");
|
|
551
|
+
const g = new Ve(e, r, a), f = new Je(g);
|
|
533
552
|
let j;
|
|
534
553
|
try {
|
|
535
554
|
j = await f.write(t);
|
|
536
555
|
} finally {
|
|
537
556
|
g.dispose(), f.dispose();
|
|
538
557
|
}
|
|
539
|
-
const
|
|
540
|
-
return
|
|
558
|
+
const A = performance.now();
|
|
559
|
+
return i.log(`Finished sending in ${(A - n) / 1e3}s.`), j;
|
|
541
560
|
};
|
|
542
561
|
export {
|
|
543
|
-
|
|
544
|
-
|
|
562
|
+
rr as Base,
|
|
563
|
+
er as Chunkable,
|
|
564
|
+
tr as Detach,
|
|
565
|
+
nr as send
|
|
545
566
|
};
|
|
546
567
|
//# sourceMappingURL=objectsender.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speckle/objectsender",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.4",
|
|
4
4
|
"description": "Simple API helper to serialize and send objects to the server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/objectsender.cjs",
|
|
@@ -32,9 +32,10 @@
|
|
|
32
32
|
"author": "AEC Systems",
|
|
33
33
|
"license": "Apache-2.0",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@speckle/shared": "^2.19.
|
|
35
|
+
"@speckle/shared": "^2.19.4",
|
|
36
36
|
"lodash": "^4.17.21",
|
|
37
|
-
"lodash-es": "^4.17.21"
|
|
37
|
+
"lodash-es": "^4.17.21",
|
|
38
|
+
"reflect-metadata": "^0.2.2"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@types/lodash": "^4.17.5",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { send, Base, type SendResult } from '../../index'
|
|
1
|
+
import { send, Base, type SendResult, Detach, Chunkable } from '../../index'
|
|
2
2
|
import { times } from '#lodash'
|
|
3
|
+
import { createCommit } from './utils'
|
|
3
4
|
|
|
4
5
|
interface ExampleAppWindow extends Window {
|
|
5
6
|
send: typeof import('../../index').send
|
|
@@ -70,6 +71,8 @@ appWindow.loadData = async () => {
|
|
|
70
71
|
projectId,
|
|
71
72
|
token: apiToken
|
|
72
73
|
})
|
|
74
|
+
|
|
75
|
+
await createCommit(res, { serverUrl, projectId, token: apiToken })
|
|
73
76
|
} catch (e) {
|
|
74
77
|
const msg = e instanceof Error ? e.message : JSON.stringify(e)
|
|
75
78
|
setInputValue('result', msg, { valueKey: 'textContent' })
|
|
@@ -108,7 +111,13 @@ function generateTestObject() {
|
|
|
108
111
|
.fill(0)
|
|
109
112
|
.map(() => new RandomFoo({ bar: 'baz baz baz' }))
|
|
110
113
|
],
|
|
111
|
-
|
|
114
|
+
detachedWithDecorator: new Collection<RandomFoo>('Collection of Foo', 'Foo', [
|
|
115
|
+
...Array(10)
|
|
116
|
+
.fill(0)
|
|
117
|
+
.map(() => new RandomFoo())
|
|
118
|
+
]),
|
|
119
|
+
'@(10)chunkedArr': times(100, () => 42),
|
|
120
|
+
some: new RandomJoe()
|
|
112
121
|
})
|
|
113
122
|
}
|
|
114
123
|
|
|
@@ -118,3 +127,33 @@ class RandomFoo extends Base {
|
|
|
118
127
|
this.noise = Math.random().toString(16)
|
|
119
128
|
}
|
|
120
129
|
}
|
|
130
|
+
|
|
131
|
+
class RandomJoe extends Base {
|
|
132
|
+
@Detach()
|
|
133
|
+
@Chunkable(10)
|
|
134
|
+
numbers: number[]
|
|
135
|
+
|
|
136
|
+
constructor(props?: Record<string, unknown>) {
|
|
137
|
+
super(props)
|
|
138
|
+
this.numbers = times(100, () => 42)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class Collection<T extends Base> extends Base {
|
|
143
|
+
@Detach()
|
|
144
|
+
elements: T[]
|
|
145
|
+
// eslint-disable-next-line camelcase
|
|
146
|
+
speckle_type = 'Speckle.Core.Models.Collection'
|
|
147
|
+
|
|
148
|
+
constructor(
|
|
149
|
+
name: string,
|
|
150
|
+
collectionType: string,
|
|
151
|
+
elements: T[] = [],
|
|
152
|
+
props?: Record<string, unknown>
|
|
153
|
+
) {
|
|
154
|
+
super(props)
|
|
155
|
+
this.name = name
|
|
156
|
+
this.collectionType = collectionType
|
|
157
|
+
this.elements = elements
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SendResult } from '../..'
|
|
2
|
+
|
|
3
|
+
interface CreateCommitParams {
|
|
4
|
+
serverUrl: string
|
|
5
|
+
projectId: string
|
|
6
|
+
token: string
|
|
7
|
+
modelName?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function createCommit(
|
|
11
|
+
res: SendResult,
|
|
12
|
+
{ serverUrl, projectId, token, modelName }: CreateCommitParams
|
|
13
|
+
) {
|
|
14
|
+
const response = await fetch(serverUrl + '/graphql', {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
Authorization: `Bearer ${token}`
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify({
|
|
21
|
+
query: `
|
|
22
|
+
mutation CreateCommit($commit: CommitCreateInput!) {
|
|
23
|
+
commitCreate(commit: $commit)
|
|
24
|
+
}
|
|
25
|
+
`,
|
|
26
|
+
variables: {
|
|
27
|
+
commit: {
|
|
28
|
+
branchName: modelName || 'main',
|
|
29
|
+
message: 'Good morning!',
|
|
30
|
+
objectId: res.hash,
|
|
31
|
+
streamId: projectId
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
await response.json()
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import 'reflect-metadata'
|
|
2
|
+
|
|
3
|
+
const detachMetadataKey = Symbol('detach')
|
|
4
|
+
const chunkableMetadataKey = Symbol('chunkable')
|
|
5
|
+
|
|
6
|
+
export function Detach() {
|
|
7
|
+
return Reflect.metadata(detachMetadataKey, true)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Chunkable(size: number) {
|
|
11
|
+
return Reflect.metadata(chunkableMetadataKey, size)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isDetached(target: object, propertyKey: string) {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
16
|
+
const metadata = Reflect.getMetadata(detachMetadataKey, target, propertyKey)
|
|
17
|
+
return metadata ? true : false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isChunkable(target: object, propertyKey: string) {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
22
|
+
const metadata = Reflect.getMetadata(chunkableMetadataKey, target, propertyKey)
|
|
23
|
+
return metadata ? true : false
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getChunkSize(target: object, propertyKey: string) {
|
|
27
|
+
return Reflect.getMetadata(chunkableMetadataKey, target, propertyKey) as number
|
|
28
|
+
}
|
package/src/utils/Serializer.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ITransport } from '../transports/ITransport'
|
|
|
4
4
|
import { Base } from './Base'
|
|
5
5
|
import { IDisposable } from './IDisposable'
|
|
6
6
|
import { isObjectLike, get } from '#lodash'
|
|
7
|
+
import { getChunkSize, isChunkable, isDetached } from './Decorators'
|
|
7
8
|
|
|
8
9
|
type BasicSpeckleObject = Record<string, unknown> & {
|
|
9
10
|
speckle_type: string
|
|
@@ -61,13 +62,22 @@ export class Serializer implements IDisposable {
|
|
|
61
62
|
continue
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
const isDetachedProp = propKey.startsWith('@')
|
|
65
|
+
const isDetachedProp = propKey.startsWith('@') || isDetached(obj, propKey)
|
|
65
66
|
|
|
66
67
|
// 2. chunked arrays
|
|
67
68
|
const isArray = Array.isArray(value)
|
|
68
|
-
const isChunked = isArray
|
|
69
|
+
const isChunked = isArray
|
|
70
|
+
? isChunkable(obj, propKey) || propKey.match(/^@\((\d*)\)/)
|
|
71
|
+
: false // chunk syntax
|
|
72
|
+
|
|
69
73
|
if (isArray && isChunked && value.length !== 0 && typeof value[0] !== 'object') {
|
|
70
|
-
|
|
74
|
+
let chunkSize = this.chunkSize
|
|
75
|
+
if (typeof isChunked === 'boolean') {
|
|
76
|
+
chunkSize = getChunkSize(obj, propKey)
|
|
77
|
+
} else {
|
|
78
|
+
chunkSize = isChunked[1] !== '' ? parseInt(isChunked[1]) : this.chunkSize
|
|
79
|
+
}
|
|
80
|
+
|
|
71
81
|
const chunkRefs = []
|
|
72
82
|
|
|
73
83
|
let chunk = new DataChunk()
|
|
@@ -83,7 +93,13 @@ export class Serializer implements IDisposable {
|
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
if (chunk.data.length !== 0) chunkRefs.push(await this.#handleChunk(chunk))
|
|
86
|
-
|
|
96
|
+
|
|
97
|
+
if (typeof isChunked === 'boolean') {
|
|
98
|
+
traversed[propKey] = chunkRefs // no need to strip chunk syntax
|
|
99
|
+
} else {
|
|
100
|
+
traversed[propKey.replace(isChunked[0], '')] = chunkRefs // strip chunk syntax
|
|
101
|
+
}
|
|
102
|
+
|
|
87
103
|
continue
|
|
88
104
|
}
|
|
89
105
|
|
package/tsconfig.json
CHANGED