@speckle/objectsender 1.0.1 → 2.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/objectsender.cjs +2 -2
- package/dist/objectsender.js +278 -266
- package/eslint.config.mjs +9 -1
- package/package.json +9 -4
- package/src/transports/ServerTransport.ts +48 -27
- package/src/utils/Serializer.ts +1 -1
- package/src/utils/Sha1.spec.ts +15 -0
- package/src/utils/Sha1.ts +1 -1
- package/tsconfig.eslint.json +5 -0
- package/{vite.config.js → vite.config.ts} +2 -1
- package/vitest.config.ts +9 -0
- package/dist/examples/browser/main.d.ts +0 -1
- package/dist/index.d.ts +0 -23
- package/dist/objectsender.cjs.map +0 -1
- package/dist/objectsender.js.map +0 -1
- package/dist/transports/ITransport.d.ts +0 -12
- package/dist/transports/ServerTransport.d.ts +0 -18
- package/dist/utils/Base.d.ts +0 -8
- package/dist/utils/IDisposable.d.ts +0 -3
- package/dist/utils/Serializer.d.ts +0 -21
- package/dist/utils/Sha1.d.ts +0 -6
- package/dist/vite.svg +0 -1
package/dist/objectsender.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);let _="";for(let v=0;v<T.length;v++){const S=T.charCodeAt(v);S<128?_+=String.fromCharCode(S):S>127&&S<2048?(_+=String.fromCharCode(S>>6|192),_+=String.fromCharCode(S&63|128)):(_+=String.fromCharCode(S>>12|224),_+=String.fromCharCode(S>>6&63|128),_+=String.fromCharCode(S&63|128))}return _}let a,n,g;const p=new Array(80);let m=1732584193,j=4023233417,h=2562383102,f=271733878,C=3285377520,l,s,o,c,d,b;t=i(t);const w=t.length,O=[];for(n=0;n<w-3;n+=4)g=t.charCodeAt(n)<<24|t.charCodeAt(n+1)<<16|t.charCodeAt(n+2)<<8|t.charCodeAt(n+3),O.push(g);switch(w%4){case 0:n=2147483648;break;case 1:n=t.charCodeAt(w-1)<<24|8388608;break;case 2:n=t.charCodeAt(w-2)<<24|t.charCodeAt(w-1)<<16|32768;break;case 3:n=t.charCodeAt(w-3)<<24|t.charCodeAt(w-2)<<16|t.charCodeAt(w-1)<<8|128;break}for(O.push(n);O.length%16!==14;)O.push(0);for(O.push(w>>>29),O.push(w<<3&4294967295),a=0;a<O.length;a+=16){for(n=0;n<16;n++)p[n]=O[a+n];for(n=16;n<=79;n++)p[n]=e(p[n-3]^p[n-8]^p[n-14]^p[n-16],1);for(l=m,s=j,o=h,c=f,d=C,n=0;n<=19;n++)b=e(l,5)+(s&o|~s&c)+d+p[n]+1518500249&4294967295,d=c,c=o,o=e(s,30),s=l,l=b;for(n=20;n<=39;n++)b=e(l,5)+(s^o^c)+d+p[n]+1859775393&4294967295,d=c,c=o,o=e(s,30),s=l,l=b;for(n=40;n<=59;n++)b=e(l,5)+(s&o|s&c|o&c)+d+p[n]+2400959708&4294967295,d=c,c=o,o=e(s,30),s=l,l=b;for(n=60;n<=79;n++)b=e(l,5)+(s^o^c)+d+p[n]+3395469782&4294967295,d=c,c=o,o=e(s,30),s=l,l=b;m=m+l&4294967295,j=j+s&4294967295,h=h+o&4294967295,f=f+c&4294967295,C=C+d&4294967295}return(r(m)+r(j)+r(h)+r(f)+r(C)).toLowerCase().substring(0,32)}var lt=typeof global=="object"&&global&&global.Object===Object&&global,pt=typeof self=="object"&&self&&self.Object===Object&&self,W=lt||pt||Function("return this")(),x=W.Symbol,rt=Object.prototype,dt=rt.hasOwnProperty,yt=rt.toString,F=x?x.toStringTag:void 0;function gt(t){var e=dt.call(t,F),r=t[F];try{t[F]=void 0;var i=!0}catch{}var a=yt.call(t);return i&&(e?t[F]=r:delete t[F]),a}var _t=Object.prototype,bt=_t.toString;function wt(t){return bt.call(t)}var St="[object Null]",Ct="[object Undefined]",Y=x?x.toStringTag:void 0;function nt(t){return t==null?t===void 0?Ct:St:Y&&Y in Object(t)?gt(t):wt(t)}function it(t){return t!=null&&typeof t=="object"}var mt="[object Symbol]";function J(t){return typeof t=="symbol"||it(t)&&nt(t)==mt}function Tt(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 V=Array.isArray,vt=1/0,Z=x?x.prototype:void 0,Q=Z?Z.toString:void 0;function at(t){if(typeof t=="string")return t;if(V(t))return Tt(t,at)+"";if(J(t))return Q?Q.call(t):"";var e=t+"";return e=="0"&&1/t==-vt?"-0":e}function st(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var jt="[object AsyncFunction]",Ot="[object Function]",zt="[object GeneratorFunction]",$t="[object Proxy]";function At(t){if(!st(t))return!1;var e=nt(t);return e==Ot||e==zt||e==jt||e==$t}var K=W["__core-js_shared__"],tt=function(){var t=/[^.]+$/.exec(K&&K.keys&&K.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Pt(t){return!!tt&&tt in t}var kt=Function.prototype,It=kt.toString;function xt(t){if(t!=null){try{return It.call(t)}catch{}try{return t+""}catch{}}return""}var Et=/[\\^$.*+?()[\]{}|]/g,Ft=/^\[object .+?Constructor\]$/,Dt=Function.prototype,Lt=Object.prototype,Nt=Dt.toString,Ht=Lt.hasOwnProperty,Mt=RegExp("^"+Nt.call(Ht).replace(Et,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Ut(t){if(!st(t)||Pt(t))return!1;var e=At(t)?Mt:Ft;return e.test(xt(t))}function Rt(t,e){return t==null?void 0:t[e]}function ot(t,e){var r=Rt(t,e);return Ut(r)?r:void 0}function Gt(t,e){return t===e||t!==t&&e!==e}var Bt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Kt=/^\w*$/;function qt(t,e){if(V(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||J(t)?!0:Kt.test(t)||!Bt.test(t)||e!=null&&t in Object(e)}var N=ot(Object,"create");function Wt(){this.__data__=N?N(null):{},this.size=0}function Jt(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Vt="__lodash_hash_undefined__",Xt=Object.prototype,Yt=Xt.hasOwnProperty;function Zt(t){var e=this.__data__;if(N){var r=e[t];return r===Vt?void 0:r}return Yt.call(e,t)?e[t]:void 0}var Qt=Object.prototype,te=Qt.hasOwnProperty;function ee(t){var e=this.__data__;return N?e[t]!==void 0:te.call(e,t)}var re="__lodash_hash_undefined__";function ne(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=N&&e===void 0?re:e,this}function A(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])}}A.prototype.clear=Wt;A.prototype.delete=Jt;A.prototype.get=Zt;A.prototype.has=ee;A.prototype.set=ne;function ie(){this.__data__=[],this.size=0}function R(t,e){for(var r=t.length;r--;)if(Gt(t[r][0],e))return r;return-1}var ae=Array.prototype,se=ae.splice;function oe(t){var e=this.__data__,r=R(e,t);if(r<0)return!1;var i=e.length-1;return r==i?e.pop():se.call(e,r,1),--this.size,!0}function ce(t){var e=this.__data__,r=R(e,t);return r<0?void 0:e[r][1]}function he(t){return R(this.__data__,t)>-1}function ue(t,e){var r=this.__data__,i=R(r,t);return i<0?(++this.size,r.push([t,e])):r[i][1]=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=oe;E.prototype.get=ce;E.prototype.has=he;E.prototype.set=ue;var fe=ot(W,"Map");function le(){this.size=0,this.__data__={hash:new A,map:new(fe||E),string:new A}}function pe(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function G(t,e){var r=t.__data__;return pe(e)?r[typeof e=="string"?"string":"hash"]:r.map}function de(t){var e=G(this,t).delete(t);return this.size-=e?1:0,e}function ye(t){return G(this,t).get(t)}function ge(t){return G(this,t).has(t)}function _e(t,e){var r=G(this,t),i=r.size;return r.set(t,e),this.size+=r.size==i?0:1,this}function P(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])}}P.prototype.clear=le;P.prototype.delete=de;P.prototype.get=ye;P.prototype.has=ge;P.prototype.set=_e;var be="Expected a function";function X(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError(be);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(X.Cache||P),r}X.Cache=P;var we=500;function Se(t){var e=X(t,function(i){return r.size===we&&r.clear(),i}),r=e.cache;return e}var Ce=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,me=/\\(\\)?/g,Te=Se(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(Ce,function(r,i,a,n){e.push(a?n.replace(me,"$1"):i||r)}),e});function ve(t){return t==null?"":at(t)}function je(t,e){return V(t)?t:qt(t,e)?[t]:Te(ve(t))}var Oe=1/0;function ze(t){if(typeof t=="string"||J(t))return t;var e=t+"";return e=="0"&&1/t==-Oe?"-0":e}function $e(t,e){e=je(e,t);for(var r=0,i=e.length;t!=null&&r<i;)t=t[ze(e[r++])];return r&&r==i?t:void 0}function Ae(t,e,r){var i=t==null?void 0:$e(t,e);return i===void 0?r:i}const Pe=t=>it(t)&&!!Ae(t,"speckle_type");var z,D,$,L,I,M,H,q,U,ct;class ke{constructor(e,r=1e3,i=B){k(this,z);k(this,$);k(this,I);k(this,H);k(this,U);u(this,"chunkSize");u(this,"detachLineage");u(this,"lineage");u(this,"familyTree");u(this,"closureTable");u(this,"transport");u(this,"uniqueId");u(this,"hashingFunction");this.chunkSize=r,this.detachLineage=[!0],this.lineage=[],this.familyTree={},this.closureTable={},this.transport=e,this.uniqueId=0,this.hashingFunction=i||B}async write(e){return await y(this,z,D).call(this,e,!0)}dispose(){this.detachLineage=[],this.lineage=[],this.familyTree={},this.closureTable={},this.transport=null}}z=new WeakSet,D=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 f=e[h];if(!f||h==="id"||h.startsWith("_"))continue;if(typeof f!="object"){a[h]=f;continue}const C=h.startsWith("@"),l=Array.isArray(f),s=l?h.match(/^@\((\d*)\)/):!1;if(l&&s&&f.length!==0&&typeof f[0]!="object"){const o=s[1]!==""?parseInt(s[1]):this.chunkSize,c=[];let d=new et,b=0;for(const w of f)b===o&&(c.push(await y(this,H,q).call(this,d)),d=new et,b=0),d.data.push(w),b++;d.data.length!==0&&c.push(await y(this,H,q).call(this,d)),a[h.replace(s[0],"")]=c;continue}if(f.speckle_type){const o=await y(this,$,L).call(this,{value:f,isDetached:C});a[h]=C?y(this,I,M).call(this,o.id):o;continue}a[h]=await y(this,$,L).call(this,{value:f,isDetached:C})}const n=this.detachLineage.pop(),g=this.lineage.pop();if(this.familyTree[g]){const h={};Object.entries(this.familyTree[g]).forEach(([f,C])=>{h[f]=C-this.detachLineage.length}),a.totalChildrenCount=Object.keys(h).length,a.totalChildrenCount&&(a.__closure=h)}const{hash:p,serializedObject:m,size:j}=y(this,U,ct).call(this,a);return a.id=p,(n||r)&&this.transport&&await this.transport.write(m,j),r&&this.transport&&await this.transport.flush(),{hash:p,traversed:a}},$=new WeakSet,L=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 y(this,$,L).call(this,{value:n})));const a=[];for(const n of e)if(Pe(n)){this.detachLineage.push(r);const{hash:g}=await y(this,z,D).call(this,n,!1);a.push(y(this,I,M).call(this,g))}else a.push(await y(this,$,L).call(this,{value:n,isDetached:r}));return a}if(!e.speckle_type)return e;if(e.speckle_type)return this.detachLineage.push(r),(await y(this,z,D).call(this,e,!1)).traversed;throw new Error(`Unsupported type '${typeof e}': ${e}.`)},I=new WeakSet,M=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"}},H=new WeakSet,q=async function(e){this.detachLineage.push(!0);const{hash:r}=await y(this,z,D).call(this,e,!1);return y(this,I,M).call(this,r)},U=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:B(r),serializedObject:a,size:r.length}};class et{constructor(){u(this,"speckle_type");u(this,"data");this.data=[],this.speckle_type="Speckle.Core.Models.DataChunk"}}class Ie{constructor(e,r,i,a=2e5){u(this,"buffer");u(this,"maxSize");u(this,"currSize");u(this,"serverUrl");u(this,"projectId");u(this,"authToken");this.maxSize=a,this.currSize=0,this.serverUrl=e,this.projectId=r,this.authToken=i,this.buffer=[]}async write(e,r){this.buffer.push(e),this.currSize+=r,!(this.currSize<this.maxSize)&&await this.flush()}async flush(){if(this.buffer.length===0)return;const e=new FormData,r="["+this.buffer.join(",")+"]";e.append("object-batch",new Blob([r],{type:"application/json"}));const i=new URL(`/objects/${this.projectId}`,this.serverUrl),a=await fetch(i,{method:"POST",headers:{Authorization:`Bearer ${this.authToken}`},body:e});if(a.status!==201)throw new Error(`Unexpected error when sending data. Expected status 200, got ${a.status}`);this.buffer=[],this.currSize=0}dispose(){this.buffer=[]}}class xe{constructor(e){u(this,"speckle_type");if(this.speckle_type=this.constructor.name,e)for(const r in e)this[r]=e[r]}}const Ee=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 Ie(e,r,i),p=new ke(g);let m;try{m=await p.write(t)}finally{g.dispose(),p.dispose()}const j=performance.now();return a.log(`Finished sending in ${(j-n)/1e3}s.`),m};exports.Base=xe;exports.send=Ee;
|
|
1
|
+
"use strict";var mt=Object.defineProperty;var St=(t,e,r)=>e in t?mt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var S=(t,e,r)=>(St(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,i)=>(tt(t,e,"write to private field"),i?i.call(t,r):e.set(t,r),r);var d=(t,e,r)=>(tt(t,e,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ct=require("@speckle/shared");function et(t){function e(O,_){return O<<_|O>>>32-_}function r(O){let _="",A,m;for(A=7;A>=0;A--)m=O>>>A*4&15,_+=m.toString(16);return _}function i(O){O=O.replace(/\r\n/g,`
|
|
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;
|
|
3
3
|
//# sourceMappingURL=objectsender.cjs.map
|