-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhypha-rpc-websocket.js.map
1 lines (1 loc) · 208 KB
/
hypha-rpc-websocket.js.map
1
{"version":3,"sources":["webpack://[name]/webpack/universalModuleDefinition","webpack://[name]/webpack/bootstrap","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/CachedKeyDecoder.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/DecodeError.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/Decoder.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/Encoder.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/ExtData.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/ExtensionCodec.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/decode.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/decodeAsync.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/encode.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/index.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/timestamp.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/utils/int.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/utils/prettyByte.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/utils/stream.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/utils/typedArrays.mjs","webpack://[name]/./node_modules/@msgpack/msgpack/dist.es5+esm/utils/utf8.mjs","webpack://[name]/./src/hypha/rpc.js","webpack://[name]/./src/hypha/utils.js","webpack://[name]/./src/hypha/websocket-client.js"],"names":["API_VERSION","CHUNK_SIZE","ArrayBufferView","Object","getPrototypeOf","Uint8Array","constructor","_appendBuffer","buffer1","buffer2","tmp","byteLength","set","buffer","indexObject","obj","is","Error","split","length","slice","concatArrayBuffers","buffers","buffersLengths","map","b","totalBufferlength","reduce","p","c","unit8Arr","i","Timer","timeout","callback","args","label","_timeout","_callback","_args","_label","_task","started","start","setTimeout","apply","clear","clearTimeout","console","warn","reset","assert","RPC","MessageEmitter","connection","client_id","manager_id","default_context","name","codecs","method_timeout","max_message_buffer_size","debug","_codecs","_client_id","_name","_connection_info","_workspace","_method_annotations","WeakMap","_manager_service","_max_message_buffer_size","_chunk_store","_method_timeout","_services","_object_store","services","add_service","id","type","config","require_context","visibility","ping","_ping","bind","get_service","get_local_service","register_service","message_cache","create","_create_message","append","_append_message","process","_process_message","remove","_remove_message","on","_handle_method","emit_message","on_message","_emit_message","_on_message","_connection","_get_connection_info","log","get_manager_service","get_connection_info","reconnection_token","set_reconnection_token","reconnection_expires_in","info","_get_connection_info_task","exp","register_codec","k","keys","msg","context","method","_generate_remote_method","_rtarget","_rmethod","_rpromise","key","heartbeat","overwrite","data","cache","push","unpacker","decodeMulti","done","value","next","main","assign","from","to","user","JSON","parse","stringify","extra","_fire","message","ArrayBuffer","_event_handlers","disconnect","get_remote_service","get_all_local_services","service_id","ws","service","startsWith","service_uri","undefined","includes","provider","waitFor","e","error","_annotate_service_methods","aObject","object_id","run_in_executor","method_name","Array","isArray","method_id","val","__rpc_object__","api","normApi","props","getOwnPropertyNames","concat","notify","workspace","_notify_service_update","unregister_service","_ndarray","typedArray","shape","dtype","_dtype","typedArrayToDtype","_rtype","_rvalue","_rshape","_rdtype","_encode_callback","session_id","clear_after_called","timer","local_workspace","encoded","self","wrapped_callback","prototype","call","arguments","_encode_promise","resolve","reject","store","_get_session_store","_encode","interval","_send_chunks","target_id","remote_services","message_id","randId","total_size","chunk_num","Math","ceil","idx","start_byte","encoded_method","remote_parent","local_parent","remote_workspace","with_promise","remote_method","Promise","local_session_id","argLength","withKwargs","_rkwargs","main_message","extra_data","message_package","msgpack_packb","then","update_client_info","get_client_info","values","heartbeat_task","parent","promise","_decode","session","err","setInterval","has","get","session_target_id","indexOf","ctx","result","clearInterval","catch","encode","levels","last_index","level","aType","bObject","temp","annotation","__name__","isarray","tp","codec","encoder","encodedObj","tf","Tensor","v_buffer","dataSync","nj","NdArray","selection","toString","Boolean","String","Date","RegExp","ImageData","FileList","FileSystemDirectoryHandle","FileSystemFileHandle","FileSystemHandle","FileSystemWritableFileStream","Blob","_current_pos","read","blob","ret","arrayBuffer","seek","pos","_rnative","size","path","_path","webkitRelativePath","DataView","Set","Map","decode","decoder","array","Uint8","reshape","arraytype","dtypeToTypedArray","tensor","byteOffset","bytes","hasOwnProperty","v","random","substr","getTime","int8","Int8Array","int16","Int16Array","int32","Int32Array","uint8","uint16","Uint16Array","uint32","Uint32Array","float32","Float32Array","float64","Float64Array","loadRequirementsInWindow","requirements","_importScript","url","scriptTag","document","createElement","src","onload","onreadystatechange","readyState","onerror","head","appendChild","importScripts","len","link_node","toLowerCase","endsWith","rel","href","loadRequirementsInWebworker","loadRequirements","WorkerGlobalScope","normalizeConfig","version","description","target_origin","allow_execution","typedArrayToDtypeMapping","typedArrayToDtypeKeys","arrType","eval","pt","cacheUrlInServiceWorker","command","navigator","serviceWorker","register","messageChannel","MessageChannel","port1","onmessage","event","controller","postMessage","port2","cacheRequirements","req","setupServiceWorker","baseUrl","targetOrigin","cacheCallback","registration","scope","window","addEventListener","origin","m","condition","urlJoin","join","replace","prom","time","race","_r","rej","finally","_once_handlers","_debug","emit","handler","once","___event_run_once","off","splice","WebsocketRPCConnection","server_url","token","_websocket","_handle_message","_reconnection_token","_server_url","open","WebSocket","binaryType","onclose","send","reason","close","connectToServer","clientId","rpc","connection_type","wm","_export","getPlugin","query","export","listPlugins","listServices","registerCodec"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;AClFA;AAAA;AAAA;AAAgD;AAChD;AACA;AACA;AACA;AACA,sCAAsC,uCAAuC;AAC7E,yCAAyC,8CAA8C;AACvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,uBAAuB;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yDAAyD,uBAAuB;AAChF;AACA;AACA,2BAA2B,gBAAgB;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,oEAAY;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAC2B;AAC5B,6C;;;;;;;;;;;;AC/DA;AAAA;AAAA,iBAAiB,SAAI,IAAI,SAAI;AAC7B;AACA;AACA,cAAc,gBAAgB,sCAAsC,iBAAiB,EAAE;AACvF,6BAA6B,8EAA8E;AAC3G;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,sBAAsB;AAC7C;AACA;AACA,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,CAAC;AACsB;AACvB,wC;;;;;;;;;;;;AChCA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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uBAAuB;AACpD,4BAA4B,wBAAwB;AACpD,2BAA2B,yDAAyD;AACpF;AACoD;AACE;AACY;AACoB;AACX;AACjB;AACV;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD;AACA,iCAAiC,sEAAgB;AACjD;AACA;AACA,wCAAwC,kBAAkB,kEAAc,cAAc;AACtF,iCAAiC,qBAAqB;AACtD,sCAAsC,gBAAgB,yDAAU,CAAC;AACjE,sCAAsC,gBAAgB,yDAAU,CAAC;AACjE,wCAAwC,kBAAkB,yDAAU,CAAC;AACrE,sCAAsC,gBAAgB,yDAAU,CAAC;AACjE,sCAAsC,gBAAgB,yDAAU,CAAC;AACjE,oCAAoC,qCAAqC;AACzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB,+EAAgB;AACrC,oBAAoB,6EAAc;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,+EAAgB;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB;AAChB,gBAAgB;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wCAAwC;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+BAA+B;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+EAA+E,wEAAU;AACzF;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B,KAAK,EAAE,EAAwB;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sCAAsC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+BAA+B;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,4DAAW,8BAA8B,wEAAU;AAC7E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kCAAkC,4DAAW;AAC7C;AACA;AACA,kCAAkC,4DAAW;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8BAA8B,4DAAW,oCAAoC,wEAAU;AACvF;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,4DAAW;AACjC;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB;AACnB,SAAS;AACT;AACA;AACA;AACA,sBAAsB,4DAAW;AACjC;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA,sBAAsB,4DAAW;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8BAA8B,sEAAsB;AACpD,qBAAqB,oEAAY;AACjC;AACA;AACA,qBAAqB,oEAAY;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,4DAAW;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,4DAAW;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,gEAAS;AAC7B;AACA;AACA;AACA;AACA,oBAAoB,+DAAQ;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACkB;AACnB,oC;;;;;;;;;;;;AC7tBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAiG;AAC3C;AACA;AACK;AACpD;AACA;AACP;AACA;AACA,wCAAwC,kBAAkB,kEAAc,cAAc;AACtF,iCAAiC,qBAAqB;AACtD,kCAAkC,8BAA8B;AAChE,2CAA2C,iDAAiD;AAC5F,kCAAkC,kBAAkB;AACpD,sCAAsC,sBAAsB;AAC5D,yCAAyC,yBAAyB;AAClE,6CAA6C,6BAA6B;AAC1E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wBAAwB,sEAAsB;AAC9C,6BAA6B,iEAAS;AACtC;AACA;AACA,YAAY,oEAAY;AACxB;AACA;AACA;AACA,6BAA6B,iEAAS;AACtC;AACA;AACA,YAAY,oEAAY;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,+EAAgB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2CAA2C,sBAAsB;AACjE;AACA;AACA;AACA;AACA;AACA;AACA,uCAAuC,oBAAoB;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uCAAuC,oBAAoB;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,gEAAS;AACjB;AACA;AACA;AACA;AACA,QAAQ,+DAAQ;AAChB;AACA;AACA;AACA,CAAC;AACkB;AACnB,oC;;;;;;;;;;;;ACtZA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACkB;AACnB,oC;;;;;;;;;;;;ACXA;AAAA;AAAA;AAAA;AAAA;AACwC;AACa;AACrD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,iEAAkB;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,iCAAiC;AACxD;AACA;AACA;AACA;AACA;AACA,+BAA+B,oDAAO;AACtC;AACA;AACA;AACA;AACA,uBAAuB,0BAA0B;AACjD;AACA;AACA;AACA;AACA;AACA,+BAA+B,oDAAO;AACtC;AACA;AACA;AACA,8BAA8B,oDAAO;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,oDAAO;AAC9B;AACA;AACA;AACA;AACA,CAAC;AACyB;AAC1B,2C;;;;;;;;;;;;ACtEA;AAAA;AAAA;AAAA;AAAA;AAAwC;AACjC;AACP;AACA;AACA;AACA;AACA,kDAAkD,oBAAoB,GAAG,qBAAqB,MAAM,0BAA0B;AAC9H;AACO;AACP,6BAA6B,gCAAgC;AAC7D,sBAAsB,oDAAO;AAC7B;AACA;AACA;AACA;AACA,6BAA6B,0BAA0B;AACvD;AACO;AACP,6BAA6B,gCAAgC;AAC7D,sBAAsB,oDAAO;AAC7B;AACA;AACA,mC;;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AyD;AACpF;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wBAAwB,KAAK,EAAE,EAAwB;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,KAAK;AACL;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mC;;;;;;;;;;;;AC3FA;AAAA;AAAA;AAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,wC;;;;;;;;;;;;ACtBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAuC;AACvC;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP,MAAM,mDAAU;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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;AAEDuR,IAAE,CAACI,MAAH,GAAYH,OAAZ;AACAD,IAAE,CAACE,SAAH,GAAeA,SAAf;AACAF,IAAE,CAACK,WAAH,GAAiBL,EAAE,CAACM,YAApB;AACAN,IAAE,CAACvR,UAAH,GAAgBA,UAAhB;AACAuR,IAAE,CAACO,aAAH,GAAmBT,GAAG,CAACvT,cAAJ,CAAmB9B,IAAnB,CAAwBqV,GAAxB,CAAnB;AACA,SAAOE,EAAP;AACD,C","file":"hypha-rpc-websocket.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"hyphaWebsocketClient\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"hyphaWebsocketClient\"] = factory();\n\telse\n\t\troot[\"hyphaWebsocketClient\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/hypha/websocket-client.js\");\n","import { utf8DecodeJs } from \"./utils/utf8.mjs\";\nvar DEFAULT_MAX_KEY_LENGTH = 16;\nvar DEFAULT_MAX_LENGTH_PER_KEY = 16;\nvar CachedKeyDecoder = /** @class */ (function () {\n function CachedKeyDecoder(maxKeyLength, maxLengthPerKey) {\n if (maxKeyLength === void 0) { maxKeyLength = DEFAULT_MAX_KEY_LENGTH; }\n if (maxLengthPerKey === void 0) { maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY; }\n this.maxKeyLength = maxKeyLength;\n this.maxLengthPerKey = maxLengthPerKey;\n this.hit = 0;\n this.miss = 0;\n // avoid `new Array(N)`, which makes a sparse array,\n // because a sparse array is typically slower than a non-sparse array.\n this.caches = [];\n for (var i = 0; i < this.maxKeyLength; i++) {\n this.caches.push([]);\n }\n }\n CachedKeyDecoder.prototype.canBeCached = function (byteLength) {\n return byteLength > 0 && byteLength <= this.maxKeyLength;\n };\n CachedKeyDecoder.prototype.find = function (bytes, inputOffset, byteLength) {\n var records = this.caches[byteLength - 1];\n FIND_CHUNK: for (var _i = 0, records_1 = records; _i < records_1.length; _i++) {\n var record = records_1[_i];\n var recordBytes = record.bytes;\n for (var j = 0; j < byteLength; j++) {\n if (recordBytes[j] !== bytes[inputOffset + j]) {\n continue FIND_CHUNK;\n }\n }\n return record.str;\n }\n return null;\n };\n CachedKeyDecoder.prototype.store = function (bytes, value) {\n var records = this.caches[bytes.length - 1];\n var record = { bytes: bytes, str: value };\n if (records.length >= this.maxLengthPerKey) {\n // `records` are full!\n // Set `record` to an arbitrary position.\n records[(Math.random() * records.length) | 0] = record;\n }\n else {\n records.push(record);\n }\n };\n CachedKeyDecoder.prototype.decode = function (bytes, inputOffset, byteLength) {\n var cachedValue = this.find(bytes, inputOffset, byteLength);\n if (cachedValue != null) {\n this.hit++;\n return cachedValue;\n }\n this.miss++;\n var str = utf8DecodeJs(bytes, inputOffset, byteLength);\n // Ensure to copy a slice of bytes because the byte may be NodeJS Buffer and Buffer#slice() returns a reference to its internal ArrayBuffer.\n var slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);\n this.store(slicedCopyOfBytes, str);\n return str;\n };\n return CachedKeyDecoder;\n}());\nexport { CachedKeyDecoder };\n//# sourceMappingURL=CachedKeyDecoder.mjs.map","var __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar DecodeError = /** @class */ (function (_super) {\n __extends(DecodeError, _super);\n function DecodeError(message) {\n var _this = _super.call(this, message) || this;\n // fix the prototype chain in a cross-platform way\n var proto = Object.create(DecodeError.prototype);\n Object.setPrototypeOf(_this, proto);\n Object.defineProperty(_this, \"name\", {\n configurable: true,\n enumerable: false,\n value: DecodeError.name,\n });\n return _this;\n }\n return DecodeError;\n}(Error));\nexport { DecodeError };\n//# sourceMappingURL=DecodeError.mjs.map","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar __asyncValues = (this && this.__asyncValues) || function (o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n};\nvar __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }\nvar __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n};\nimport { prettyByte } from \"./utils/prettyByte.mjs\";\nimport { ExtensionCodec } from \"./ExtensionCodec.mjs\";\nimport { getInt64, getUint64, UINT32_MAX } from \"./utils/int.mjs\";\nimport { utf8DecodeJs, TEXT_DECODER_THRESHOLD, utf8DecodeTD } from \"./utils/utf8.mjs\";\nimport { createDataView, ensureUint8Array } from \"./utils/typedArrays.mjs\";\nimport { CachedKeyDecoder } from \"./CachedKeyDecoder.mjs\";\nimport { DecodeError } from \"./DecodeError.mjs\";\nvar isValidMapKeyType = function (key) {\n var keyType = typeof key;\n return keyType === \"string\" || keyType === \"number\";\n};\nvar HEAD_BYTE_REQUIRED = -1;\nvar EMPTY_VIEW = new DataView(new ArrayBuffer(0));\nvar EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);\n// IE11: Hack to support IE11.\n// IE11: Drop this hack and just use RangeError when IE11 is obsolete.\nexport var DataViewIndexOutOfBoundsError = (function () {\n try {\n // IE11: The spec says it should throw RangeError,\n // IE11: but in IE11 it throws TypeError.\n EMPTY_VIEW.getInt8(0);\n }\n catch (e) {\n return e.constructor;\n }\n throw new Error(\"never reached\");\n})();\nvar MORE_DATA = new DataViewIndexOutOfBoundsError(\"Insufficient data\");\nvar sharedCachedKeyDecoder = new CachedKeyDecoder();\nvar Decoder = /** @class */ (function () {\n function Decoder(extensionCodec, context, maxStrLength, maxBinLength, maxArrayLength, maxMapLength, maxExtLength, keyDecoder) {\n if (extensionCodec === void 0) { extensionCodec = ExtensionCodec.defaultCodec; }\n if (context === void 0) { context = undefined; }\n if (maxStrLength === void 0) { maxStrLength = UINT32_MAX; }\n if (maxBinLength === void 0) { maxBinLength = UINT32_MAX; }\n if (maxArrayLength === void 0) { maxArrayLength = UINT32_MAX; }\n if (maxMapLength === void 0) { maxMapLength = UINT32_MAX; }\n if (maxExtLength === void 0) { maxExtLength = UINT32_MAX; }\n if (keyDecoder === void 0) { keyDecoder = sharedCachedKeyDecoder; }\n this.extensionCodec = extensionCodec;\n this.context = context;\n this.maxStrLength = maxStrLength;\n this.maxBinLength = maxBinLength;\n this.maxArrayLength = maxArrayLength;\n this.maxMapLength = maxMapLength;\n this.maxExtLength = maxExtLength;\n this.keyDecoder = keyDecoder;\n this.totalPos = 0;\n this.pos = 0;\n this.view = EMPTY_VIEW;\n this.bytes = EMPTY_BYTES;\n this.headByte = HEAD_BYTE_REQUIRED;\n this.stack = [];\n }\n Decoder.prototype.reinitializeState = function () {\n this.totalPos = 0;\n this.headByte = HEAD_BYTE_REQUIRED;\n this.stack.length = 0;\n // view, bytes, and pos will be re-initialized in setBuffer()\n };\n Decoder.prototype.setBuffer = function (buffer) {\n this.bytes = ensureUint8Array(buffer);\n this.view = createDataView(this.bytes);\n this.pos = 0;\n };\n Decoder.prototype.appendBuffer = function (buffer) {\n if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {\n this.setBuffer(buffer);\n }\n else {\n var remainingData = this.bytes.subarray(this.pos);\n var newData = ensureUint8Array(buffer);\n // concat remainingData + newData\n var newBuffer = new Uint8Array(remainingData.length + newData.length);\n newBuffer.set(remainingData);\n newBuffer.set(newData, remainingData.length);\n this.setBuffer(newBuffer);\n }\n };\n Decoder.prototype.hasRemaining = function (size) {\n return this.view.byteLength - this.pos >= size;\n };\n Decoder.prototype.createExtraByteError = function (posToShow) {\n var _a = this, view = _a.view, pos = _a.pos;\n return new RangeError(\"Extra \" + (view.byteLength - pos) + \" of \" + view.byteLength + \" byte(s) found at buffer[\" + posToShow + \"]\");\n };\n /**\n * @throws {DecodeError}\n * @throws {RangeError}\n */\n Decoder.prototype.decode = function (buffer) {\n this.reinitializeState();\n this.setBuffer(buffer);\n var object = this.doDecodeSync();\n if (this.hasRemaining(1)) {\n throw this.createExtraByteError(this.pos);\n }\n return object;\n };\n Decoder.prototype.decodeMulti = function (buffer) {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n this.reinitializeState();\n this.setBuffer(buffer);\n _a.label = 1;\n case 1:\n if (!this.hasRemaining(1)) return [3 /*break*/, 3];\n return [4 /*yield*/, this.doDecodeSync()];\n case 2:\n _a.sent();\n return [3 /*break*/, 1];\n case 3: return [2 /*return*/];\n }\n });\n };\n Decoder.prototype.decodeAsync = function (stream) {\n var stream_1, stream_1_1;\n var e_1, _a;\n return __awaiter(this, void 0, void 0, function () {\n var decoded, object, buffer, e_1_1, _b, headByte, pos, totalPos;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0:\n decoded = false;\n _c.label = 1;\n case 1:\n _c.trys.push([1, 6, 7, 12]);\n stream_1 = __asyncValues(stream);\n _c.label = 2;\n case 2: return [4 /*yield*/, stream_1.next()];\n case 3:\n if (!(stream_1_1 = _c.sent(), !stream_1_1.done)) return [3 /*break*/, 5];\n buffer = stream_1_1.value;\n if (decoded) {\n throw this.createExtraByteError(this.totalPos);\n }\n this.appendBuffer(buffer);\n try {\n object = this.doDecodeSync();\n decoded = true;\n }\n catch (e) {\n if (!(e instanceof DataViewIndexOutOfBoundsError)) {\n throw e; // rethrow\n }\n // fallthrough\n }\n this.totalPos += this.pos;\n _c.label = 4;\n case 4: return [3 /*break*/, 2];\n case 5: return [3 /*break*/, 12];\n case 6:\n e_1_1 = _c.sent();\n e_1 = { error: e_1_1 };\n return [3 /*break*/, 12];\n case 7:\n _c.trys.push([7, , 10, 11]);\n if (!(stream_1_1 && !stream_1_1.done && (_a = stream_1.return))) return [3 /*break*/, 9];\n return [4 /*yield*/, _a.call(stream_1)];\n case 8:\n _c.sent();\n _c.label = 9;\n case 9: return [3 /*break*/, 11];\n case 10:\n if (e_1) throw e_1.error;\n return [7 /*endfinally*/];\n case 11: return [7 /*endfinally*/];\n case 12:\n if (decoded) {\n if (this.hasRemaining(1)) {\n throw this.createExtraByteError(this.totalPos);\n }\n return [2 /*return*/, object];\n }\n _b = this, headByte = _b.headByte, pos = _b.pos, totalPos = _b.totalPos;\n throw new RangeError(\"Insufficient data in parsing \" + prettyByte(headByte) + \" at \" + totalPos + \" (\" + pos + \" in the current buffer)\");\n }\n });\n });\n };\n Decoder.prototype.decodeArrayStream = function (stream) {\n return this.decodeMultiAsync(stream, true);\n };\n Decoder.prototype.decodeStream = function (stream) {\n return this.decodeMultiAsync(stream, false);\n };\n Decoder.prototype.decodeMultiAsync = function (stream, isArray) {\n return __asyncGenerator(this, arguments, function decodeMultiAsync_1() {\n var isArrayHeaderRequired, arrayItemsLeft, stream_2, stream_2_1, buffer, e_2, e_3_1;\n var e_3, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n isArrayHeaderRequired = isArray;\n arrayItemsLeft = -1;\n _b.label = 1;\n case 1:\n _b.trys.push([1, 13, 14, 19]);\n stream_2 = __asyncValues(stream);\n _b.label = 2;\n case 2: return [4 /*yield*/, __await(stream_2.next())];\n case 3:\n if (!(stream_2_1 = _b.sent(), !stream_2_1.done)) return [3 /*break*/, 12];\n buffer = stream_2_1.value;\n if (isArray && arrayItemsLeft === 0) {\n throw this.createExtraByteError(this.totalPos);\n }\n this.appendBuffer(buffer);\n if (isArrayHeaderRequired) {\n arrayItemsLeft = this.readArraySize();\n isArrayHeaderRequired = false;\n this.complete();\n }\n _b.label = 4;\n case 4:\n _b.trys.push([4, 9, , 10]);\n _b.label = 5;\n case 5:\n if (!true) return [3 /*break*/, 8];\n return [4 /*yield*/, __await(this.doDecodeSync())];\n case 6: return [4 /*yield*/, _b.sent()];\n case 7:\n _b.sent();\n if (--arrayItemsLeft === 0) {\n return [3 /*break*/, 8];\n }\n return [3 /*break*/, 5];\n case 8: return [3 /*break*/, 10];\n case 9:\n e_2 = _b.sent();\n if (!(e_2 instanceof DataViewIndexOutOfBoundsError)) {\n throw e_2; // rethrow\n }\n return [3 /*break*/, 10];\n case 10:\n this.totalPos += this.pos;\n _b.label = 11;\n case 11: return [3 /*break*/, 2];\n case 12: return [3 /*break*/, 19];\n case 13:\n e_3_1 = _b.sent();\n e_3 = { error: e_3_1 };\n return [3 /*break*/, 19];\n case 14:\n _b.trys.push([14, , 17, 18]);\n if (!(stream_2_1 && !stream_2_1.done && (_a = stream_2.return))) return [3 /*break*/, 16];\n return [4 /*yield*/, __await(_a.call(stream_2))];\n case 15:\n _b.sent();\n _b.label = 16;\n case 16: return [3 /*break*/, 18];\n case 17:\n if (e_3) throw e_3.error;\n return [7 /*endfinally*/];\n case 18: return [7 /*endfinally*/];\n case 19: return [2 /*return*/];\n }\n });\n });\n };\n Decoder.prototype.doDecodeSync = function () {\n DECODE: while (true) {\n var headByte = this.readHeadByte();\n var object = void 0;\n if (headByte >= 0xe0) {\n // negative fixint (111x xxxx) 0xe0 - 0xff\n object = headByte - 0x100;\n }\n else if (headByte < 0xc0) {\n if (headByte < 0x80) {\n // positive fixint (0xxx xxxx) 0x00 - 0x7f\n object = headByte;\n }\n else if (headByte < 0x90) {\n // fixmap (1000 xxxx) 0x80 - 0x8f\n var size = headByte - 0x80;\n if (size !== 0) {\n this.pushMapState(size);\n this.complete();\n continue DECODE;\n }\n else {\n object = {};\n }\n }\n else if (headByte < 0xa0) {\n // fixarray (1001 xxxx) 0x90 - 0x9f\n var size = headByte - 0x90;\n if (size !== 0) {\n this.pushArrayState(size);\n this.complete();\n continue DECODE;\n }\n else {\n object = [];\n }\n }\n else {\n // fixstr (101x xxxx) 0xa0 - 0xbf\n var byteLength = headByte - 0xa0;\n object = this.decodeUtf8String(byteLength, 0);\n }\n }\n else if (headByte === 0xc0) {\n // nil\n object = null;\n }\n else if (headByte === 0xc2) {\n // false\n object = false;\n }\n else if (headByte === 0xc3) {\n // true\n object = true;\n }\n else if (headByte === 0xca) {\n // float 32\n object = this.readF32();\n }\n else if (headByte === 0xcb) {\n // float 64\n object = this.readF64();\n }\n else if (headByte === 0xcc) {\n // uint 8\n object = this.readU8();\n }\n else if (headByte === 0xcd) {\n // uint 16\n object = this.readU16();\n }\n else if (headByte === 0xce) {\n // uint 32\n object = this.readU32();\n }\n else if (headByte === 0xcf) {\n // uint 64\n object = this.readU64();\n }\n else if (headByte === 0xd0) {\n // int 8\n object = this.readI8();\n }\n else if (headByte === 0xd1) {\n // int 16\n object = this.readI16();\n }\n else if (headByte === 0xd2) {\n // int 32\n object = this.readI32();\n }\n else if (headByte === 0xd3) {\n // int 64\n object = this.readI64();\n }\n else if (headByte === 0xd9) {\n // str 8\n var byteLength = this.lookU8();\n object = this.decodeUtf8String(byteLength, 1);\n }\n else if (headByte === 0xda) {\n // str 16\n var byteLength = this.lookU16();\n object = this.decodeUtf8String(byteLength, 2);\n }\n else if (headByte === 0xdb) {\n // str 32\n var byteLength = this.lookU32();\n object = this.decodeUtf8String(byteLength, 4);\n }\n else if (headByte === 0xdc) {\n // array 16\n var size = this.readU16();\n if (size !== 0) {\n this.pushArrayState(size);\n this.complete();\n continue DECODE;\n }\n else {\n object = [];\n }\n }\n else if (headByte === 0xdd) {\n // array 32\n var size = this.readU32();\n if (size !== 0) {\n this.pushArrayState(size);\n this.complete();\n continue DECODE;\n }\n else {\n object = [];\n }\n }\n else if (headByte === 0xde) {\n // map 16\n var size = this.readU16();\n if (size !== 0) {\n this.pushMapState(size);\n this.complete();\n continue DECODE;\n }\n else {\n object = {};\n }\n }\n else if (headByte === 0xdf) {\n // map 32\n var size = this.readU32();\n if (size !== 0) {\n this.pushMapState(size);\n this.complete();\n continue DECODE;\n }\n else {\n object = {};\n }\n }\n else if (headByte === 0xc4) {\n // bin 8\n var size = this.lookU8();\n object = this.decodeBinary(size, 1);\n }\n else if (headByte === 0xc5) {\n // bin 16\n var size = this.lookU16();\n object = this.decodeBinary(size, 2);\n }\n else if (headByte === 0xc6) {\n // bin 32\n var size = this.lookU32();\n object = this.decodeBinary(size, 4);\n }\n else if (headByte === 0xd4) {\n // fixext 1\n object = this.decodeExtension(1, 0);\n }\n else if (headByte === 0xd5) {\n // fixext 2\n object = this.decodeExtension(2, 0);\n }\n else if (headByte === 0xd6) {\n // fixext 4\n object = this.decodeExtension(4, 0);\n }\n else if (headByte === 0xd7) {\n // fixext 8\n object = this.decodeExtension(8, 0);\n }\n else if (headByte === 0xd8) {\n // fixext 16\n object = this.decodeExtension(16, 0);\n }\n else if (headByte === 0xc7) {\n // ext 8\n var size = this.lookU8();\n object = this.decodeExtension(size, 1);\n }\n else if (headByte === 0xc8) {\n // ext 16\n var size = this.lookU16();\n object = this.decodeExtension(size, 2);\n }\n else if (headByte === 0xc9) {\n // ext 32\n var size = this.lookU32();\n object = this.decodeExtension(size, 4);\n }\n else {\n throw new DecodeError(\"Unrecognized type byte: \" + prettyByte(headByte));\n }\n this.complete();\n var stack = this.stack;\n while (stack.length > 0) {\n // arrays and maps\n var state = stack[stack.length - 1];\n if (state.type === 0 /* ARRAY */) {\n state.array[state.position] = object;\n state.position++;\n if (state.position === state.size) {\n stack.pop();\n object = state.array;\n }\n else {\n continue DECODE;\n }\n }\n else if (state.type === 1 /* MAP_KEY */) {\n if (!isValidMapKeyType(object)) {\n throw new DecodeError(\"The type of key must be string or number but \" + typeof object);\n }\n if (object === \"__proto__\") {\n throw new DecodeError(\"The key __proto__ is not allowed\");\n }\n state.key = object;\n state.type = 2 /* MAP_VALUE */;\n continue DECODE;\n }\n else {\n // it must be `state.type === State.MAP_VALUE` here\n state.map[state.key] = object;\n state.readCount++;\n if (state.readCount === state.size) {\n stack.pop();\n object = state.map;\n }\n else {\n state.key = null;\n state.type = 1 /* MAP_KEY */;\n continue DECODE;\n }\n }\n }\n return object;\n }\n };\n Decoder.prototype.readHeadByte = function () {\n if (this.headByte === HEAD_BYTE_REQUIRED) {\n this.headByte = this.readU8();\n // console.log(\"headByte\", prettyByte(this.headByte));\n }\n return this.headByte;\n };\n Decoder.prototype.complete = function () {\n this.headByte = HEAD_BYTE_REQUIRED;\n };\n Decoder.prototype.readArraySize = function () {\n var headByte = this.readHeadByte();\n switch (headByte) {\n case 0xdc:\n return this.readU16();\n case 0xdd:\n return this.readU32();\n default: {\n if (headByte < 0xa0) {\n return headByte - 0x90;\n }\n else {\n throw new DecodeError(\"Unrecognized array type byte: \" + prettyByte(headByte));\n }\n }\n }\n };\n Decoder.prototype.pushMapState = function (size) {\n if (size > this.maxMapLength) {\n throw new DecodeError(\"Max length exceeded: map length (\" + size + \") > maxMapLengthLength (\" + this.maxMapLength + \")\");\n }\n this.stack.push({\n type: 1 /* MAP_KEY */,\n size: size,\n key: null,\n readCount: 0,\n map: {},\n });\n };\n Decoder.prototype.pushArrayState = function (size) {\n if (size > this.maxArrayLength) {\n throw new DecodeError(\"Max length exceeded: array length (\" + size + \") > maxArrayLength (\" + this.maxArrayLength + \")\");\n }\n this.stack.push({\n type: 0 /* ARRAY */,\n size: size,\n array: new Array(size),\n position: 0,\n });\n };\n Decoder.prototype.decodeUtf8String = function (byteLength, headerOffset) {\n var _a;\n if (byteLength > this.maxStrLength) {\n throw new DecodeError(\"Max length exceeded: UTF-8 byte length (\" + byteLength + \") > maxStrLength (\" + this.maxStrLength + \")\");\n }\n if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {\n throw MORE_DATA;\n }\n var offset = this.pos + headerOffset;\n var object;\n if (this.stateIsMapKey() && ((_a = this.keyDecoder) === null || _a === void 0 ? void 0 : _a.canBeCached(byteLength))) {\n object = this.keyDecoder.decode(this.bytes, offset, byteLength);\n }\n else if (byteLength > TEXT_DECODER_THRESHOLD) {\n object = utf8DecodeTD(this.bytes, offset, byteLength);\n }\n else {\n object = utf8DecodeJs(this.bytes, offset, byteLength);\n }\n this.pos += headerOffset + byteLength;\n return object;\n };\n Decoder.prototype.stateIsMapKey = function () {\n if (this.stack.length > 0) {\n var state = this.stack[this.stack.length - 1];\n return state.type === 1 /* MAP_KEY */;\n }\n return false;\n };\n Decoder.prototype.decodeBinary = function (byteLength, headOffset) {\n if (byteLength > this.maxBinLength) {\n throw new DecodeError(\"Max length exceeded: bin length (\" + byteLength + \") > maxBinLength (\" + this.maxBinLength + \")\");\n }\n if (!this.hasRemaining(byteLength + headOffset)) {\n throw MORE_DATA;\n }\n var offset = this.pos + headOffset;\n var object = this.bytes.subarray(offset, offset + byteLength);\n this.pos += headOffset + byteLength;\n return object;\n };\n Decoder.prototype.decodeExtension = function (size, headOffset) {\n if (size > this.maxExtLength) {\n throw new DecodeError(\"Max length exceeded: ext length (\" + size + \") > maxExtLength (\" + this.maxExtLength + \")\");\n }\n var extType = this.view.getInt8(this.pos + headOffset);\n var data = this.decodeBinary(size, headOffset + 1 /* extType */);\n return this.extensionCodec.decode(data, extType, this.context);\n };\n Decoder.prototype.lookU8 = function () {\n return this.view.getUint8(this.pos);\n };\n Decoder.prototype.lookU16 = function () {\n return this.view.getUint16(this.pos);\n };\n Decoder.prototype.lookU32 = function () {\n return this.view.getUint32(this.pos);\n };\n Decoder.prototype.readU8 = function () {\n var value = this.view.getUint8(this.pos);\n this.pos++;\n return value;\n };\n Decoder.prototype.readI8 = function () {\n var value = this.view.getInt8(this.pos);\n this.pos++;\n return value;\n };\n Decoder.prototype.readU16 = function () {\n var value = this.view.getUint16(this.pos);\n this.pos += 2;\n return value;\n };\n Decoder.prototype.readI16 = function () {\n var value = this.view.getInt16(this.pos);\n this.pos += 2;\n return value;\n };\n Decoder.prototype.readU32 = function () {\n var value = this.view.getUint32(this.pos);\n this.pos += 4;\n return value;\n };\n Decoder.prototype.readI32 = function () {\n var value = this.view.getInt32(this.pos);\n this.pos += 4;\n return value;\n };\n Decoder.prototype.readU64 = function () {\n var value = getUint64(this.view, this.pos);\n this.pos += 8;\n return value;\n };\n Decoder.prototype.readI64 = function () {\n var value = getInt64(this.view, this.pos);\n this.pos += 8;\n return value;\n };\n Decoder.prototype.readF32 = function () {\n var value = this.view.getFloat32(this.pos);\n this.pos += 4;\n return value;\n };\n Decoder.prototype.readF64 = function () {\n var value = this.view.getFloat64(this.pos);\n this.pos += 8;\n return value;\n };\n return Decoder;\n}());\nexport { Decoder };\n//# sourceMappingURL=Decoder.mjs.map","import { utf8EncodeJs, utf8Count, TEXT_ENCODER_THRESHOLD, utf8EncodeTE } from \"./utils/utf8.mjs\";\nimport { ExtensionCodec } from \"./ExtensionCodec.mjs\";\nimport { setInt64, setUint64 } from \"./utils/int.mjs\";\nimport { ensureUint8Array } from \"./utils/typedArrays.mjs\";\nexport var DEFAULT_MAX_DEPTH = 100;\nexport var DEFAULT_INITIAL_BUFFER_SIZE = 2048;\nvar Encoder = /** @class */ (function () {\n function Encoder(extensionCodec, context, maxDepth, initialBufferSize, sortKeys, forceFloat32, ignoreUndefined, forceIntegerToFloat) {\n if (extensionCodec === void 0) { extensionCodec = ExtensionCodec.defaultCodec; }\n if (context === void 0) { context = undefined; }\n if (maxDepth === void 0) { maxDepth = DEFAULT_MAX_DEPTH; }\n if (initialBufferSize === void 0) { initialBufferSize = DEFAULT_INITIAL_BUFFER_SIZE; }\n if (sortKeys === void 0) { sortKeys = false; }\n if (forceFloat32 === void 0) { forceFloat32 = false; }\n if (ignoreUndefined === void 0) { ignoreUndefined = false; }\n if (forceIntegerToFloat === void 0) { forceIntegerToFloat = false; }\n this.extensionCodec = extensionCodec;\n this.context = context;\n this.maxDepth = maxDepth;\n this.initialBufferSize = initialBufferSize;\n this.sortKeys = sortKeys;\n this.forceFloat32 = forceFloat32;\n this.ignoreUndefined = ignoreUndefined;\n this.forceIntegerToFloat = forceIntegerToFloat;\n this.pos = 0;\n this.view = new DataView(new ArrayBuffer(this.initialBufferSize));\n this.bytes = new Uint8Array(this.view.buffer);\n }\n Encoder.prototype.getUint8Array = function () {\n return this.bytes.subarray(0, this.pos);\n };\n Encoder.prototype.reinitializeState = function () {\n this.pos = 0;\n };\n Encoder.prototype.encode = function (object) {\n this.reinitializeState();\n this.doEncode(object, 1);\n return this.getUint8Array();\n };\n Encoder.prototype.doEncode = function (object, depth) {\n if (depth > this.maxDepth) {\n throw new Error(\"Too deep objects in depth \" + depth);\n }\n if (object == null) {\n this.encodeNil();\n }\n else if (typeof object === \"boolean\") {\n this.encodeBoolean(object);\n }\n else if (typeof object === \"number\") {\n this.encodeNumber(object);\n }\n else if (typeof object === \"string\") {\n this.encodeString(object);\n }\n else {\n this.encodeObject(object, depth);\n }\n };\n Encoder.prototype.ensureBufferSizeToWrite = function (sizeToWrite) {\n var requiredSize = this.pos + sizeToWrite;\n if (this.view.byteLength < requiredSize) {\n this.resizeBuffer(requiredSize * 2);\n }\n };\n Encoder.prototype.resizeBuffer = function (newSize) {\n var newBuffer = new ArrayBuffer(newSize);\n var newBytes = new Uint8Array(newBuffer);\n var newView = new DataView(newBuffer);\n newBytes.set(this.bytes);\n this.view = newView;\n this.bytes = newBytes;\n };\n Encoder.prototype.encodeNil = function () {\n this.writeU8(0xc0);\n };\n Encoder.prototype.encodeBoolean = function (object) {\n if (object === false) {\n this.writeU8(0xc2);\n }\n else {\n this.writeU8(0xc3);\n }\n };\n Encoder.prototype.encodeNumber = function (object) {\n if (Number.isSafeInteger(object) && !this.forceIntegerToFloat) {\n if (object >= 0) {\n if (object < 0x80) {\n // positive fixint\n this.writeU8(object);\n }\n else if (object < 0x100) {\n // uint 8\n this.writeU8(0xcc);\n this.writeU8(object);\n }\n else if (object < 0x10000) {\n // uint 16\n this.writeU8(0xcd);\n this.writeU16(object);\n }\n else if (object < 0x100000000) {\n // uint 32\n this.writeU8(0xce);\n this.writeU32(object);\n }\n else {\n // uint 64\n this.writeU8(0xcf);\n this.writeU64(object);\n }\n }\n else {\n if (object >= -0x20) {\n // negative fixint\n this.writeU8(0xe0 | (object + 0x20));\n }\n else if (object >= -0x80) {\n // int 8\n this.writeU8(0xd0);\n this.writeI8(object);\n }\n else if (object >= -0x8000) {\n // int 16\n this.writeU8(0xd1);\n this.writeI16(object);\n }\n else if (object >= -0x80000000) {\n // int 32\n this.writeU8(0xd2);\n this.writeI32(object);\n }\n else {\n // int 64\n this.writeU8(0xd3);\n this.writeI64(object);\n }\n }\n }\n else {\n // non-integer numbers\n if (this.forceFloat32) {\n // float 32\n this.writeU8(0xca);\n this.writeF32(object);\n }\n else {\n // float 64\n this.writeU8(0xcb);\n this.writeF64(object);\n }\n }\n };\n Encoder.prototype.writeStringHeader = function (byteLength) {\n if (byteLength < 32) {\n // fixstr\n this.writeU8(0xa0 + byteLength);\n }\n else if (byteLength < 0x100) {\n // str 8\n this.writeU8(0xd9);\n this.writeU8(byteLength);\n }\n else if (byteLength < 0x10000) {\n // str 16\n this.writeU8(0xda);\n this.writeU16(byteLength);\n }\n else if (byteLength < 0x100000000) {\n // str 32\n this.writeU8(0xdb);\n this.writeU32(byteLength);\n }\n else {\n throw new Error(\"Too long string: \" + byteLength + \" bytes in UTF-8\");\n }\n };\n Encoder.prototype.encodeString = function (object) {\n var maxHeaderSize = 1 + 4;\n var strLength = object.length;\n if (strLength > TEXT_ENCODER_THRESHOLD) {\n var byteLength = utf8Count(object);\n this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);\n this.writeStringHeader(byteLength);\n utf8EncodeTE(object, this.bytes, this.pos);\n this.pos += byteLength;\n }\n else {\n var byteLength = utf8Count(object);\n this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);\n this.writeStringHeader(byteLength);\n utf8EncodeJs(object, this.bytes, this.pos);\n this.pos += byteLength;\n }\n };\n Encoder.prototype.encodeObject = function (object, depth) {\n // try to encode objects with custom codec first of non-primitives\n var ext = this.extensionCodec.tryToEncode(object, this.context);\n if (ext != null) {\n this.encodeExtension(ext);\n }\n else if (Array.isArray(object)) {\n this.encodeArray(object, depth);\n }\n else if (ArrayBuffer.isView(object)) {\n this.encodeBinary(object);\n }\n else if (typeof object === \"object\") {\n this.encodeMap(object, depth);\n }\n else {\n // symbol, function and other special object come here unless extensionCodec handles them.\n throw new Error(\"Unrecognized object: \" + Object.prototype.toString.apply(object));\n }\n };\n Encoder.prototype.encodeBinary = function (object) {\n var size = object.byteLength;\n if (size < 0x100) {\n // bin 8\n this.writeU8(0xc4);\n this.writeU8(size);\n }\n else if (size < 0x10000) {\n // bin 16\n this.writeU8(0xc5);\n this.writeU16(size);\n }\n else if (size < 0x100000000) {\n // bin 32\n this.writeU8(0xc6);\n this.writeU32(size);\n }\n else {\n throw new Error(\"Too large binary: \" + size);\n }\n var bytes = ensureUint8Array(object);\n this.writeU8a(bytes);\n };\n Encoder.prototype.encodeArray = function (object, depth) {\n var size = object.length;\n if (size < 16) {\n // fixarray\n this.writeU8(0x90 + size);\n }\n else if (size < 0x10000) {\n // array 16\n this.writeU8(0xdc);\n this.writeU16(size);\n }\n else if (size < 0x100000000) {\n // array 32\n this.writeU8(0xdd);\n this.writeU32(size);\n }\n else {\n throw new Error(\"Too large array: \" + size);\n }\n for (var _i = 0, object_1 = object; _i < object_1.length; _i++) {\n var item = object_1[_i];\n this.doEncode(item, depth + 1);\n }\n };\n Encoder.prototype.countWithoutUndefined = function (object, keys) {\n var count = 0;\n for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {\n var key = keys_1[_i];\n if (object[key] !== undefined) {\n count++;\n }\n }\n return count;\n };\n Encoder.prototype.encodeMap = function (object, depth) {\n var keys = Object.keys(object);\n if (this.sortKeys) {\n keys.sort();\n }\n var size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;\n if (size < 16) {\n // fixmap\n this.writeU8(0x80 + size);\n }\n else if (size < 0x10000) {\n // map 16\n this.writeU8(0xde);\n this.writeU16(size);\n }\n else if (size < 0x100000000) {\n // map 32\n this.writeU8(0xdf);\n this.writeU32(size);\n }\n else {\n throw new Error(\"Too large map object: \" + size);\n }\n for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {\n var key = keys_2[_i];\n var value = object[key];\n if (!(this.ignoreUndefined && value === undefined)) {\n this.encodeString(key);\n this.doEncode(value, depth + 1);\n }\n }\n };\n Encoder.prototype.encodeExtension = function (ext) {\n var size = ext.data.length;\n if (size === 1) {\n // fixext 1\n this.writeU8(0xd4);\n }\n else if (size === 2) {\n // fixext 2\n this.writeU8(0xd5);\n }\n else if (size === 4) {\n // fixext 4\n this.writeU8(0xd6);\n }\n else if (size === 8) {\n // fixext 8\n this.writeU8(0xd7);\n }\n else if (size === 16) {\n // fixext 16\n this.writeU8(0xd8);\n }\n else if (size < 0x100) {\n // ext 8\n this.writeU8(0xc7);\n this.writeU8(size);\n }\n else if (size < 0x10000) {\n // ext 16\n this.writeU8(0xc8);\n this.writeU16(size);\n }\n else if (size < 0x100000000) {\n // ext 32\n this.writeU8(0xc9);\n this.writeU32(size);\n }\n else {\n throw new Error(\"Too large extension object: \" + size);\n }\n this.writeI8(ext.type);\n this.writeU8a(ext.data);\n };\n Encoder.prototype.writeU8 = function (value) {\n this.ensureBufferSizeToWrite(1);\n this.view.setUint8(this.pos, value);\n this.pos++;\n };\n Encoder.prototype.writeU8a = function (values) {\n var size = values.length;\n this.ensureBufferSizeToWrite(size);\n this.bytes.set(values, this.pos);\n this.pos += size;\n };\n Encoder.prototype.writeI8 = function (value) {\n this.ensureBufferSizeToWrite(1);\n this.view.setInt8(this.pos, value);\n this.pos++;\n };\n Encoder.prototype.writeU16 = function (value) {\n this.ensureBufferSizeToWrite(2);\n this.view.setUint16(this.pos, value);\n this.pos += 2;\n };\n Encoder.prototype.writeI16 = function (value) {\n this.ensureBufferSizeToWrite(2);\n this.view.setInt16(this.pos, value);\n this.pos += 2;\n };\n Encoder.prototype.writeU32 = function (value) {\n this.ensureBufferSizeToWrite(4);\n this.view.setUint32(this.pos, value);\n this.pos += 4;\n };\n Encoder.prototype.writeI32 = function (value) {\n this.ensureBufferSizeToWrite(4);\n this.view.setInt32(this.pos, value);\n this.pos += 4;\n };\n Encoder.prototype.writeF32 = function (value) {\n this.ensureBufferSizeToWrite(4);\n this.view.setFloat32(this.pos, value);\n this.pos += 4;\n };\n Encoder.prototype.writeF64 = function (value) {\n this.ensureBufferSizeToWrite(8);\n this.view.setFloat64(this.pos, value);\n this.pos += 8;\n };\n Encoder.prototype.writeU64 = function (value) {\n this.ensureBufferSizeToWrite(8);\n setUint64(this.view, this.pos, value);\n this.pos += 8;\n };\n Encoder.prototype.writeI64 = function (value) {\n this.ensureBufferSizeToWrite(8);\n setInt64(this.view, this.pos, value);\n this.pos += 8;\n };\n return Encoder;\n}());\nexport { Encoder };\n//# sourceMappingURL=Encoder.mjs.map","/**\n * ExtData is used to handle Extension Types that are not registered to ExtensionCodec.\n */\nvar ExtData = /** @class */ (function () {\n function ExtData(type, data) {\n this.type = type;\n this.data = data;\n }\n return ExtData;\n}());\nexport { ExtData };\n//# sourceMappingURL=ExtData.mjs.map","// ExtensionCodec to handle MessagePack extensions\nimport { ExtData } from \"./ExtData.mjs\";\nimport { timestampExtension } from \"./timestamp.mjs\";\nvar ExtensionCodec = /** @class */ (function () {\n function ExtensionCodec() {\n // built-in extensions\n this.builtInEncoders = [];\n this.builtInDecoders = [];\n // custom extensions\n this.encoders = [];\n this.decoders = [];\n this.register(timestampExtension);\n }\n ExtensionCodec.prototype.register = function (_a) {\n var type = _a.type, encode = _a.encode, decode = _a.decode;\n if (type >= 0) {\n // custom extensions\n this.encoders[type] = encode;\n this.decoders[type] = decode;\n }\n else {\n // built-in extensions\n var index = 1 + type;\n this.builtInEncoders[index] = encode;\n this.builtInDecoders[index] = decode;\n }\n };\n ExtensionCodec.prototype.tryToEncode = function (object, context) {\n // built-in extensions\n for (var i = 0; i < this.builtInEncoders.length; i++) {\n var encodeExt = this.builtInEncoders[i];\n if (encodeExt != null) {\n var data = encodeExt(object, context);\n if (data != null) {\n var type = -1 - i;\n return new ExtData(type, data);\n }\n }\n }\n // custom extensions\n for (var i = 0; i < this.encoders.length; i++) {\n var encodeExt = this.encoders[i];\n if (encodeExt != null) {\n var data = encodeExt(object, context);\n if (data != null) {\n var type = i;\n return new ExtData(type, data);\n }\n }\n }\n if (object instanceof ExtData) {\n // to keep ExtData as is\n return object;\n }\n return null;\n };\n ExtensionCodec.prototype.decode = function (data, type, context) {\n var decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];\n if (decodeExt) {\n return decodeExt(data, type, context);\n }\n else {\n // decode() does not fail, returns ExtData instead.\n return new ExtData(type, data);\n }\n };\n ExtensionCodec.defaultCodec = new ExtensionCodec();\n return ExtensionCodec;\n}());\nexport { ExtensionCodec };\n//# sourceMappingURL=ExtensionCodec.mjs.map","import { Decoder } from \"./Decoder.mjs\";\nexport var defaultDecodeOptions = {};\n/**\n * It decodes a single MessagePack object in a buffer.\n *\n * This is a synchronous decoding function.\n * See other variants for asynchronous decoding: {@link decodeAsync()}, {@link decodeStream()}, or {@link decodeArrayStream()}.\n */\nexport function decode(buffer, options) {\n if (options === void 0) { options = defaultDecodeOptions; }\n var decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);\n return decoder.decode(buffer);\n}\n/**\n * It decodes multiple MessagePack objects in a buffer.\n * This is corresponding to {@link decodeMultiStream()}.\n */\nexport function decodeMulti(buffer, options) {\n if (options === void 0) { options = defaultDecodeOptions; }\n var decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);\n return decoder.decodeMulti(buffer);\n}\n//# sourceMappingURL=decode.mjs.map","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nimport { Decoder } from \"./Decoder.mjs\";\nimport { ensureAsyncIterable } from \"./utils/stream.mjs\";\nimport { defaultDecodeOptions } from \"./decode.mjs\";\nexport function decodeAsync(streamLike, options) {\n if (options === void 0) { options = defaultDecodeOptions; }\n return __awaiter(this, void 0, void 0, function () {\n var stream, decoder;\n return __generator(this, function (_a) {\n stream = ensureAsyncIterable(streamLike);\n decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);\n return [2 /*return*/, decoder.decodeAsync(stream)];\n });\n });\n}\nexport function decodeArrayStream(streamLike, options) {\n if (options === void 0) { options = defaultDecodeOptions; }\n var stream = ensureAsyncIterable(streamLike);\n var decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);\n return decoder.decodeArrayStream(stream);\n}\nexport function decodeMultiStream(streamLike, options) {\n if (options === void 0) { options = defaultDecodeOptions; }\n var stream = ensureAsyncIterable(streamLike);\n var decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);\n return decoder.decodeStream(stream);\n}\n/**\n * @deprecated Use {@link decodeMultiStream()} instead.\n */\nexport function decodeStream(streamLike, options) {\n if (options === void 0) { options = defaultDecodeOptions; }\n return decodeMultiStream(streamLike, options);\n}\n//# sourceMappingURL=decodeAsync.mjs.map","import { Encoder } from \"./Encoder.mjs\";\nvar defaultEncodeOptions = {};\n/**\n * It encodes `value` in the MessagePack format and\n * returns a byte buffer.\n *\n * The returned buffer is a slice of a larger `ArrayBuffer`, so you have to use its `#byteOffset` and `#byteLength` in order to convert it to another typed arrays including NodeJS `Buffer`.\n */\nexport function encode(value, options) {\n if (options === void 0) { options = defaultEncodeOptions; }\n var encoder = new Encoder(options.extensionCodec, options.context, options.maxDepth, options.initialBufferSize, options.sortKeys, options.forceFloat32, options.ignoreUndefined, options.forceIntegerToFloat);\n return encoder.encode(value);\n}\n//# sourceMappingURL=encode.mjs.map","// Main Functions:\nimport { encode } from \"./encode.mjs\";\nexport { encode };\nimport { decode, decodeMulti } from \"./decode.mjs\";\nexport { decode, decodeMulti };\nimport { decodeAsync, decodeArrayStream, decodeMultiStream, decodeStream } from \"./decodeAsync.mjs\";\nexport { decodeAsync, decodeArrayStream, decodeMultiStream, decodeStream };\nimport { Decoder, DataViewIndexOutOfBoundsError } from \"./Decoder.mjs\";\nimport { DecodeError } from \"./DecodeError.mjs\";\nexport { Decoder, DecodeError, DataViewIndexOutOfBoundsError };\nimport { Encoder } from \"./Encoder.mjs\";\nexport { Encoder };\n// Utilitiies for Extension Types:\nimport { ExtensionCodec } from \"./ExtensionCodec.mjs\";\nexport { ExtensionCodec };\nimport { ExtData } from \"./ExtData.mjs\";\nexport { ExtData };\nimport { EXT_TIMESTAMP, encodeDateToTimeSpec, encodeTimeSpecToTimestamp, decodeTimestampToTimeSpec, encodeTimestampExtension, decodeTimestampExtension, } from \"./timestamp.mjs\";\nexport { EXT_TIMESTAMP, encodeDateToTimeSpec, encodeTimeSpecToTimestamp, decodeTimestampToTimeSpec, encodeTimestampExtension, decodeTimestampExtension, };\n//# sourceMappingURL=index.mjs.map","// https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type\nimport { DecodeError } from \"./DecodeError.mjs\";\nimport { getInt64, setInt64 } from \"./utils/int.mjs\";\nexport var EXT_TIMESTAMP = -1;\nvar TIMESTAMP32_MAX_SEC = 0x100000000 - 1; // 32-bit unsigned int\nvar TIMESTAMP64_MAX_SEC = 0x400000000 - 1; // 34-bit unsigned int\nexport function encodeTimeSpecToTimestamp(_a) {\n var sec = _a.sec, nsec = _a.nsec;\n if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {\n // Here sec >= 0 && nsec >= 0\n if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {\n // timestamp 32 = { sec32 (unsigned) }\n var rv = new Uint8Array(4);\n var view = new DataView(rv.buffer);\n view.setUint32(0, sec);\n return rv;\n }\n else {\n // timestamp 64 = { nsec30 (unsigned), sec34 (unsigned) }\n var secHigh = sec / 0x100000000;\n var secLow = sec & 0xffffffff;\n var rv = new Uint8Array(8);\n var view = new DataView(rv.buffer);\n // nsec30 | secHigh2\n view.setUint32(0, (nsec << 2) | (secHigh & 0x3));\n // secLow32\n view.setUint32(4, secLow);\n return rv;\n }\n }\n else {\n // timestamp 96 = { nsec32 (unsigned), sec64 (signed) }\n var rv = new Uint8Array(12);\n var view = new DataView(rv.buffer);\n view.setUint32(0, nsec);\n setInt64(view, 4, sec);\n return rv;\n }\n}\nexport function encodeDateToTimeSpec(date) {\n var msec = date.getTime();\n var sec = Math.floor(msec / 1e3);\n var nsec = (msec - sec * 1e3) * 1e6;\n // Normalizes { sec, nsec } to ensure nsec is unsigned.\n var nsecInSec = Math.floor(nsec / 1e9);\n return {\n sec: sec + nsecInSec,\n nsec: nsec - nsecInSec * 1e9,\n };\n}\nexport function encodeTimestampExtension(object) {\n if (object instanceof Date) {\n var timeSpec = encodeDateToTimeSpec(object);\n return encodeTimeSpecToTimestamp(timeSpec);\n }\n else {\n return null;\n }\n}\nexport function decodeTimestampToTimeSpec(data) {\n var view = new DataView(data.buffer, data.byteOffset, data.byteLength);\n // data may be 32, 64, or 96 bits\n switch (data.byteLength) {\n case 4: {\n // timestamp 32 = { sec32 }\n var sec = view.getUint32(0);\n var nsec = 0;\n return { sec: sec, nsec: nsec };\n }\n case 8: {\n // timestamp 64 = { nsec30, sec34 }\n var nsec30AndSecHigh2 = view.getUint32(0);\n var secLow32 = view.getUint32(4);\n var sec = (nsec30AndSecHigh2 & 0x3) * 0x100000000 + secLow32;\n var nsec = nsec30AndSecHigh2 >>> 2;\n return { sec: sec, nsec: nsec };\n }\n case 12: {\n // timestamp 96 = { nsec32 (unsigned), sec64 (signed) }\n var sec = getInt64(view, 4);\n var nsec = view.getUint32(0);\n return { sec: sec, nsec: nsec };\n }\n default:\n throw new DecodeError(\"Unrecognized data size for timestamp (expected 4, 8, or 12): \" + data.length);\n }\n}\nexport function decodeTimestampExtension(data) {\n var timeSpec = decodeTimestampToTimeSpec(data);\n return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);\n}\nexport var timestampExtension = {\n type: EXT_TIMESTAMP,\n encode: encodeTimestampExtension,\n decode: decodeTimestampExtension,\n};\n//# sourceMappingURL=timestamp.mjs.map","// Integer Utility\nexport var UINT32_MAX = 4294967295;\n// DataView extension to handle int64 / uint64,\n// where the actual range is 53-bits integer (a.k.a. safe integer)\nexport function setUint64(view, offset, value) {\n var high = value / 4294967296;\n var low = value; // high bits are truncated by DataView\n view.setUint32(offset, high);\n view.setUint32(offset + 4, low);\n}\nexport function setInt64(view, offset, value) {\n var high = Math.floor(value / 4294967296);\n var low = value; // high bits are truncated by DataView\n view.setUint32(offset, high);\n view.setUint32(offset + 4, low);\n}\nexport function getInt64(view, offset) {\n var high = view.getInt32(offset);\n var low = view.getUint32(offset + 4);\n return high * 4294967296 + low;\n}\nexport function getUint64(view, offset) {\n var high = view.getUint32(offset);\n var low = view.getUint32(offset + 4);\n return high * 4294967296 + low;\n}\n//# sourceMappingURL=int.mjs.map","export function prettyByte(byte) {\n return (byte < 0 ? \"-\" : \"\") + \"0x\" + Math.abs(byte).toString(16).padStart(2, \"0\");\n}\n//# sourceMappingURL=prettyByte.mjs.map","// utility for whatwg streams\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }\nvar __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n};\nexport function isAsyncIterable(object) {\n return object[Symbol.asyncIterator] != null;\n}\nfunction assertNonNull(value) {\n if (value == null) {\n throw new Error(\"Assertion Failure: value must not be null nor undefined\");\n }\n}\nexport function asyncIterableFromStream(stream) {\n return __asyncGenerator(this, arguments, function asyncIterableFromStream_1() {\n var reader, _a, done, value;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n reader = stream.getReader();\n _b.label = 1;\n case 1:\n _b.trys.push([1, , 9, 10]);\n _b.label = 2;\n case 2:\n if (!true) return [3 /*break*/, 8];\n return [4 /*yield*/, __await(reader.read())];\n case 3:\n _a = _b.sent(), done = _a.done, value = _a.value;\n if (!done) return [3 /*break*/, 5];\n return [4 /*yield*/, __await(void 0)];\n case 4: return [2 /*return*/, _b.sent()];\n case 5:\n assertNonNull(value);\n return [4 /*yield*/, __await(value)];\n case 6: return [4 /*yield*/, _b.sent()];\n case 7:\n _b.sent();\n return [3 /*break*/, 2];\n case 8: return [3 /*break*/, 10];\n case 9:\n reader.releaseLock();\n return [7 /*endfinally*/];\n case 10: return [2 /*return*/];\n }\n });\n });\n}\nexport function ensureAsyncIterable(streamLike) {\n if (isAsyncIterable(streamLike)) {\n return streamLike;\n }\n else {\n return asyncIterableFromStream(streamLike);\n }\n}\n//# sourceMappingURL=stream.mjs.map","export function ensureUint8Array(buffer) {\n if (buffer instanceof Uint8Array) {\n return buffer;\n }\n else if (ArrayBuffer.isView(buffer)) {\n return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n }\n else if (buffer instanceof ArrayBuffer) {\n return new Uint8Array(buffer);\n }\n else {\n // ArrayLike<number>\n return Uint8Array.from(buffer);\n }\n}\nexport function createDataView(buffer) {\n if (buffer instanceof ArrayBuffer) {\n return new DataView(buffer);\n }\n var bufferView = ensureUint8Array(buffer);\n return new DataView(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength);\n}\n//# sourceMappingURL=typedArrays.mjs.map","import { UINT32_MAX } from \"./int.mjs\";\nvar TEXT_ENCODING_AVAILABLE = (typeof process === \"undefined\" || process.env[\"TEXT_ENCODING\"] !== \"never\") &&\n typeof TextEncoder !== \"undefined\" &&\n typeof TextDecoder !== \"undefined\";\nexport function utf8Count(str) {\n var strLength = str.length;\n var byteLength = 0;\n var pos = 0;\n while (pos < strLength) {\n var value = str.charCodeAt(pos++);\n if ((value & 0xffffff80) === 0) {\n // 1-byte\n byteLength++;\n continue;\n }\n else if ((value & 0xfffff800) === 0) {\n // 2-bytes\n byteLength += 2;\n }\n else {\n // handle surrogate pair\n if (value >= 0xd800 && value <= 0xdbff) {\n // high surrogate\n if (pos < strLength) {\n var extra = str.charCodeAt(pos);\n if ((extra & 0xfc00) === 0xdc00) {\n ++pos;\n value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;\n }\n }\n }\n if ((value & 0xffff0000) === 0) {\n // 3-byte\n byteLength += 3;\n }\n else {\n // 4-byte\n byteLength += 4;\n }\n }\n }\n return byteLength;\n}\nexport function utf8EncodeJs(str, output, outputOffset) {\n var strLength = str.length;\n var offset = outputOffset;\n var pos = 0;\n while (pos < strLength) {\n var value = str.charCodeAt(pos++);\n if ((value & 0xffffff80) === 0) {\n // 1-byte\n output[offset++] = value;\n continue;\n }\n else if ((value & 0xfffff800) === 0) {\n // 2-bytes\n output[offset++] = ((value >> 6) & 0x1f) | 0xc0;\n }\n else {\n // handle surrogate pair\n if (value >= 0xd800 && value <= 0xdbff) {\n // high surrogate\n if (pos < strLength) {\n var extra = str.charCodeAt(pos);\n if ((extra & 0xfc00) === 0xdc00) {\n ++pos;\n value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;\n }\n }\n }\n if ((value & 0xffff0000) === 0) {\n // 3-byte\n output[offset++] = ((value >> 12) & 0x0f) | 0xe0;\n output[offset++] = ((value >> 6) & 0x3f) | 0x80;\n }\n else {\n // 4-byte\n output[offset++] = ((value >> 18) & 0x07) | 0xf0;\n output[offset++] = ((value >> 12) & 0x3f) | 0x80;\n output[offset++] = ((value >> 6) & 0x3f) | 0x80;\n }\n }\n output[offset++] = (value & 0x3f) | 0x80;\n }\n}\nvar sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;\nexport var TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE\n ? UINT32_MAX\n : typeof process !== \"undefined\" && process.env[\"TEXT_ENCODING\"] !== \"force\"\n ? 200\n : 0;\nfunction utf8EncodeTEencode(str, output, outputOffset) {\n output.set(sharedTextEncoder.encode(str), outputOffset);\n}\nfunction utf8EncodeTEencodeInto(str, output, outputOffset) {\n sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));\n}\nexport var utf8EncodeTE = (sharedTextEncoder === null || sharedTextEncoder === void 0 ? void 0 : sharedTextEncoder.encodeInto) ? utf8EncodeTEencodeInto : utf8EncodeTEencode;\nvar CHUNK_SIZE = 4096;\nexport function utf8DecodeJs(bytes, inputOffset, byteLength) {\n var offset = inputOffset;\n var end = offset + byteLength;\n var units = [];\n var result = \"\";\n while (offset < end) {\n var byte1 = bytes[offset++];\n if ((byte1 & 0x80) === 0) {\n // 1 byte\n units.push(byte1);\n }\n else if ((byte1 & 0xe0) === 0xc0) {\n // 2 bytes\n var byte2 = bytes[offset++] & 0x3f;\n units.push(((byte1 & 0x1f) << 6) | byte2);\n }\n else if ((byte1 & 0xf0) === 0xe0) {\n // 3 bytes\n var byte2 = bytes[offset++] & 0x3f;\n var byte3 = bytes[offset++] & 0x3f;\n units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);\n }\n else if ((byte1 & 0xf8) === 0xf0) {\n // 4 bytes\n var byte2 = bytes[offset++] & 0x3f;\n var byte3 = bytes[offset++] & 0x3f;\n var byte4 = bytes[offset++] & 0x3f;\n var unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;\n if (unit > 0xffff) {\n unit -= 0x10000;\n units.push(((unit >>> 10) & 0x3ff) | 0xd800);\n unit = 0xdc00 | (unit & 0x3ff);\n }\n units.push(unit);\n }\n else {\n units.push(byte1);\n }\n if (units.length >= CHUNK_SIZE) {\n result += String.fromCharCode.apply(String, units);\n units.length = 0;\n }\n }\n if (units.length > 0) {\n result += String.fromCharCode.apply(String, units);\n }\n return result;\n}\nvar sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;\nexport var TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE\n ? UINT32_MAX\n : typeof process !== \"undefined\" && process.env[\"TEXT_DECODER\"] !== \"force\"\n ? 200\n : 0;\nexport function utf8DecodeTD(bytes, inputOffset, byteLength) {\n var stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);\n return sharedTextDecoder.decode(stringBytes);\n}\n//# sourceMappingURL=utf8.mjs.map","/**\n * Contains the RPC object used both by the application\n * site, and by each plugin\n */\nimport {\n randId,\n typedArrayToDtype,\n dtypeToTypedArray,\n MessageEmitter,\n assert,\n waitFor\n} from \"./utils.js\";\n\nimport { encode as msgpack_packb, decodeMulti } from \"@msgpack/msgpack\";\n\nexport const API_VERSION = \"0.3.0\";\nconst CHUNK_SIZE = 1024 * 500;\n\nconst ArrayBufferView = Object.getPrototypeOf(\n Object.getPrototypeOf(new Uint8Array())\n).constructor;\n\nfunction _appendBuffer(buffer1, buffer2) {\n const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);\n tmp.set(new Uint8Array(buffer1), 0);\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength);\n return tmp.buffer;\n}\n\nfunction indexObject(obj, is) {\n if (!is) throw new Error(\"undefined index\");\n if (typeof is === \"string\") return indexObject(obj, is.split(\".\"));\n else if (is.length === 0) return obj;\n else return indexObject(obj[is[0]], is.slice(1));\n}\n\nfunction concatArrayBuffers(buffers) {\n var buffersLengths = buffers.map(function(b) {\n return b.byteLength;\n }),\n totalBufferlength = buffersLengths.reduce(function(p, c) {\n return p + c;\n }, 0),\n unit8Arr = new Uint8Array(totalBufferlength);\n buffersLengths.reduce(function(p, c, i) {\n unit8Arr.set(new Uint8Array(buffers[i]), p);\n return p + c;\n }, 0);\n return unit8Arr.buffer;\n}\n\nclass Timer {\n constructor(timeout, callback, args, label) {\n this._timeout = timeout;\n this._callback = callback;\n this._args = args;\n this._label = label || \"timer\";\n this._task = null;\n this.started = false;\n }\n\n start() {\n this._task = setTimeout(() => {\n this._callback.apply(this, this._args);\n }, this._timeout * 1000);\n this.started = true;\n }\n\n clear() {\n if (this._task) {\n clearTimeout(this._task);\n this._task = null;\n this.started = false;\n } else {\n console.warn(`Clearing a timer (${this._label}) which is not started`);\n }\n }\n\n reset() {\n assert(this._task, `Timer (${this._label}) is not started`);\n clearTimeout(this._task);\n this.start();\n }\n}\n\n/**\n * RPC object represents a single site in the\n * communication protocol between the application and the plugin\n *\n * @param {Object} connection a special object allowing to send\n * and receive messages from the opposite site (basically it\n * should only provide send() and onMessage() methods)\n */\nexport class RPC extends MessageEmitter {\n constructor(\n connection,\n {\n client_id = null,\n manager_id = null,\n default_context = null,\n name = null,\n codecs = null,\n method_timeout = null,\n max_message_buffer_size = 0,\n debug = false\n }\n ) {\n super(debug);\n this._codecs = codecs || {};\n assert(client_id && typeof client_id === \"string\");\n assert(client_id, \"client_id is required\");\n this._client_id = client_id;\n this._name = name;\n this._connection_info = null;\n this._workspace = null;\n this.manager_id = manager_id;\n this.default_context = default_context || {};\n this._method_annotations = new WeakMap();\n this._manager_service = null;\n this._max_message_buffer_size = max_message_buffer_size;\n this._chunk_store = {};\n this._method_timeout = method_timeout || 20;\n\n // make sure there is an execute function\n this._services = {};\n this._object_store = {\n services: this._services\n };\n\n if (connection) {\n this.add_service({\n id: \"built-in\",\n type: \"built-in\",\n name: \"RPC built-in services\",\n config: { require_context: true, visibility: \"public\" },\n ping: this._ping.bind(this),\n get_service: this.get_local_service.bind(this),\n register_service: this.register_service.bind(this),\n message_cache: {\n create: this._create_message.bind(this),\n append: this._append_message.bind(this),\n process: this._process_message.bind(this),\n remove: this._remove_message.bind(this)\n }\n });\n this.on(\"method\", this._handle_method.bind(this));\n\n assert(connection.emit_message && connection.on_message);\n this._emit_message = connection.emit_message.bind(connection);\n connection.on_message(this._on_message.bind(this));\n this._connection = connection;\n // Update the server and obtain client info\n this._get_connection_info();\n } else {\n this._emit_message = function() {\n console.log(\"No connection to emit message\");\n };\n }\n }\n\n async _get_connection_info() {\n if (this.manager_id) {\n // try to get the root service\n try {\n await this.get_manager_service(5.0);\n assert(this._manager_service);\n this._connection_info = await this._manager_service.get_connection_info();\n if (\n this._connection_info.reconnection_token &&\n this._connection.set_reconnection_token\n ) {\n this._connection.set_reconnection_token(\n this._connection_info.reconnection_token\n );\n const reconnection_expires_in =\n this._connection_info.reconnection_expires_in * 0.8;\n console.info(\n `Reconnection token obtained: ${this._connection_info.reconnection_token}, will be refreshed in ${reconnection_expires_in} seconds`\n );\n this._get_connection_info_task = setTimeout(\n this._get_connection_info.bind(this),\n reconnection_expires_in * 1000\n );\n }\n } catch (exp) {\n console.warn(\"Failed to fetch user info from \", this.manager_id, exp);\n }\n }\n }\n\n register_codec(config) {\n if (!config[\"name\"] || (!config[\"encoder\"] && !config[\"decoder\"])) {\n throw new Error(\n \"Invalid codec format, please make sure you provide a name, type, encoder and decoder.\"\n );\n } else {\n if (config.type) {\n for (let k of Object.keys(this._codecs)) {\n if (this._codecs[k].type === config.type || k === config.name) {\n delete this._codecs[k];\n console.warn(\"Remove duplicated codec: \" + k);\n }\n }\n }\n this._codecs[config[\"name\"]] = config;\n }\n }\n\n async _ping(msg, context) {\n assert(msg == \"ping\");\n return \"pong\";\n }\n\n async ping(client_id, timeout) {\n let method = this._generate_remote_method({\n _rtarget: client_id,\n _rmethod: \"services.built-in.ping\",\n _rpromise: true\n });\n assert((await method(\"ping\", timeout)) == \"pong\");\n }\n\n _create_message(key, heartbeat, overwrite, context) {\n if (heartbeat) {\n if (!this._object_store[key]) {\n throw new Error(`session does not exist anymore: ${key}`);\n }\n this._object_store[key][\"timer\"].reset();\n }\n\n if (!this._object_store[\"message_cache\"]) {\n this._object_store[\"message_cache\"] = {};\n }\n if (!overwrite && this._object_store[\"message_cache\"][key]) {\n throw new Error(\n `Message with the same key (${key}) already exists in the cache store, please use overwrite=true or remove it first.`\n );\n }\n\n this._object_store[\"message_cache\"][key] = [];\n }\n\n _append_message(key, data, heartbeat, context) {\n if (heartbeat) {\n if (!this._object_store[key]) {\n throw new Error(`session does not exist anymore: ${key}`);\n }\n this._object_store[key][\"timer\"].reset();\n }\n const cache = this._object_store[\"message_cache\"];\n if (!cache[key]) {\n throw new Error(`Message with key ${key} does not exists.`);\n }\n assert(data instanceof ArrayBufferView);\n cache[key].push(data);\n }\n\n _remove_message(key, context) {\n const cache = this._object_store[\"message_cache\"];\n if (!cache[key]) {\n throw new Error(`Message with key ${key} does not exists.`);\n }\n delete cache[key];\n }\n\n _process_message(key, heartbeat, context) {\n if (heartbeat) {\n if (!this._object_store[key]) {\n throw new Error(`session does not exist anymore: ${key}`);\n }\n this._object_store[key][\"timer\"].reset();\n }\n const cache = this._object_store[\"message_cache\"];\n assert(!!context, \"Context is required\");\n if (!cache[key]) {\n throw new Error(`Message with key ${key} does not exists.`);\n }\n cache[key] = concatArrayBuffers(cache[key]);\n console.debug(`Processing message ${key} (size=${cache[key].length})`);\n let unpacker = decodeMulti(cache[key]);\n const { done, value } = unpacker.next();\n const main = value;\n // Make sure the fields are from trusted source\n Object.assign(main, {\n from: context.from,\n to: context.to,\n user: context.user\n });\n main[\"ctx\"] = JSON.parse(JSON.stringify(main));\n Object.assign(main[\"ctx\"], this.default_context);\n if (!done) {\n let extra = unpacker.next();\n Object.assign(main, extra.value);\n }\n this._fire(main[\"type\"], main);\n delete cache[key];\n }\n\n _on_message(message) {\n assert(message instanceof ArrayBuffer);\n let unpacker = decodeMulti(message);\n const { done, value } = unpacker.next();\n const main = value;\n // Add trusted context to the method call\n main[\"ctx\"] = JSON.parse(JSON.stringify(main));\n Object.assign(main[\"ctx\"], this.default_context);\n if (!done) {\n let extra = unpacker.next();\n Object.assign(main, extra.value);\n }\n this._fire(main[\"type\"], main);\n }\n\n reset() {\n this._event_handlers = {};\n this._services = {};\n }\n\n async disconnect() {\n if (this._get_connection_info_task) {\n clearTimeout(this._get_connection_info_task);\n this._get_connection_info_task = null;\n }\n this._fire(\"disconnect\");\n }\n\n async get_manager_service(timeout) {\n if (this.manager_id && !this._manager_service) {\n this._manager_service = await this.get_remote_service(\n `${this.manager_id}:default`,\n timeout\n );\n }\n }\n\n get_all_local_services() {\n return this._services;\n }\n get_local_service(service_id, context) {\n assert(service_id);\n const [ws, client_id] = context[\"to\"].split(\"/\");\n assert(client_id === this._client_id);\n\n const service = this._services[service_id];\n if (!service) {\n throw new Error(\"Service not found: \" + service_id);\n }\n\n // allow access for the same workspace\n if (service.config.visibility == \"public\") {\n return service;\n }\n\n // allow access for the same workspace\n if (context[\"from\"].startsWith(ws + \"/\")) {\n return service;\n }\n\n throw new Error(\"Permission denied for service: \" + service_id);\n }\n async get_remote_service(service_uri, timeout) {\n timeout = timeout === undefined ? 5 : timeout;\n if (!service_uri && this.manager_id) {\n service_uri = this.manager_id;\n } else if (!service_uri.includes(\":\")) {\n service_uri = this._client_id + \":\" + service_uri;\n }\n const provider = service_uri.split(\":\")[0];\n assert(provider);\n try {\n const method = this._generate_remote_method({\n _rtarget: provider,\n _rmethod: \"services.built-in.get_service\",\n _rpromise: true\n });\n return await waitFor(\n method(service_uri.split(\":\")[1]),\n timeout,\n \"Timeout Error: Failed to get remote service: \" + service_uri\n );\n } catch (e) {\n console.error(\"Failed to get remote service: \" + service_uri, e);\n throw e;\n }\n }\n _annotate_service_methods(\n aObject,\n object_id,\n require_context,\n run_in_executor,\n visibility\n ) {\n if (typeof aObject === \"function\") {\n // mark the method as a remote method that requires context\n let method_name = object_id.split(\".\")[1];\n this._method_annotations.set(aObject, {\n require_context: Array.isArray(require_context)\n ? require_context.includes(method_name)\n : !!require_context,\n run_in_executor: run_in_executor,\n method_id: \"services.\" + object_id,\n visibility: visibility\n });\n } else if (aObject instanceof Array || aObject instanceof Object) {\n for (let key of Object.keys(aObject)) {\n let val = aObject[key];\n if (typeof val === \"function\" && val.__rpc_object__) {\n let client_id = val.__rpc_object__._rtarget;\n if (client_id.includes(\"/\")) {\n client_id = client_id.split(\"/\")[1];\n }\n if (this._client_id === client_id) {\n if (aObject instanceof Array) {\n aObject = aObject.slice();\n }\n // recover local method\n aObject[key] = indexObject(\n this._object_store,\n val.__rpc_object__._rmethod\n );\n val = aObject[key]; // make sure it's annotated later\n } else {\n throw new Error(\n `Local method not found: ${val.__rpc_object__._rmethod}, client id mismatch ${this._client_id} != ${client_id}`\n );\n }\n }\n this._annotate_service_methods(\n val,\n object_id + \".\" + key,\n require_context,\n run_in_executor,\n visibility\n );\n }\n }\n }\n add_service(api, overwrite) {\n if (!api || Array.isArray(api)) throw new Error(\"Invalid service object\");\n if (api.constructor === Object) {\n api = Object.assign({}, api);\n } else {\n const normApi = {};\n const props = Object.getOwnPropertyNames(api).concat(\n Object.getOwnPropertyNames(Object.getPrototypeOf(api))\n );\n for (let k of props) {\n if (k !== \"constructor\") {\n if (typeof api[k] === \"function\") normApi[k] = api[k].bind(api);\n else normApi[k] = api[k];\n }\n }\n // For class instance, we need set a default id\n api.id = api.id || \"default\";\n api = normApi;\n }\n assert(\n api.id && typeof api.id === \"string\",\n `Service id not found: ${api}`\n );\n if (!api.name) {\n api.name = api.id;\n }\n if (!api.config) {\n api.config = {};\n }\n if (!api.type) {\n api.type = \"generic\";\n }\n // require_context only applies to the top-level functions\n let require_context = false,\n run_in_executor = false;\n if (api.config.require_context)\n require_context = api.config.require_context;\n if (api.config.run_in_executor) run_in_executor = true;\n const visibility = api.config.visibility || \"protected\";\n assert([\"protected\", \"public\"].includes(visibility));\n this._annotate_service_methods(\n api,\n api[\"id\"],\n require_context,\n run_in_executor,\n visibility\n );\n\n if (this._services[api.id]) {\n if (overwrite) {\n delete this._services[api.id];\n } else {\n throw new Error(\n `Service already exists: ${api.id}, please specify a different id (not ${api.id}) or overwrite=true`\n );\n }\n }\n this._services[api.id] = api;\n return api;\n }\n\n async register_service(api, overwrite, notify, context) {\n if (notify === undefined) notify = true;\n if (context) {\n // If this function is called from remote, we need to make sure\n const [workspace, client_id] = context[\"to\"].split(\"/\");\n assert(client_id === this._client_id);\n assert(\n workspace === context[\"from\"].split(\"/\")[0],\n \"Services can only be registered from the same workspace\"\n );\n }\n const service = this.add_service(api, overwrite);\n if (notify) {\n this._fire(\"service-updated\", {\n service_id: service[\"id\"],\n api: service,\n type: \"add\"\n });\n await this._notify_service_update();\n }\n return {\n id: `${this._client_id}:${service[\"id\"]}`,\n type: service[\"type\"],\n name: service[\"name\"],\n config: service[\"config\"]\n };\n }\n async unregister_service(service, notify) {\n if (service instanceof Object) {\n service = service.id;\n }\n if (!this._services[service]) {\n throw new Error(`Service not found: ${service}`);\n }\n const api = this._services[service];\n delete this._services[service];\n this._fire(\"service-updated\", {\n service_id: service,\n api: api,\n type: \"remove\"\n });\n await this._notify_service_update();\n }\n\n _ndarray(typedArray, shape, dtype) {\n const _dtype = typedArrayToDtype(typedArray);\n if (dtype && dtype !== _dtype) {\n throw \"dtype doesn't match the type of the array: \" +\n _dtype +\n \" != \" +\n dtype;\n }\n shape = shape || [typedArray.length];\n return {\n _rtype: \"ndarray\",\n _rvalue: typedArray.buffer,\n _rshape: shape,\n _rdtype: _dtype\n };\n }\n\n _encode_callback(\n name,\n callback,\n session_id,\n clear_after_called,\n timer,\n local_workspace\n ) {\n let method_id = `${session_id}.${name}`;\n let encoded = {\n _rtype: \"method\",\n _rtarget: local_workspace\n ? `${local_workspace}/${this._client_id}`\n : this._client_id,\n _rmethod: method_id,\n _rpromise: false\n };\n\n const self = this;\n let wrapped_callback = function() {\n try {\n callback.apply(null, Array.prototype.slice.call(arguments));\n } catch (error) {\n console.error(\"Error in callback:\", method_id, error);\n } finally {\n if (clear_after_called && self._object_store[session_id]) {\n console.log(\"Deleting session\", session_id, \"from\", self._client_id);\n delete self._object_store[session_id];\n }\n if (timer && timer.started) {\n timer.clear();\n }\n }\n };\n\n return [encoded, wrapped_callback];\n }\n\n async _encode_promise(\n resolve,\n reject,\n session_id,\n clear_after_called,\n timer,\n local_workspace\n ) {\n let store = this._get_session_store(session_id, true);\n assert(\n store,\n `Failed to create session store ${session_id} due to invalid parent`\n );\n let encoded = {};\n\n if (timer && reject && this._method_timeout) {\n encoded.heartbeat = await this._encode(\n timer.reset.bind(timer),\n session_id,\n local_workspace\n );\n encoded.interval = this._method_timeout / 2;\n store.timer = timer;\n } else {\n timer = null;\n }\n\n [encoded.resolve, store.resolve] = this._encode_callback(\n \"resolve\",\n resolve,\n session_id,\n clear_after_called,\n timer,\n local_workspace\n );\n [encoded.reject, store.reject] = this._encode_callback(\n \"reject\",\n reject,\n session_id,\n clear_after_called,\n timer,\n local_workspace\n );\n return encoded;\n }\n\n async _send_chunks(data, target_id, session_id) {\n let remote_services = await this.get_remote_service(\n `${target_id}:built-in`\n );\n assert(\n remote_services.message_cache,\n \"Remote client does not support message caching for long message.\"\n );\n let message_cache = remote_services.message_cache;\n let message_id = session_id || randId();\n await message_cache.create(message_id, !!session_id);\n let total_size = data.length;\n let chunk_num = Math.ceil(total_size / CHUNK_SIZE);\n for (let idx = 0; idx < chunk_num; idx++) {\n let start_byte = idx * CHUNK_SIZE;\n await message_cache.append(\n message_id,\n data.slice(start_byte, start_byte + CHUNK_SIZE),\n !!session_id\n );\n console.log(\n `Sending chunk ${idx + 1}/${chunk_num} (${total_size} bytes)`\n );\n }\n console.log(`All chunks sent (${chunk_num})`);\n await message_cache.process(message_id, !!session_id);\n }\n\n _generate_remote_method(\n encoded_method,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n ) {\n let target_id = encoded_method._rtarget;\n if (remote_workspace && !target_id.includes(\"/\")) {\n target_id = remote_workspace + \"/\" + target_id;\n // Fix the target id to be an absolute id\n encoded_method._rtarget = target_id;\n }\n let method_id = encoded_method._rmethod;\n let with_promise = encoded_method._rpromise;\n const self = this;\n\n function remote_method() {\n return new Promise(async (resolve, reject) => {\n let local_session_id = randId();\n if (local_parent) {\n // Store the children session under the parent\n local_session_id = local_parent + \".\" + local_session_id;\n }\n let store = self._get_session_store(local_session_id, true);\n if (!store) {\n reject(\n new Error(\n `Runtime Error: Failed to get session store ${local_session_id}`\n )\n );\n return;\n }\n store[\"target_id\"] = target_id;\n const args = await self._encode(\n Array.prototype.slice.call(arguments),\n local_session_id,\n local_workspace\n );\n const argLength = args.length;\n // if the last argument is an object, mark it as kwargs\n const withKwargs =\n argLength > 0 &&\n typeof args[argLength - 1] === \"object\" &&\n args[argLength - 1] !== null &&\n args[argLength - 1]._rkwargs;\n if (withKwargs) delete args[argLength - 1]._rkwargs;\n let main_message = {\n type: \"method\",\n from: self._client_id,\n to: target_id,\n method: method_id\n };\n let extra_data = {};\n if (args) {\n extra_data[\"args\"] = args;\n }\n if (withKwargs) {\n extra_data[\"with_kwargs\"] = withKwargs;\n }\n\n console.log(\n `Calling remote method ${target_id}:${method_id}, session: ${local_session_id}`\n );\n if (remote_parent) {\n // Set the parent session\n // Note: It's a session id for the remote, not the current client\n main_message[\"parent\"] = remote_parent;\n }\n\n let timer = null;\n if (with_promise) {\n // Only pass the current session id to the remote\n // if we want to received the result\n // I.e. the session id won't be passed for promises themselves\n main_message[\"session\"] = local_session_id;\n let method_name = `${target_id}:${method_id}`;\n timer = new Timer(\n self._method_timeout,\n reject,\n [`Method call time out: ${method_name}`],\n method_name\n );\n extra_data[\"promise\"] = await self._encode_promise(\n resolve,\n reject,\n local_session_id,\n true,\n timer,\n local_workspace\n );\n }\n // The message consists of two segments, the main message and extra data\n let message_package = msgpack_packb(main_message);\n if (extra_data) {\n const extra = msgpack_packb(extra_data);\n message_package = new Uint8Array([...message_package, ...extra]);\n }\n let total_size = message_package.length;\n if (total_size <= CHUNK_SIZE + 1024) {\n self._emit_message(message_package).then(function() {\n if (timer) {\n console.log(`Start watchdog timer.`);\n // Only start the timer after we send the message successfully\n timer.start();\n }\n });\n } else {\n // send chunk by chunk\n self\n ._send_chunks(message_package, target_id, remote_parent)\n .then(function() {\n if (timer) {\n console.log(`Start watchdog timer.`);\n // Only start the timer after we send the message successfully\n timer.start();\n }\n });\n }\n });\n }\n\n // Generate debugging information for the method\n remote_method.__rpc_object__ = encoded_method;\n return remote_method;\n }\n\n async _notify_service_update() {\n if (this.manager_id) {\n // try to get the root service\n try {\n await this.get_manager_service(5.0);\n assert(this._manager_service);\n await this._manager_service.update_client_info(this.get_client_info());\n } catch (exp) {\n // pylint: disable=broad-except\n console.warn(\n \"Failed to notify service update to\",\n this.manager_id,\n exp\n );\n }\n }\n }\n\n get_client_info() {\n const services = [];\n for (let service of Object.values(this._services)) {\n services.push({\n id: `${this._client_id}:${service[\"id\"]}`,\n type: service[\"type\"],\n name: service[\"name\"],\n config: service[\"config\"]\n });\n }\n\n return {\n id: this._client_id,\n services: services\n };\n }\n\n async _handle_method(data) {\n let reject = null;\n let heartbeat_task = null;\n try {\n assert(data[\"method\"] && data[\"ctx\"] && data[\"from\"]);\n const method_name = data.from + \":\" + data.method;\n const remote_workspace = data.from.split(\"/\")[0];\n const local_workspace = data.to.split(\"/\")[0];\n const local_parent = data.parent;\n\n let resolve, reject;\n if (data.promise) {\n // Decode the promise with the remote session id\n // Such that the session id will be passed to the remote as a parent session id\n const promise = await this._decode(\n data.promise,\n data.session,\n local_parent,\n remote_workspace,\n local_workspace\n );\n resolve = promise.resolve;\n reject = promise.reject;\n if (promise.heartbeat && promise.interval) {\n async function heartbeat() {\n try {\n console.log(\"Reset heartbeat timer: \" + data.method);\n await promise.heartbeat();\n } catch (err) {\n console.error(err);\n }\n }\n heartbeat_task = setInterval(heartbeat, promise.interval * 1000);\n }\n }\n\n let method;\n\n try {\n method = indexObject(this._object_store, data[\"method\"]);\n } catch (e) {\n console.debug(\"Failed to find method\", method_name, e);\n throw new Error(`Method not found: ${method_name}`);\n }\n\n assert(\n method && typeof method === \"function\",\n \"Invalid method: \" + method_name\n );\n\n // Check permission\n if (this._method_annotations.has(method)) {\n // For services, it should not be protected\n if (this._method_annotations.get(method).visibility === \"protected\") {\n if (local_workspace !== remote_workspace) {\n throw new Error(\n \"Permission denied for protected method \" +\n method_name +\n \", workspace mismatch: \" +\n local_workspace +\n \" != \" +\n remote_workspace\n );\n }\n }\n } else {\n // For sessions, the target_id should match exactly\n let session_target_id = this._object_store[data.method.split(\".\")[0]]\n .target_id;\n if (\n local_workspace === remote_workspace &&\n session_target_id &&\n session_target_id.indexOf(\"/\") === -1\n ) {\n session_target_id = local_workspace + \"/\" + session_target_id;\n }\n if (session_target_id !== data.from) {\n throw new Error(\n \"Access denied for method call (\" +\n method_name +\n \") from \" +\n data.from\n );\n }\n }\n\n // Make sure the parent session is still open\n if (local_parent) {\n // The parent session should be a session that generate the current method call\n assert(\n this._get_session_store(local_parent, true) !== null,\n \"Parent session was closed: \" + local_parent\n );\n }\n let args;\n if (data.args) {\n args = await this._decode(\n data.args,\n data.session,\n null,\n remote_workspace,\n null\n );\n } else {\n args = [];\n }\n if (\n this._method_annotations.has(method) &&\n this._method_annotations.get(method).require_context\n ) {\n args.push(data.ctx);\n }\n console.log(\"Executing method: \" + method_name);\n if (data.promise) {\n const result = method.apply(null, args);\n if (result instanceof Promise) {\n result\n .then(result => {\n resolve(result);\n clearInterval(heartbeat_task);\n })\n .catch(err => {\n reject(err);\n clearInterval(heartbeat_task);\n });\n } else {\n resolve(result);\n clearInterval(heartbeat_task);\n }\n } else {\n method.apply(null, args);\n clearInterval(heartbeat_task);\n }\n } catch (err) {\n if (reject) {\n reject(err);\n console.debug(\"Error during calling method: \", err);\n } else {\n console.error(\"Error during calling method: \", err);\n }\n // make sure we clear the heartbeat timer\n clearInterval(heartbeat_task);\n }\n }\n\n encode(aObject, session_id) {\n return this._encode(aObject, session_id);\n }\n\n _get_session_store(session_id, create) {\n let store = this._object_store;\n const levels = session_id.split(\".\");\n if (create) {\n const last_index = levels.length - 1;\n for (let level of levels.slice(0, last_index)) {\n if (!store[level]) {\n return null;\n }\n store = store[level];\n }\n // Create the last level\n if (!store[levels[last_index]]) {\n store[levels[last_index]] = {};\n }\n return store[levels[last_index]];\n } else {\n for (let level of levels) {\n if (!store[level]) {\n return null;\n }\n store = store[level];\n }\n return store;\n }\n }\n\n /**\n * Prepares the provided set of remote method arguments for\n * sending to the remote site, replaces all the callbacks with\n * identifiers\n *\n * @param {Array} args to wrap\n *\n * @returns {Array} wrapped arguments\n */\n async _encode(aObject, session_id, local_workspace) {\n const aType = typeof aObject;\n if (\n aType === \"number\" ||\n aType === \"string\" ||\n aType === \"boolean\" ||\n aObject === null ||\n aObject === undefined ||\n aObject instanceof Uint8Array\n ) {\n return aObject;\n }\n if (aObject instanceof ArrayBuffer) {\n return {\n _rtype: \"memoryview\",\n _rvalue: new Uint8Array(aObject)\n };\n }\n // Reuse the remote object\n if (aObject.__rpc_object__) {\n return aObject.__rpc_object__;\n }\n\n let bObject;\n\n // skip if already encoded\n if (aObject.constructor instanceof Object && aObject._rtype) {\n // make sure the interface functions are encoded\n const temp = aObject._rtype;\n delete aObject._rtype;\n bObject = await this._encode(aObject, session_id, local_workspace);\n bObject._rtype = temp;\n return bObject;\n }\n\n if (typeof aObject === \"function\") {\n if (this._method_annotations.has(aObject)) {\n let annotation = this._method_annotations.get(aObject);\n bObject = {\n _rtype: \"method\",\n _rtarget: this._client_id,\n _rmethod: annotation.method_id,\n _rpromise: true\n };\n } else {\n assert(typeof session_id === \"string\");\n let object_id;\n if (aObject.__name__) {\n object_id = `${randId()}-${aObject.__name__}`;\n } else {\n object_id = randId();\n }\n bObject = {\n _rtype: \"method\",\n _rtarget: this._client_id,\n _rmethod: `${session_id}.${object_id}`,\n _rpromise: true\n };\n let store = this._get_session_store(session_id, true);\n assert(\n store !== null,\n `Failed to create session store ${session_id} due to invalid parent`\n );\n store[object_id] = aObject;\n }\n return bObject;\n }\n const isarray = Array.isArray(aObject);\n\n for (let tp of Object.keys(this._codecs)) {\n const codec = this._codecs[tp];\n if (codec.encoder && aObject instanceof codec.type) {\n // TODO: what if multiple encoders found\n let encodedObj = await Promise.resolve(codec.encoder(aObject));\n if (encodedObj && !encodedObj._rtype) encodedObj._rtype = codec.name;\n // encode the functions in the interface object\n if (typeof encodedObj === \"object\") {\n const temp = encodedObj._rtype;\n delete encodedObj._rtype;\n encodedObj = await this._encode(\n encodedObj,\n session_id,\n local_workspace\n );\n encodedObj._rtype = temp;\n }\n bObject = encodedObj;\n return bObject;\n }\n }\n\n if (\n /*global tf*/\n typeof tf !== \"undefined\" &&\n tf.Tensor &&\n aObject instanceof tf.Tensor\n ) {\n const v_buffer = aObject.dataSync();\n bObject = {\n _rtype: \"ndarray\",\n _rvalue: new Uint8Array(v_buffer.buffer),\n _rshape: aObject.shape,\n _rdtype: aObject.dtype\n };\n } else if (\n /*global nj*/\n typeof nj !== \"undefined\" &&\n nj.NdArray &&\n aObject instanceof nj.NdArray\n ) {\n const dtype = typedArrayToDtype(aObject.selection.data);\n bObject = {\n _rtype: \"ndarray\",\n _rvalue: new Uint8Array(aObject.selection.data.buffer),\n _rshape: aObject.shape,\n _rdtype: dtype\n };\n } else if (aObject instanceof Error) {\n console.error(aObject);\n bObject = { _rtype: \"error\", _rvalue: aObject.toString() };\n }\n // send objects supported by structure clone algorithm\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n else if (\n aObject !== Object(aObject) ||\n aObject instanceof Boolean ||\n aObject instanceof String ||\n aObject instanceof Date ||\n aObject instanceof RegExp ||\n aObject instanceof ImageData ||\n (typeof FileList !== \"undefined\" && aObject instanceof FileList) ||\n (typeof FileSystemDirectoryHandle !== \"undefined\" &&\n aObject instanceof FileSystemDirectoryHandle) ||\n (typeof FileSystemFileHandle !== \"undefined\" &&\n aObject instanceof FileSystemFileHandle) ||\n (typeof FileSystemHandle !== \"undefined\" &&\n aObject instanceof FileSystemHandle) ||\n (typeof FileSystemWritableFileStream !== \"undefined\" &&\n aObject instanceof FileSystemWritableFileStream)\n ) {\n bObject = aObject;\n // TODO: avoid object such as DynamicPlugin instance.\n } else if (aObject instanceof Blob) {\n let _current_pos = 0;\n async function read(length) {\n let blob;\n if (length) {\n blob = aObject.slice(_current_pos, _current_pos + length);\n } else {\n blob = aObject.slice(_current_pos);\n }\n const ret = new Uint8Array(await blob.arrayBuffer());\n _current_pos = _current_pos + ret.byteLength;\n return ret;\n }\n function seek(pos) {\n _current_pos = pos;\n }\n bObject = {\n _rtype: \"iostream\",\n _rnative: \"js:blob\",\n type: aObject.type,\n name: aObject.name,\n size: aObject.size,\n path: aObject._path || aObject.webkitRelativePath,\n read: await this._encode(read, session_id, local_workspace),\n seek: await this._encode(seek, session_id, local_workspace)\n };\n } else if (aObject instanceof ArrayBufferView) {\n const dtype = typedArrayToDtype(aObject);\n bObject = {\n _rtype: \"typedarray\",\n _rvalue: new Uint8Array(aObject.buffer),\n _rdtype: dtype\n };\n } else if (aObject instanceof DataView) {\n bObject = {\n _rtype: \"memoryview\",\n _rvalue: new Uint8Array(aObject.buffer)\n };\n } else if (aObject instanceof Set) {\n bObject = {\n _rtype: \"set\",\n _rvalue: await this._encode(\n Array.from(aObject),\n session_id,\n local_workspace\n )\n };\n } else if (aObject instanceof Map) {\n bObject = {\n _rtype: \"orderedmap\",\n _rvalue: await this._encode(\n Array.from(aObject),\n session_id,\n local_workspace\n )\n };\n } else if (\n aObject.constructor instanceof Object ||\n Array.isArray(aObject)\n ) {\n bObject = isarray ? [] : {};\n const keys = Object.keys(aObject);\n for (let k of keys) {\n bObject[k] = await this._encode(\n aObject[k],\n session_id,\n local_workspace\n );\n }\n } else {\n throw `imjoy-rpc: Unsupported data type: ${aObject}, you can register a custom codec to encode/decode the object.`;\n }\n\n if (!bObject) {\n throw new Error(\"Failed to encode object\");\n }\n return bObject;\n }\n\n async decode(aObject) {\n return await this._decode(aObject);\n }\n\n async _decode(\n aObject,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n ) {\n if (!aObject) {\n return aObject;\n }\n let bObject;\n if (aObject._rtype) {\n if (\n this._codecs[aObject._rtype] &&\n this._codecs[aObject._rtype].decoder\n ) {\n const temp = aObject._rtype;\n delete aObject._rtype;\n aObject = await this._decode(\n aObject,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n );\n aObject._rtype = temp;\n\n bObject = await Promise.resolve(\n this._codecs[aObject._rtype].decoder(aObject)\n );\n } else if (aObject._rtype === \"method\") {\n bObject = this._generate_remote_method(\n aObject,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n );\n } else if (aObject._rtype === \"ndarray\") {\n /*global nj tf*/\n //create build array/tensor if used in the plugin\n if (typeof nj !== \"undefined\" && nj.array) {\n if (Array.isArray(aObject._rvalue)) {\n aObject._rvalue = aObject._rvalue.reduce(_appendBuffer);\n }\n bObject = nj\n .array(new Uint8(aObject._rvalue), aObject._rdtype)\n .reshape(aObject._rshape);\n } else if (typeof tf !== \"undefined\" && tf.Tensor) {\n if (Array.isArray(aObject._rvalue)) {\n aObject._rvalue = aObject._rvalue.reduce(_appendBuffer);\n }\n const arraytype = dtypeToTypedArray[aObject._rdtype];\n bObject = tf.tensor(\n new arraytype(aObject._rvalue),\n aObject._rshape,\n aObject._rdtype\n );\n } else {\n //keep it as regular if transfered to the main app\n bObject = aObject;\n }\n } else if (aObject._rtype === \"error\") {\n bObject = new Error(aObject._rvalue);\n } else if (aObject._rtype === \"typedarray\") {\n const arraytype = dtypeToTypedArray[aObject._rdtype];\n if (!arraytype)\n throw new Error(\"unsupported dtype: \" + aObject._rdtype);\n const buffer = aObject._rvalue.buffer.slice(\n aObject._rvalue.byteOffset,\n aObject._rvalue.byteOffset + aObject._rvalue.byteLength\n );\n bObject = new arraytype(buffer);\n } else if (aObject._rtype === \"memoryview\") {\n bObject = aObject._rvalue.buffer.slice(\n aObject._rvalue.byteOffset,\n aObject._rvalue.byteOffset + aObject._rvalue.byteLength\n ); // ArrayBuffer\n } else if (aObject._rtype === \"iostream\") {\n if (aObject._rnative === \"js:blob\") {\n const read = await this._generate_remote_method(\n aObject.read,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n );\n const bytes = await read();\n bObject = new Blob([bytes], {\n type: aObject.type,\n name: aObject.name\n });\n } else {\n bObject = {};\n for (let k of Object.keys(aObject)) {\n if (!k.startsWith(\"_\")) {\n bObject[k] = await this._decode(\n aObject[k],\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n );\n }\n }\n }\n bObject[\"__rpc_object__\"] = aObject;\n } else if (aObject._rtype === \"orderedmap\") {\n bObject = new Map(\n await this._decode(\n aObject._rvalue,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n )\n );\n } else if (aObject._rtype === \"set\") {\n bObject = new Set(\n await this._decode(\n aObject._rvalue,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n )\n );\n } else {\n const temp = aObject._rtype;\n delete aObject._rtype;\n bObject = await this._decode(\n aObject,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n );\n bObject._rtype = temp;\n }\n } else if (aObject.constructor === Object || Array.isArray(aObject)) {\n const isarray = Array.isArray(aObject);\n bObject = isarray ? [] : {};\n for (let k of Object.keys(aObject)) {\n if (isarray || aObject.hasOwnProperty(k)) {\n const v = aObject[k];\n bObject[k] = await this._decode(\n v,\n remote_parent,\n local_parent,\n remote_workspace,\n local_workspace\n );\n }\n }\n } else {\n bObject = aObject;\n }\n if (bObject === undefined) {\n throw new Error(\"Failed to decode object\");\n }\n return bObject;\n }\n}\n","export function randId() {\n return (\n Math.random()\n .toString(36)\n .substr(2, 10) + new Date().getTime()\n );\n}\n\nexport const dtypeToTypedArray = {\n int8: Int8Array,\n int16: Int16Array,\n int32: Int32Array,\n uint8: Uint8Array,\n uint16: Uint16Array,\n uint32: Uint32Array,\n float32: Float32Array,\n float64: Float64Array,\n array: Array\n};\n\nexport async function loadRequirementsInWindow(requirements) {\n function _importScript(url) {\n //url is URL of external file, implementationCode is the code\n //to be called from the file, location is the location to\n //insert the <script> element\n return new Promise((resolve, reject) => {\n var scriptTag = document.createElement(\"script\");\n scriptTag.src = url;\n scriptTag.type = \"text/javascript\";\n scriptTag.onload = resolve;\n scriptTag.onreadystatechange = function() {\n if (this.readyState === \"loaded\" || this.readyState === \"complete\") {\n resolve();\n }\n };\n scriptTag.onerror = reject;\n document.head.appendChild(scriptTag);\n });\n }\n\n // support importScripts outside web worker\n async function importScripts() {\n var args = Array.prototype.slice.call(arguments),\n len = args.length,\n i = 0;\n for (; i < len; i++) {\n await _importScript(args[i]);\n }\n }\n\n if (\n requirements &&\n (Array.isArray(requirements) || typeof requirements === \"string\")\n ) {\n try {\n var link_node;\n requirements =\n typeof requirements === \"string\" ? [requirements] : requirements;\n if (Array.isArray(requirements)) {\n for (var i = 0; i < requirements.length; i++) {\n if (\n requirements[i].toLowerCase().endsWith(\".css\") ||\n requirements[i].startsWith(\"css:\")\n ) {\n if (requirements[i].startsWith(\"css:\")) {\n requirements[i] = requirements[i].slice(4);\n }\n link_node = document.createElement(\"link\");\n link_node.rel = \"stylesheet\";\n link_node.href = requirements[i];\n document.head.appendChild(link_node);\n } else if (\n requirements[i].toLowerCase().endsWith(\".mjs\") ||\n requirements[i].startsWith(\"mjs:\")\n ) {\n // import esmodule\n if (requirements[i].startsWith(\"mjs:\")) {\n requirements[i] = requirements[i].slice(4);\n }\n await import(/* webpackIgnore: true */ requirements[i]);\n } else if (\n requirements[i].toLowerCase().endsWith(\".js\") ||\n requirements[i].startsWith(\"js:\")\n ) {\n if (requirements[i].startsWith(\"js:\")) {\n requirements[i] = requirements[i].slice(3);\n }\n await importScripts(requirements[i]);\n } else if (requirements[i].startsWith(\"http\")) {\n await importScripts(requirements[i]);\n } else if (requirements[i].startsWith(\"cache:\")) {\n //ignore cache\n } else {\n console.log(\"Unprocessed requirements url: \" + requirements[i]);\n }\n }\n } else {\n throw \"unsupported requirements definition\";\n }\n } catch (e) {\n throw \"failed to import required scripts: \" + requirements.toString();\n }\n }\n}\n\nexport async function loadRequirementsInWebworker(requirements) {\n if (\n requirements &&\n (Array.isArray(requirements) || typeof requirements === \"string\")\n ) {\n try {\n if (!Array.isArray(requirements)) {\n requirements = [requirements];\n }\n for (var i = 0; i < requirements.length; i++) {\n if (\n requirements[i].toLowerCase().endsWith(\".css\") ||\n requirements[i].startsWith(\"css:\")\n ) {\n throw \"unable to import css in a webworker\";\n } else if (\n requirements[i].toLowerCase().endsWith(\".js\") ||\n requirements[i].startsWith(\"js:\")\n ) {\n if (requirements[i].startsWith(\"js:\")) {\n requirements[i] = requirements[i].slice(3);\n }\n importScripts(requirements[i]);\n } else if (requirements[i].startsWith(\"http\")) {\n importScripts(requirements[i]);\n } else if (requirements[i].startsWith(\"cache:\")) {\n //ignore cache\n } else {\n console.log(\"Unprocessed requirements url: \" + requirements[i]);\n }\n }\n } catch (e) {\n throw \"failed to import required scripts: \" + requirements.toString();\n }\n }\n}\n\nexport function loadRequirements(requirements) {\n if (\n typeof WorkerGlobalScope !== \"undefined\" &&\n self instanceof WorkerGlobalScope\n ) {\n return loadRequirementsInWebworker(requirements);\n } else {\n return loadRequirementsInWindow(requirements);\n }\n}\n\nexport function normalizeConfig(config) {\n config.version = config.version || \"0.1.0\";\n config.description =\n config.description || `[TODO: add description for ${config.name} ]`;\n config.type = config.type || \"rpc-window\";\n config.id = config.id || randId();\n config.target_origin = config.target_origin || \"*\";\n config.allow_execution = config.allow_execution || false;\n // remove functions\n config = Object.keys(config).reduce((p, c) => {\n if (typeof config[c] !== \"function\") p[c] = config[c];\n return p;\n }, {});\n return config;\n}\nexport const typedArrayToDtypeMapping = {\n Int8Array: \"int8\",\n Int16Array: \"int16\",\n Int32Array: \"int32\",\n Uint8Array: \"uint8\",\n Uint16Array: \"uint16\",\n Uint32Array: \"uint32\",\n Float32Array: \"float32\",\n Float64Array: \"float64\",\n Array: \"array\"\n};\n\nconst typedArrayToDtypeKeys = [];\nfor (const arrType of Object.keys(typedArrayToDtypeMapping)) {\n typedArrayToDtypeKeys.push(eval(arrType));\n}\n\nexport function typedArrayToDtype(obj) {\n let dtype = typedArrayToDtypeMapping[obj.constructor.name];\n if (!dtype) {\n const pt = Object.getPrototypeOf(obj);\n for (const arrType of typedArrayToDtypeKeys) {\n if (pt instanceof arrType) {\n dtype = typedArrayToDtypeMapping[arrType.name];\n break;\n }\n }\n }\n return dtype;\n}\n\nfunction cacheUrlInServiceWorker(url) {\n return new Promise(function(resolve, reject) {\n const message = {\n command: \"add\",\n url: url\n };\n if (!navigator.serviceWorker || !navigator.serviceWorker.register) {\n reject(\"Service worker is not supported.\");\n return;\n }\n const messageChannel = new MessageChannel();\n messageChannel.port1.onmessage = function(event) {\n if (event.data && event.data.error) {\n reject(event.data.error);\n } else {\n resolve(event.data && event.data.result);\n }\n };\n\n if (navigator.serviceWorker && navigator.serviceWorker.controller) {\n navigator.serviceWorker.controller.postMessage(message, [\n messageChannel.port2\n ]);\n } else {\n reject(\"Service worker controller is not available\");\n }\n });\n}\n\nexport async function cacheRequirements(requirements) {\n requirements = requirements || [];\n if (!Array.isArray(requirements)) {\n requirements = [requirements];\n }\n for (let req of requirements) {\n //remove prefix\n if (req.startsWith(\"js:\")) req = req.slice(3);\n if (req.startsWith(\"css:\")) req = req.slice(4);\n if (req.startsWith(\"cache:\")) req = req.slice(6);\n if (!req.startsWith(\"http\")) continue;\n\n await cacheUrlInServiceWorker(req).catch(e => {\n console.error(e);\n });\n }\n}\n\nexport function setupServiceWorker(baseUrl, targetOrigin, cacheCallback) {\n // register service worker for offline access\n if (\"serviceWorker\" in navigator) {\n baseUrl = baseUrl || \"/\";\n navigator.serviceWorker.register(baseUrl + \"plugin-service-worker.js\").then(\n function(registration) {\n // Registration was successful\n console.log(\n \"ServiceWorker registration successful with scope: \",\n registration.scope\n );\n },\n function(err) {\n // registration failed :(\n console.log(\"ServiceWorker registration failed: \", err);\n }\n );\n targetOrigin = targetOrigin || \"*\";\n cacheCallback = cacheCallback || cacheRequirements;\n if (cacheCallback && typeof cacheCallback !== \"function\") {\n throw new Error(\"config.cache_requirements must be a function\");\n }\n window.addEventListener(\"message\", function(e) {\n if (targetOrigin === \"*\" || e.origin === targetOrigin) {\n const m = e.data;\n if (m.type === \"cacheRequirements\") {\n cacheCallback(m.requirements);\n }\n }\n });\n }\n}\n\nexport function assert(condition, message) {\n if (!condition) {\n throw new Error(message || \"Assertion failed\");\n }\n}\n\n//#Source https://bit.ly/2neWfJ2\nexport function urlJoin(...args) {\n return args\n .join(\"/\")\n .replace(/[\\/]+/g, \"/\")\n .replace(/^(.+):\\//, \"$1://\")\n .replace(/^file:/, \"file:/\")\n .replace(/\\/(\\?|&|#[^!])/g, \"$1\")\n .replace(/\\?/g, \"&\")\n .replace(\"&\", \"?\");\n}\n\nexport function waitFor(prom, time, error) {\n let timer;\n return Promise.race([\n prom,\n new Promise(\n (_r, rej) =>\n (timer = setTimeout(() => {\n rej(error || \"Timeout Error\");\n }, time * 1000))\n )\n ]).finally(() => clearTimeout(timer));\n}\n\nexport class MessageEmitter {\n constructor(debug) {\n this._event_handlers = {};\n this._once_handlers = {};\n this._debug = debug;\n }\n emit() {\n throw new Error(\"emit is not implemented\");\n }\n on(event, handler) {\n if (!this._event_handlers[event]) {\n this._event_handlers[event] = [];\n }\n this._event_handlers[event].push(handler);\n }\n once(event, handler) {\n handler.___event_run_once = true;\n this.on(event, handler);\n }\n off(event, handler) {\n if (!event && !handler) {\n // remove all events handlers\n this._event_handlers = {};\n } else if (event && !handler) {\n // remove all hanlders for the event\n if (this._event_handlers[event]) this._event_handlers[event] = [];\n } else {\n // remove a specific handler\n if (this._event_handlers[event]) {\n const idx = this._event_handlers[event].indexOf(handler);\n if (idx >= 0) {\n this._event_handlers[event].splice(idx, 1);\n }\n }\n }\n }\n _fire(event, data) {\n if (this._event_handlers[event]) {\n var i = this._event_handlers[event].length;\n while (i--) {\n const handler = this._event_handlers[event][i];\n try {\n handler(data);\n } catch (e) {\n console.error(e);\n } finally {\n if (handler.___event_run_once) {\n this._event_handlers[event].splice(i, 1);\n }\n }\n }\n } else {\n if (this._debug) {\n console.warn(\"unhandled event\", event, data);\n }\n }\n }\n}\n","import { RPC, API_VERSION } from \"./rpc.js\";\nimport { assert, loadRequirements, randId, waitFor } from \"./utils.js\";\n\nexport { RPC, API_VERSION };\nexport { version as VERSION } from \"../../package.json\";\nexport { loadRequirements };\n\nclass WebsocketRPCConnection {\n constructor(server_url, client_id, workspace, token, timeout) {\n assert(server_url && client_id, \"server_url and client_id are required\");\n server_url = server_url + \"?client_id=\" + client_id;\n if (workspace) {\n server_url += \"&workspace=\" + workspace;\n }\n if (token) {\n server_url += \"&token=\" + token;\n }\n this._websocket = null;\n this._handle_message = null;\n this._reconnection_token = null;\n this._server_url = server_url;\n this._timeout = timeout || 5; // 5s\n }\n\n set_reconnection_token(token) {\n this._reconnection_token = token;\n }\n\n on_message(handler) {\n assert(handler, \"handler is required\");\n this._handle_message = handler;\n }\n\n async open() {\n const server_url = this._reconnection_token\n ? `${this._server_url}&reconnection_token=${this._reconnection_token}`\n : this._server_url;\n console.info(\"Receating a new connection to \", server_url.split(\"?\")[0]);\n this._websocket = new WebSocket(server_url);\n this._websocket.binaryType = \"arraybuffer\";\n this._websocket.onmessage = event => {\n const data = event.data;\n this._handle_message(data);\n };\n const self = this;\n this._websocket.onclose = function() {\n console.log(\"websocket closed\");\n self._websocket = null;\n };\n const promise = await new Promise(resolve => {\n this._websocket.addEventListener(\"open\", resolve);\n });\n return await waitFor(\n promise,\n this._timeout,\n \"Timeout Error: Failed connect to the server \" + server_url.split(\"?\")[0]\n );\n }\n\n async emit_message(data) {\n assert(this._handle_message, \"No handler for message\");\n if (!this._websocket) {\n await this.open();\n }\n try {\n if (data.buffer) data = data.buffer;\n this._websocket.send(data);\n } catch (exp) {\n // data = msgpack_unpackb(data);\n console.error(`Failed to send data, error: ${exp}`);\n throw exp;\n }\n }\n\n async disconnect(reason) {\n const ws = this._websocket;\n this._websocket = null;\n if (ws) {\n ws.close(1000, reason);\n }\n console.info(`Websocket connection disconnected (${reason})`);\n }\n}\n\nexport async function connectToServer(config) {\n let clientId = config.client_id;\n if (!clientId) {\n clientId = randId();\n }\n let server_url = config.server_url;\n if (server_url.startsWith(\"http://\")) {\n server_url =\n server_url.replace(\"http://\", \"ws://\").replace(/\\/$/, \"\") + \"/ws\";\n } else if (server_url.startsWith(\"https://\")) {\n server_url =\n server_url.replace(\"https://\", \"wss://\").replace(/\\/$/, \"\") + \"/ws\";\n }\n let connection = new WebsocketRPCConnection(\n server_url,\n clientId,\n config.workspace,\n config.token,\n config.method_timeout || 5\n );\n await connection.open();\n const rpc = new RPC(connection, {\n client_id: clientId,\n manager_id: \"workspace-manager\",\n default_context: { connection_type: \"websocket\" },\n name: config.name,\n method_timeout: config.method_timeout\n });\n const wm = await rpc.get_remote_service(\"workspace-manager:default\");\n wm.rpc = rpc;\n\n async function _export(api) {\n api.id = \"default\";\n api.name = config.name || api.id;\n await rpc.register_service(api, true);\n // const svc = await rpc.get_remote_service(rpc._client_id + \":default\");\n // if (svc.setup) {\n // await svc.setup();\n // }\n }\n\n async function getPlugin(query) {\n return await wm.get_service(query + \":default\");\n }\n\n async function disconnect() {\n await rpc.disconnect();\n await connection.disconnect();\n }\n\n wm.export = _export;\n wm.getPlugin = getPlugin;\n wm.listPlugins = wm.listServices;\n wm.disconnect = disconnect;\n wm.registerCodec = rpc.register_codec.bind(rpc);\n return wm;\n}\n"],"sourceRoot":""}