@formant/data-sdk 1.80.4 → 1.80.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formant/data-sdk",
3
- "version": "1.80.4",
3
+ "version": "1.80.6",
4
4
  "description": "A library for getting data from Formant",
5
5
  "repository": {
6
6
  "type": "git",
@@ -86,4 +86,4 @@
86
86
  "engines": {
87
87
  "node": "^18.12.0 || ^16.13.0 || 20.x"
88
88
  }
89
- }
89
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"DataFetchWorker-0a168933.js","sources":["../src/connector/common/duration.ts","../src/connector/common/fork.ts","../src/connector/data/StoreCache.ts","../src/connector/data/DataFetchWorker.ts"],"sourcesContent":["const millisecond = 1;\nconst second = 1000;\nconst minute = 60 * second;\nconst hour = 60 * minute;\nconst day = 24 * hour;\nconst week = 7 * day;\nconst month = 30 * day;\nconst year = 365 * day;\n\nexport const duration = {\n millisecond,\n second,\n minute,\n hour,\n day,\n week,\n month,\n year,\n} as const;\n","/**\n * Used to fire-and-forget a promise.\n * This is useful as a function wrapper to suppress floating promise warnings.\n */\nexport function fork<T>(_: Promise<T>): void {\n return undefined;\n}\n","import { duration } from \"../common/duration\";\nimport { fork } from \"../common/fork\";\n\ninterface ICacheEntryMetadata<Value> {\n generating: boolean;\n expiration: Date;\n lastValue?: Value;\n}\n\ntype CacheKey = string;\n\nexport class StoreCache<Key, Value> {\n private entries = new Map<CacheKey, Value>();\n private metadata = new Map<CacheKey, ICacheEntryMetadata<Value>>();\n private capacity!: number;\n private timeout!: number;\n\n constructor({\n capacity,\n timeout,\n }: { capacity?: number; timeout?: number } = {}) {\n this.capacity = capacity || 10000;\n this.timeout = timeout || duration.minute;\n }\n\n public get(key: Key, generator?: () => Promise<Value>): Value | undefined {\n const cacheKey = this.keyToCacheKey(key);\n const entry = this.entries.get(cacheKey);\n const metadata = this.metadata.get(cacheKey);\n\n if (\n (entry === undefined ||\n (metadata && metadata?.expiration.getTime() < Date.now())) &&\n !metadata?.generating &&\n generator\n ) {\n this.generate(key, generator());\n }\n\n if (entry === undefined && metadata && metadata.lastValue !== undefined) {\n return metadata.lastValue;\n }\n\n return entry;\n }\n\n public set(key: Key, value: Value) {\n const cacheKey = this.keyToCacheKey(key);\n this.metadata.set(cacheKey, {\n generating: false,\n expiration: new Date(Date.now() + this.timeout),\n lastValue: value,\n });\n this.entries.set(cacheKey, value);\n\n if (this.metadata.size > this.capacity) {\n this.deleteOldestEntry();\n }\n }\n\n public clear() {\n this.entries.clear();\n [...this.metadata.values()].forEach((value) => (value.generating = false));\n }\n\n public clearKey(key: string): void {\n this.metadata.delete(key);\n this.entries.delete(key);\n }\n\n private keyToCacheKey(key: Key): CacheKey {\n return JSON.stringify(key);\n }\n\n private deleteOldestEntry() {\n if (this.metadata.size < 1) {\n return;\n }\n const [key] = [...this.metadata.entries()].reduce(\n ([oldestKey, oldestEntry], [thisKey, entry]) =>\n entry.expiration.getTime() < oldestEntry.expiration.getTime()\n ? [thisKey, entry]\n : [oldestKey, oldestEntry]\n );\n this.clearKey(key);\n }\n\n private generate(key: Key, promise: Promise<Value>) {\n const cacheKey = this.keyToCacheKey(key);\n const existingMetadata = this.metadata.get(cacheKey) || {};\n this.metadata.set(cacheKey, {\n ...existingMetadata,\n generating: true,\n expiration: new Date(Date.now() + this.timeout),\n });\n setTimeout(() => {\n fork(\n promise.then((value) => {\n const metadata = this.metadata.get(cacheKey);\n const canceled = !metadata?.generating;\n if (!canceled) {\n this.set(key, value);\n }\n })\n );\n }, 0);\n }\n}\n","import { duration } from \"../common/duration\";\nimport { StoreCache } from \"./StoreCache\";\n\nconst cache = new StoreCache<string, any>({\n capacity: 1000,\n timeout: 1 * duration.minute,\n});\n\nonmessage = async (event: MessageEvent<{ url?: string }>) => {\n const { url } = event.data;\n\n if (url) {\n // Check if the point cloud for the given URL is already in the cache\n const cached = cache.get(url, async () => {\n // Fetch the point cloud and store it in the cache\n const res = await fetch(url, { mode: \"cors\" }).then((r) => r.json());\n return res;\n });\n\n if (cached) {\n postMessage({ url, response: cached });\n }\n }\n};\n"],"names":["duration","fork","_","StoreCache","capacity","timeout","__publicField","key","generator","cacheKey","entry","metadata","value","oldestKey","oldestEntry","thisKey","promise","existingMetadata","cache","event","url","cached","r"],"mappings":"iMASO,MAAMA,EAAW,CACtB,cACA,WACA,WACA,UACA,UACA,YACA,aACA,YACF,ECdO,SAASC,EAAQC,EAAqB,CAE7C,CCKO,MAAMC,CAAuB,CAMlC,YAAY,CACV,SAAAC,EACA,QAAAC,CACF,EAA6C,GAAI,CARzCC,EAAA,mBAAc,KACdA,EAAA,oBAAe,KACfA,EAAA,iBACAA,EAAA,gBAMN,KAAK,SAAWF,GAAY,IACvB,KAAA,QAAUC,GAAWL,EAAS,MACrC,CAEO,IAAIO,EAAUC,EAAqD,CAClE,MAAAC,EAAW,KAAK,cAAcF,CAAG,EACjCG,EAAQ,KAAK,QAAQ,IAAID,CAAQ,EACjCE,EAAW,KAAK,SAAS,IAAIF,CAAQ,EAW3C,OARGC,IAAU,QACRC,IAAYA,GAAA,YAAAA,EAAU,WAAW,WAAY,KAAK,IAAI,IACzD,EAACA,GAAA,MAAAA,EAAU,aACXH,GAEK,KAAA,SAASD,EAAKC,EAAW,CAAA,EAG5BE,IAAU,QAAaC,GAAYA,EAAS,YAAc,OACrDA,EAAS,UAGXD,CACT,CAEO,IAAIH,EAAUK,EAAc,CAC3B,MAAAH,EAAW,KAAK,cAAcF,CAAG,EAClC,KAAA,SAAS,IAAIE,EAAU,CAC1B,WAAY,GACZ,WAAY,IAAI,KAAK,KAAK,IAAI,EAAI,KAAK,OAAO,EAC9C,UAAWG,CAAA,CACZ,EACI,KAAA,QAAQ,IAAIH,EAAUG,CAAK,EAE5B,KAAK,SAAS,KAAO,KAAK,UAC5B,KAAK,kBAAkB,CAE3B,CAEO,OAAQ,CACb,KAAK,QAAQ,QACZ,CAAA,G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MA,EAAE,KAAM,CAAA,CAEpE,EAEGD,GACF,YAAY,CAAE,IAAAD,EAAK,SAAUC,CAAQ,CAAA,CAEzC,CACF"}
@@ -1,6 +0,0 @@
1
- var R=Object.defineProperty;var G=(M,b,x)=>b in M?R(M,b,{enumerable:!0,configurable:!0,writable:!0,value:x}):M[b]=x;var I=(M,b,x)=>(G(M,typeof b!="symbol"?b+"":b,x),x);(function(){"use strict";const S={millisecond:1,second:1e3,minute:6e4,hour:36e5,day:864e5,week:6048e5,month:2592e6,year:31536e6};function q(o){}class _{constructor({capacity:t,timeout:n}={}){I(this,"entries",new Map);I(this,"metadata",new Map);I(this,"capacity");I(this,"timeout");this.capacity=t||1e4,this.timeout=n||S.minute}get(t,n){const e=this.keyToCacheKey(t),c=this.entries.get(e),i=this.metadata.get(e);return(c===void 0||i&&(i==null?void 0:i.expiration.getTime())<Date.now())&&!(i!=null&&i.generating)&&n&&this.generate(t,n()),c===void 0&&i&&i.lastValue!==void 0?i.lastValue:c}set(t,n){const e=this.keyToCacheKey(t);this.metadata.set(e,{generating:!1,expiration:new Date(Date.now()+this.timeout),lastValue:n}),this.entries.set(e,n),this.metadata.size>this.capacity&&this.deleteOldestEntry()}clear(){this.entries.clear(),[...this.metadata.values()].forEach(t=>t.generating=!1)}clearKey(t){this.metadata.delete(t),this.entries.delete(t)}keyToCacheKey(t){return JSON.stringify(t)}deleteOldestEntry(){if(this.metadata.size<1)return;const[t]=[...this.metadata.entries()].reduce(([n,e],[c,i])=>i.expiration.getTime()<e.expiration.getTime()?[c,i]:[n,e]);this.clearKey(t)}generate(t,n){const e=this.keyToCacheKey(t),c=this.metadata.get(e)||{};this.metadata.set(e,{...c,generating:!0,expiration:new Date(Date.now()+this.timeout)}),setTimeout(()=>{n.then(i=>{const r=this.metadata.get(e);!(r!=null&&r.generating)||this.set(t,i)})},0)}}/**
2
- * LZF compression/decompression module. Ported from the C
3
- * implementation of liblzf, specfically lzf_c.c and lzf_d.c
4
- * @license BSD-2-Clause
5
- */function K(o){var t=new Uint8Array(o),n=[],e=0,c=0;do{var i=t[e++];if(i<32){if(i++,e+i>t.length)throw new Error("Invalid input");for(;i--;)n[c++]=t[e++]}else{var r=i>>5,f=c-((i&31)<<8)-1;if(e>=t.length)throw new Error("Invalid input");if(r==7&&(r+=t[e++],e>=t.length))throw new Error("Invalid input");if(f-=t[e++],f<0)throw new Error("Invalid input");r+=2;do n[c++]=n[f++];while(--r)}}while(e<t.length);if(typeof Buffer!="undefined")return new Buffer(n);var u=new Uint8Array(n.length);return u.set(n),u}function O(o){var t=16,n=1<<t,e=8192,c=256+8,i=32;function r(v,T){return v[T]<<8|v[T+1]}function f(v,T,P){return v<<8|T[P+2]}function u(v){return v*506832829>>32-t-8&n-1}for(var s=new Uint8Array(o),a=[],d=new Uint32Array(n),y=s.length,h=0,g=r(s,h),p=1,l=0;h<y-2;){g=f(g,o,h);var z=u(g),m=d[z];d[z]=h;var E;if(m<h&&(E=h-m-1)<e&&m>0&&s[m+2]==s[h+2]&&s[m+1]==s[h+1]&&s[m]==s[h]){var w=2,F=y-h-w;F=F>c?c:F,a[p-l-1]=l-1&255,l==0&&(p-=1);do w++;while(w<F&&s[m+w]==s[h+w]);if(w-=2,h++,w<7?a[p++]=(E>>8)+(w<<5)&255:(a[p++]=(E>>8)+224&255,a[p++]=w-7&255),a[p++]=E&255,l=0,p++,h+=w+1,h>=y-2)break;--h,--h,g=r(s,h),g=f(g,s,h),d[u(g)]=h++,g=f(g,s,h),d[u(g)]=h++}else l++,a[p++]=s[h++],l==i&&(a[p-l-1]=l-1&255,l=0,p++)}for(;h<y;)l++,a[p++]=s[h++],l==i&&(a[p-l-1]=l-1&255,l=0,p++);if(l!=0&&(a[p-l-1]=l-1&255),typeof Buffer!="undefined")return new Buffer(a);var U=new Uint8Array(a.length);return U.set(a),U}var B={decompress:K,compress:O};const C=(o,t)=>t<=o?[]:new Array(t-o).fill(0).map((n,e)=>e+o),A=!0;function H(o){const t=atob(o),n=t.length,e=new Uint8Array(n);for(let c=0;c<n;c+=1)e[c]=t.charCodeAt(c);return e.buffer}function L(o){const t=new Uint8Array(o);let n="",e=0;for(;e<t.length&&n.search(/[\r\n]DATA\s(\S*)\s/i)===-1;e+=1)n+=String.fromCharCode(t[e]);return{body:o.slice(e),header:n.replace(/#.*/gi,"")}}function V(o){const n=new Uint32Array(o,0,2)[0];return n===0?new ArrayBuffer(0):B.decompress(new Uint8Array(o,8,n)).buffer}function k(o){const{header:t,body:n}=L(o),e=/VERSION (.*)/i.exec(t);if(e===null)throw new Error(`Missing version. Header ${t}`);const c=e[1],i=/FIELDS (.*)/i.exec(t);if(!i)throw new Error("Missing fields");const r=i[1].split(" "),f=/SIZE (.*)/i.exec(t);if(!f)throw new Error("Missing size");const u=f[1].split(" ").map(v=>parseInt(v,10)),s=/TYPE (.*)/i.exec(t);if(!s)throw new Error("Missing type");const a=s[1].split(" "),d=/COUNT (.*)/i.exec(t);let y;d&&(y=d[1].split(" ").map(v=>parseInt(v,10)));const h=y||r.map(v=>1),g=/WIDTH (.*)/i.exec(t);if(!g)throw new Error("Missing width");const p=parseInt(g[1],10),l=/HEIGHT (.*)/i.exec(t);if(!l)throw new Error("Missing height");const z=parseInt(l[1],10),m=/POINTS (.*)/i.exec(t);let E;m&&(E=parseInt(m[1],10));const w=E||p*z,F=/DATA (.*)/i.exec(t);if(!F)throw new Error("Missing data");const U=F[1];return{body:n,header:{count:h,data:U,fields:r,height:z,points:w,size:u,type:a,version:c,width:p}}}function N(o){const t={};return o.fields.reduce(({offsets:n,size:e},c,i)=>{let r=e;return c==="x"&&(n.x=r),c==="y"&&(n.y=r),c==="z"&&(n.z=r),c==="rgb"&&(n.rgb=r),c==="rgba"&&(n.rgba=r),c==="intensity"&&(n.intensity=r),o.data==="ascii"?r+=1:o.data==="binary"?r+=o.size[i]*o.count[i]:o.data==="binary_compressed"&&(r+=o.size[i]*o.count[i]*o.points),{offsets:n,size:r}},{offsets:t,size:0})}function D(o){const{header:t,body:n}=k(o),{offsets:e,size:c}=N(t);let i;e.x!==void 0&&e.y!==void 0&&e.z!==void 0&&(i=new Float32Array(t.points*3));let r;(e.rgb!==void 0||e.rgba!==void 0)&&(r=new Float32Array(t.points*4));let f;if(e.intensity!==void 0&&(f=new Float32Array(t.points)),t.data==="ascii")String.fromCharCode(...new Uint8Array(n)).split(`
6
- `).forEach((a,d)=>{const y=a.split(" ");if(i!==void 0&&(i[d*3+0]=parseFloat(y[e.x||0]),i[d*3+1]=parseFloat(y[e.y||0]),i[d*3+2]=parseFloat(y[e.z||0])),r!==void 0){const h=new Int32Array([parseInt(y[e.rgb||e.rgba||0],10)]),g=new DataView(h.buffer,0);r[d*3+0]=g.getUint8(2)/255,r[d*3+1]=g.getUint8(1)/255,r[d*3+2]=g.getUint8(0)/255}f!==void 0&&(f[d]=parseFloat(y[e.intensity||0]))});else if(t.data==="binary"){const u=new DataView(n);C(0,t.points).forEach(s=>{const a=c*s;if(i!==void 0&&(i[s*3+0]=u.getFloat32(a+(e.x||0),A),i[s*3+1]=u.getFloat32(a+(e.y||0),A),i[s*3+2]=u.getFloat32(a+(e.z||0),A)),r!==void 0){const d=a+(e.rgb||e.rgba||0);d+2<=u.byteLength&&(r[s*4+0]=u.getUint8(d+2)/255,r[s*4+1]=u.getUint8(d+1)/255,r[s*4+2]=u.getUint8(d+0)/255,r[s*4+3]=1)}f!==void 0&&(f[s]=u.getFloat32(a+(e.intensity||0),A))})}else if(t.data==="binary_compressed"){const u=V(n),s=new DataView(u);C(0,t.points).forEach(a=>{if(i!==void 0&&(i[a*3+0]=s.getFloat32((e.x||0)+a*4,A),i[a*3+1]=s.getFloat32((e.y||0)+a*4,A),i[a*3+2]=s.getFloat32((e.z||0)+a*4,A)),r!==void 0){const d=(e.rgb||e.rgba||0)+a*4;d+2<=s.byteLength&&(r[a*4+0]=s.getUint8(d+2)/255,r[a*4+1]=s.getUint8(d+1)/255,r[a*4+2]=s.getUint8(d+0)/255,r[a*4+3]=1)}f!==void 0&&(f[a]=s.getFloat32((e.intensity||0)+a*4,A))})}return{colors:r,header:t,intensity:f,positions:i}}function X(o){return D(H(o))}const Z=new _({capacity:1e3,timeout:1*S.minute});onmessage=async o=>{const{url:t,id:n,pointCloud:e}=o.data;if(t){const c=Z.get(t,async()=>D(await fetch(t,{mode:"cors"}).then(r=>r.arrayBuffer())));c&&postMessage({url:t,pcd:c})}if(n&&e){const c=X(e);postMessage({id:n,pcd:c})}}})();