hakuban 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/hakuban.min.js CHANGED
@@ -1,2 +1,2 @@
1
- let t;const n=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});n.decode();let e=new Uint8Array;function r(){return 0===e.byteLength&&(e=new Uint8Array(t.memory.buffer)),e}function i(t,e){return n.decode(r().subarray(t,t+e))}const o=new Array(32).fill(void 0);o.push(void 0,null,!0,!1);let a=o.length;function s(t){a===o.length&&o.push(o.length+1);const n=a;return a=o[n],o[n]=t,n}function _(t){return o[t]}function c(t){const n=_(t);return function(t){t<36||(o[t]=a,a=t)}(t),n}let l=0;const h=new TextEncoder("utf-8"),u="function"==typeof h.encodeInto?function(t,n){return h.encodeInto(t,n)}:function(t,n){const e=h.encode(t);return n.set(e),{read:t.length,written:e.length}};function d(t,n,e){if(void 0===e){const e=h.encode(t),i=n(e.length);return r().subarray(i,i+e.length).set(e),l=e.length,i}let i=t.length,o=n(i);const a=r();let s=0;for(;s<i;s++){const n=t.charCodeAt(s);if(n>127)break;a[o+s]=n}if(s!==i){0!==s&&(t=t.slice(s)),o=e(o,i,i=s+3*t.length);const n=r().subarray(o+s,o+i);s+=u(t,n).written}return l=s,o}let w=new Int32Array;function f(){return 0===w.byteLength&&(w=new Int32Array(t.memory.buffer)),w}function g(t){const n=typeof t;if("number"==n||"boolean"==n||null==t)return`${t}`;if("string"==n)return`"${t}"`;if("symbol"==n){const n=t.description;return null==n?"Symbol":`Symbol(${n})`}if("function"==n){const n=t.name;return"string"==typeof n&&n.length>0?`Function(${n})`:"Function"}if(Array.isArray(t)){const n=t.length;let e="[";n>0&&(e+=g(t[0]));for(let r=1;r<n;r++)e+=", "+g(t[r]);return e+="]",e}const e=/\[object ([^\]]+)\]/.exec(toString.call(t));let r;if(!(e.length>1))return toString.call(t);if(r=e[1],"Object"==r)try{return"Object("+JSON.stringify(t)+")"}catch(t){return"Object"}return t instanceof Error?`${t.name}: ${t.message}\n${t.stack}`:r}function p(n){t.hakuban_tag_expose_contract_drop(n)}let b=new Uint32Array;function y(){return 0===b.byteLength&&(b=new Uint32Array(t.memory.buffer)),b}function v(t,n){return y().subarray(t/4,t/4+n)}function k(n){t.hakuban_tag_observe_contract_drop(n)}function m(n){t.hakuban_tag_descriptor_drop(n)}function x(n,e){const r=d(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l,o=function(t,n){const e=n(4*t.length);return y().set(t,e/4),l=t.length,e}(e,t.__wbindgen_malloc),a=l,s=t.hakuban_object_descriptor_new(r,i,o,a);return Q.__wrap(s)}function j(n){t.hakuban_object_descriptor_drop(n)}let A=new BigUint64Array;function z(){return 0===A.byteLength&&(A=new BigUint64Array(t.memory.buffer)),A}function I(t,n){const e=n(1*t.length);return r().set(t,e/1),l=t.length,e}function O(n,e,r,i){const o=function(t,n){const e=n(8*t.length);return z().set(t,e/8),l=t.length,e}(n,t.__wbindgen_malloc),a=l,_=function(t,n){const e=n(4*t.length),r=y();for(let n=0;n<t.length;n++)r[e/4+n]=s(t[n]);return l=t.length,e}(e,t.__wbindgen_malloc),c=l,h=I(r,t.__wbindgen_malloc),u=l,d=t.hakuban_object_state_new(o,a,_,c,h,u,i);return Q.__wrap(d)}function P(n){t.hakuban_object_state_drop(n)}let S=new BigInt64Array;function U(n,e){return(0===S.byteLength&&(S=new BigInt64Array(t.memory.buffer)),S).subarray(n/8,n/8+e)}function L(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_state_format(o,n);var e=f()[o/4+0],r=f()[o/4+1],i=function(t,n){const e=y().subarray(t/4,t/4+n),r=[];for(let t=0;t<e.length;t++)r.push(c(e[t]));return r}(e,r).slice();return t.__wbindgen_free(e,4*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}function R(t,n){return r().subarray(t/1,t/1+n)}function T(n){t.hakuban_object_state_stream_drop(n)}function B(n){t.hakuban_remote_exchange_drop(n)}function D(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_message_take(o,n);var e=f()[o/4+0],r=f()[o/4+1],i=R(e,r).slice();return t.__wbindgen_free(e,1*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}function N(n,e,r){const i=t.hakuban_future_returning_pointer_poll(n,e,r);return Q.__wrap(i)}function E(n){t.hakuban_future_returning_nothing_drop(n)}function J(n,e,r){const i=t.hakuban_future_returning_nothing_poll(n,e,r);return K.__wrap(i)}function W(n){t.hakuban_future_returning_nothing_drop(n)}function F(n){t.hakuban_object_state_sink_drop(n)}function $(n){t.hakuban_object_state_sink_params_drop(n)}function q(n){t.hakuban_local_exchange_drop(n)}function C(n){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_local_exchange_notified(s,n);var e=f()[s/4+0],r=f()[s/4+1],i=(o=e,a=r,z().subarray(o/8,o/8+a)).slice();return t.__wbindgen_free(e,8*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}var o,a}function M(n){t.hakuban_object_expose_contract_drop(n)}function H(n){t.hakuban_object_observe_contract_drop(n)}function G(n,e){try{return n.apply(this,e)}catch(n){t.__wbindgen_exn_store(s(n))}}Object.freeze({Ok:0,0:"Ok",Pending:1,1:"Pending",NotAvailable:2,2:"NotAvailable",InvalidString:3,3:"InvalidString",InvalidJSON:4,4:"InvalidJSON",InvalidURL:5,5:"InvalidURL",InvalidLogLevel:6,6:"InvalidLogLevel",UnknownError:7,7:"UnknownError"});class K{static __wrap(t){const n=Object.create(K.prototype);return n.ptr=t,n}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const n=this.__destroy_into_raw();t.__wbg_wasmresultwithnothing_free(n)}get status(){return t.__wbg_get_wasmresultwithnothing_status(this.ptr)>>>0}set status(n){t.__wbg_set_wasmresultwithnothing_status(this.ptr,n)}}class Q{static __wrap(t){const n=Object.create(Q.prototype);return n.ptr=t,n}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const n=this.__destroy_into_raw();t.__wbg_wasmresultwithpointer_free(n)}get status(){return t.__wbg_get_wasmresultwithpointer_status(this.ptr)>>>0}set status(n){t.__wbg_set_wasmresultwithpointer_status(this.ptr,n)}get value(){return t.__wbg_get_wasmresultwithpointer_value(this.ptr)}set value(n){t.__wbg_set_wasmresultwithpointer_value(this.ptr,n)}}function V(){const n={wbg:{}};return n.wbg.__wbindgen_string_new=function(t,n){return s(i(t,n))},n.wbg.__wbindgen_object_drop_ref=function(t){c(t)},n.wbg.__wbindgen_string_get=function(n,e){const r=_(e),i="string"==typeof r?r:void 0;var o=null==i?0:d(i,t.__wbindgen_malloc,t.__wbindgen_realloc),a=l;f()[n/4+1]=a,f()[n/4+0]=o},n.wbg.__wbg_debug_f15cb542ea509609=function(t){console.debug(_(t))},n.wbg.__wbg_error_ef9a0be47931175f=function(t){console.error(_(t))},n.wbg.__wbg_info_2874fdd5393f35ce=function(t){console.info(_(t))},n.wbg.__wbg_log_4b5638ad60bdc54a=function(t){console.log(_(t))},n.wbg.__wbg_warn_58110c4a199df084=function(t){console.warn(_(t))},n.wbg.__wbg_now_8172cd917e5eda6b=function(t){return _(t).now()},n.wbg.__wbg_newnoargs_b5b063fc6c2f0376=function(t,n){return s(new Function(i(t,n)))},n.wbg.__wbg_get_765201544a2b6869=function(){return G((function(t,n){return s(Reflect.get(_(t),_(n)))}),arguments)},n.wbg.__wbg_call_97ae9d8645dc388b=function(){return G((function(t,n){return s(_(t).call(_(n)))}),arguments)},n.wbg.__wbg_self_6d479506f72c6a71=function(){return G((function(){return s(self.self)}),arguments)},n.wbg.__wbg_window_f2557cc78490aceb=function(){return G((function(){return s(window.window)}),arguments)},n.wbg.__wbg_globalThis_7f206bda628d5286=function(){return G((function(){return s(globalThis.globalThis)}),arguments)},n.wbg.__wbg_global_ba75c50d1cf384f4=function(){return G((function(){return s(global.global)}),arguments)},n.wbg.__wbindgen_is_undefined=function(t){return void 0===_(t)},n.wbg.__wbindgen_object_clone_ref=function(t){return s(_(t))},n.wbg.__wbg_new_abda76e883ba8a5f=function(){return s(new Error)},n.wbg.__wbg_stack_658279fe44541cf6=function(n,e){const r=d(_(e).stack,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;f()[n/4+1]=i,f()[n/4+0]=r},n.wbg.__wbg_error_f851667af71bcfc6=function(n,e){try{console.error(i(n,e))}finally{t.__wbindgen_free(n,e)}},n.wbg.__wbindgen_debug_string=function(n,e){const r=d(g(_(e)),t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;f()[n/4+1]=i,f()[n/4+0]=r},n.wbg.__wbindgen_throw=function(t,n){throw new Error(i(t,n))},n}async function X(n){void 0===n&&(n=new URL("hakuban_bg.wasm",import.meta.url));const r=V();("string"==typeof n||"function"==typeof Request&&n instanceof Request||"function"==typeof URL&&n instanceof URL)&&(n=fetch(n));const{instance:i,module:o}=await async function(t,n){if("function"==typeof Response&&t instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(t,n)}catch(n){if("application/wasm"==t.headers.get("Content-Type"))throw n;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n)}const e=await t.arrayBuffer();return await WebAssembly.instantiate(e,n)}{const e=await WebAssembly.instantiate(t,n);return e instanceof WebAssembly.Instance?{instance:e,module:t}:e}}(await n,r);return function(n,r){return t=n.exports,X.__wbindgen_wasm_module=r,S=new BigInt64Array,A=new BigUint64Array,w=new Int32Array,b=new Uint32Array,e=new Uint8Array,t}(i,o)}var Y,Z,tt=function(t){if(0===t.status)return t.value;throw"hakuban wasm call failed: "+t.status},nt=function(t){if(0===t.status)return t.value;if(2===t.status)return null;throw"hakuban wasm call failed: "+t.status},et=class{constructor(t,n,e,r,i){this.local_exchange=t,this.future_owner=n,this.poll_function=e,this.drop_function=r,this._pointer=i}async await_and_drop(t=null){var n,e,r,i;try{for(n=new Promise((t=>this.lock_id=this.future_owner.drop_lock(t)));;)switch(e=this.local_exchange.notified(),(r=this.local_exchange.with_pointer((t=>this.poll_function(t,this._pointer,e.id)))).status){case 0:return r.value;case 1:switch(i=[e,n],null!=t&&i.push(t),await Promise.race(i)){case"ABORT":return!1;case"DROP":return null}break;case 2:return null;default:throw r.status}}finally{this.drop_function(this._pointer),this.future_owner.drop_release(this.lock_id),null!=e&&this.local_exchange.return_notified(e)}}},rt=function(n,e=!1){var r;return 0===(r=function(n){const e=d(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=l;return t.hakuban_logger_initialize(e,r)>>>0}(n))||(console.error("Failed to initialize logger, error "+r),!1)};Z=new FinalizationRegistry((function(t){return t[0](t[1])})),Y=function(t,n){var e,r,i,o,a;try{return e=!1,null!=(a=n(t))&&"function"==typeof a.then?(e=!0,a.finally((()=>{var n,e,r,i,o;for(o=[],n=0,e=(i=[t].flat()).length;n<e;n++)r=i[n],o.push(r.drop());return o}))):a}finally{if(!e)for(r=0,i=(o=[t].flat()).length;r<i;r++)o[r].drop()}};var it,ot=function(t,n){return null!=n?Y(t,n):t},at=class{constructor(){this.message="PointerAlreadyDropped"}},st=class t{initialize_pointer(t,n,e){return this._local_exchange=t,this._pointer=n,this._drop_function=e,this._was_dropped=null,this._drop_locks_sequence=0,this._drop_locks={},Z.register(this,[this._drop_function,this._pointer],this)}dropped(){return null!=this._was_dropped}drop(){return null==this._was_dropped&&(this._was_dropped=new Promise((async t=>{var n,e,r,i;if(null!=this._pointer){if(Object.keys(this._drop_locks).length>0){for(n=new Promise((t=>{this._all_locks_dropped_set=t})),e=0,r=(i=Object.values(this._drop_locks)).length;e<r;e++)(0,i[e])("DROP");await n}if(Object.keys(this._drop_locks).length>0)throw"Hakuban internal error: drop was attempted with existing drop locks";Z.unregister(this),this._drop_function(this._pointer),null!=this._local_exchange&&this._local_exchange.notify()}return this._pointer=!1,t()}))),this._was_dropped}with_pointer(t){if(this.dropped())throw new at;return t(this._pointer)}do_and_drop_or_return(t){return ot(this,t)}drop_lock(n){var e;return null!=this._was_dropped&&raise(t.prototype.PointerAlreadyDropped),e=this._drop_locks_sequence++,this._drop_locks[e]=n,e}drop_release(t){if(delete this._drop_locks[t],null!=this._was_dropped&&0===Object.keys(this._drop_locks).length)return this._all_locks_dropped_set()}},_t=class extends st{constructor(n,e,r=null){var o,a;super(),null!=r?(this.json=JSON.parse(function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_descriptor_json(o,n);var e=f()[o/4+0],r=f()[o/4+1];return i(e,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(e,r)}}(r)),this.tags=function(){var n,e,i,o;for(o=[],n=0,e=(i=function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_descriptor_tags(o,n);var e=f()[o/4+0],r=f()[o/4+1],i=v(e,r).slice();return t.__wbindgen_free(e,4*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(r)).length;n<e;n++)a=i[n],o.push(new ct(null,null,a));return o}()):(this.json=e,this.tags=function(){var t,e,r;for(r=[],t=0,e=n.length;t<e;t++)o=n[t],r.push(o instanceof ct?o:new ct(o));return r}(),r=tt(x(JSON.stringify(this.json),function(){var t,n,e,r;for(r=[],t=0,n=(e=this.tags).length;t<n;t++)o=e[t],r.push(o._pointer);return r}.call(this)))),this.initialize_pointer(null,r,j)}},ct=class extends st{constructor(n){var e;super(),this.json=n,e=tt(function(n){const e=d(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=l,i=t.hakuban_tag_descriptor_new(e,r);return Q.__wrap(i)}(JSON.stringify(this.json))),this.initialize_pointer(null,e,m)}};it=[0,0,0];var lt,ht=class n extends st{constructor(n=null,e=null,r=null,i=0,o=null){var a,s,_;if(super(),null!=o)this.initialize_pointer(null,o,P),this.version=function(){var n,e,r,i;for(i=[],n=0,e=(r=function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_state_version(o,n);var e=f()[o/4+0],r=f()[o/4+1],i=U(e,r).slice();return t.__wbindgen_free(e,8*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(o)).length;n<e;n++)_=r[n],i.push(_);return i}(),this.synchronized_us_ago=function(n){const e=t.hakuban_object_state_synchronized_ago(n);return BigInt.asUintN(64,e)}(o),this.format=L(o),this.data=(new TextDecoder).decode(function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_state_data(o,n);var e=f()[o/4+0],r=f()[o/4+1],i=R(e,r).slice();return t.__wbindgen_free(e,1*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(o));else{if(null==e){for(a=(new Date).getTime(),e=[0,Math.floor(a/1e3),a%1e3*1e3];e[1]===it[1]&&e[2]<=it[2];)e[2]++;it=e}this.version=function(){var t,n,r;for(r=[],t=0,n=e.length;t<n;t++)s=e[t],r.push(BigInt(s));return r}(),null==r&&(r=[]),this.format=[r].flat(Infinity),this.synchronized_us_ago=BigInt(i),this.data=n}}with_pointer(t){var n;if(this.dropped())throw new PointerAlreadyDropped;return null!=this._pointer||(n=tt(O(this.version,this.format,(new TextEncoder).encode(this.data),this.synchronized_us_ago)),this.initialize_pointer(null,n,P)),t(this._pointer)}with_data(t){return new n(t,this.version,this.format,this.synchronized_us_ago)}with_version(t){return new n(this.data,t,this.format,this.synchronized_us_ago)}with_format(t){return new n(this.data,this.version,t,this.synchronized_us_ago)}with_synchronized_us_ago(t){return new n(this.data,this.version,this.format,t)}json_deserialize(){if("JSON"!==this.format[this.format.length-1])throw"Invalid data format";return new n(JSON.parse(this.data),this.version,this.format.slice(0,-1),this.synchronized_us_ago)}json_serialize(){return new n(JSON.stringify(this.data),this.version,this.format.concat("JSON"),this.synchronized_us_ago)}},ut=class t{constructor(t,n=!1,e=!1){this._stream=t,this._without_implicit_drop=n,this._async=e}async(n){return new t(this._stream,this._without_implicit_drop,!0).call_or_return(n)}without_implicit_drop(n){return new t(this._stream,!0,this._async).call_or_return(n)}call_or_return(t){return null!=t?this.call(t):this}async call(t){var n,e;for(e=[];null!=(n=await this._stream.next());)if(this._async)e.push(new Promise((async e=>{var r;if(r=n,this._without_implicit_drop)return await t(r);try{return await t(r)}finally{await r.drop()}})));else if(this._without_implicit_drop)e.push(await t(n));else try{e.push(await t(n))}finally{await n.drop()}return e}},dt=class extends st{constructor(t,n){super(),this.local_exchange=t,this.initialize_pointer(this.local_exchange,n,T)}descriptor(){return this.with_pointer((function(n){return new _t(null,null,(e=n,t.hakuban_object_state_stream_descriptor(e)));var e}))}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_object_state_stream_next(e);var e})),null!=(i=await new et(this.local_exchange,this,N,E,r).await_and_drop())?new ht(null,null,null,null,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}each(t){return new ut(this).call_or_return(t)}current(n){var e,r;try{return null!=(r=this.with_pointer((n=>nt(function(n){const e=t.hakuban_object_state_stream_current(n);return Q.__wrap(e)}(n)))))?new ht(null,null,null,null,r).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}},wt=class extends st{constructor(t){super(),this.initialize_pointer(null,t,$)}},ft=class extends st{constructor(t,n){super(),this.local_exchange=t,this.initialize_pointer(this.local_exchange,n,F)}descriptor(){return this.with_pointer((function(n){return new _t(null,null,(e=n,t.hakuban_object_state_sink_descriptor(e)));var e}))}async send(n){var e,r;try{return r=this.with_pointer((e=>n.with_pointer((n=>function(n,e){return t.hakuban_object_state_sink_push(n,e)}(e,n))))),await new et(this.local_exchange,this,J,W,r).await_and_drop(),this.local_exchange.notify(),!0}catch(t){if((e=t)instanceof PointerAlreadyDropped)return null;throw e}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_object_state_sink_next(e);var e})),null!=(i=await new et(this.local_exchange,this,N,E,r).await_and_drop())?new wt(i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof PointerAlreadyDropped)return null;throw e}}each(t){return new ut(this).call_or_return(t)}current(n){var e,r;try{return null!=(r=this.with_pointer((n=>nt(function(n){const e=t.hakuban_object_state_sink_current(n);return Q.__wrap(e)}(n)))))?new wt(r).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof PointerAlreadyDropped)return null;throw e}}desynchronize(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_object_state_sink_desynchronize(e);var e})),this.local_exchange.notify(),!0}catch(t){if((n=t)instanceof PointerAlreadyDropped)return null;throw n}}};lt=class extends st{each(t){return new ut(this).call_or_return(t)}};var gt,pt,bt=class extends lt{constructor(n,e){super(),this.local_exchange=n,this.descriptor=e[0]instanceof _t?e[0]:new _t(...e),this.local_exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.local_exchange,function(n,e){return t.hakuban_object_observe_contract_new(n,e)}(n,e),H))))),this.local_exchange.notify()}terminate(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_object_observe_contract_terminate(e);var e})),this.local_exchange.notify()}catch(t){if((n=t)instanceof at)return null;throw n}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_object_observe_contract_next(e);var e})),i=await new et(this.local_exchange,this,N,E,r).await_and_drop(),this.local_exchange.notify(),null!=i?await new dt(this.local_exchange,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}ready(n){var e,r;try{return r=this.with_pointer((n=>nt(function(n){const e=t.hakuban_object_observe_contract_ready(n);return Q.__wrap(e)}(n)))),this.local_exchange.notify(),null!=r?new dt(this.local_exchange,r).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}},yt=class extends lt{constructor(n,e){super(),this.local_exchange=n,this.descriptor=e[0]instanceof _t?e[0]:new _t(...e),this.local_exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.local_exchange,function(n,e){return t.hakuban_object_expose_contract_new(n,e)}(n,e),M))))),this.local_exchange.notify()}terminate(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_object_expose_contract_terminate(e);var e})),this.local_exchange.notify()}catch(t){if((n=t)instanceof at)return null;throw n}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_object_expose_contract_next(e);var e})),i=await new et(this.local_exchange,this,N,E,r).await_and_drop(),this.local_exchange.notify(),null!=i?await new ft(this.local_exchange,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}ready(n){var e,r;try{return r=this.with_pointer((n=>nt(function(n){const e=t.hakuban_object_expose_contract_ready(n);return Q.__wrap(e)}(n)))),this.local_exchange.notify(),null!=r?new ft(this.local_exchange,r).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}},vt=class extends lt{constructor(n,e){super(),this.local_exchange=n,this.descriptor=e,this.descriptor instanceof ct||(this.descriptor=new ct(this.descriptor)),this.local_exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.local_exchange,function(n,e){return t.hakuban_tag_observe_contract_new(n,e)}(n,e),k))))),this.local_exchange.notify()}terminate(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_tag_observe_contract_terminate(e);var e})),this.local_exchange.notify()}catch(t){if((n=t)instanceof at)return null;throw n}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_tag_observe_contract_next(e);var e})),i=await new et(this.local_exchange,this,N,E,r).await_and_drop(),this.local_exchange.notify(),null!=i?new dt(this.local_exchange,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}ready(n){var e,r,i;try{return i=this.with_pointer((n=>function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_observe_contract_ready(o,n);var e=f()[o/4+0],r=f()[o/4+1],i=v(e,r).slice();return t.__wbindgen_free(e,4*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(n))),this.local_exchange.notify(),ot(function(){var t,n,e;for(e=[],t=0,n=i.length;t<n;t++)r=i[t],e.push(new dt(this.local_exchange,r));return e}.call(this),n)}catch(t){if((e=t)instanceof at)return null;throw e}}},kt=class extends lt{constructor(n,e){super(),this.local_exchange=n,this.descriptor=e,this.descriptor instanceof ct||(this.descriptor=new ct(this.descriptor)),this.local_exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.local_exchange,function(n,e){return t.hakuban_tag_expose_contract_new(n,e)}(n,e),p))))),this.local_exchange.notify()}terminate(){var n;try{return this.with_pointer((n=>{return e=n,void t.hakuban_tag_expose_contract_terminate(e);var e})),this.local_exchange.notify()}catch(t){if((n=t)instanceof at)return null;throw n}}async next(n){var e,r,i;try{return r=this.with_pointer((n=>{return e=n,t.hakuban_tag_expose_contract_next(e);var e})),i=await new et(this.local_exchange,this,N,E,r).await_and_drop(),this.local_exchange.notify(),null!=i?new ft(this.local_exchange,i).do_and_drop_or_return(n):null}catch(t){if((e=t)instanceof at)return null;throw e}}ready(n){var e,r,i;try{return i=this.with_pointer((n=>function(n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_expose_contract_ready(o,n);var e=f()[o/4+0],r=f()[o/4+1],i=v(e,r).slice();return t.__wbindgen_free(e,4*r),i}finally{t.__wbindgen_add_to_stack_pointer(16)}}(n))),this.local_exchange.notify(),ot(function(){var t,n,e;for(e=[],t=0,n=i.length;t<n;t++)r=i[t],e.push(new ft(this.local_exchange,r));return e}.call(this),n)}catch(t){if((e=t)instanceof at)return null;throw e}}},mt=class extends st{constructor(n="wasm"){super(),this.name=n,this._notification_sequence=BigInt(0),this._notification_resolve={},this.initialize_pointer(null,tt(function(n){const e=d(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=l,i=t.hakuban_local_exchange_new(e,r);return Q.__wrap(i)}(this.name)),q)}object(t,n){return new gt(this,[t,n])}tag(t){return new pt(this,t)}notified(){var t,n;return t=++this._notification_sequence,(n=new Promise((n=>this._notification_resolve[t]=n))).id=t,n}notify(){var t,n,e,r,i;for(i=[],t=0,e=(r=this.with_pointer((function(t){return C(t)}))).length;t<e;t++)n=r[t],null!=this._notification_resolve[n]?(this._notification_resolve[n](!0),i.push(delete this._notification_resolve[n])):i.push(void 0);return i}return_notified(t){return delete this._notification_resolve[t.id]}};gt=class{constructor(t,n){this.local_exchange=t,this.descriptor=n}observe(t){return new bt(this.local_exchange,this.descriptor).do_and_drop_or_return(t)}expose(t){return new yt(this.local_exchange,this.descriptor).do_and_drop_or_return(t)}},pt=class{constructor(t,n){this.local_exchange=t,this.descriptor=n}observe(t){return new vt(this.local_exchange,this.descriptor).do_and_drop_or_return(t)}expose(t){return new kt(this.local_exchange,this.descriptor).do_and_drop_or_return(t)}};var xt=class extends st{constructor(n,e,r,i){super(),this.local_exchange=n,this.local_exchange.with_pointer((n=>this.initialize_pointer(this.local_exchange,function(n,e,r,i){return t.hakuban_remote_exchange_new(n,e,r,i)}(n,e,r,i),B)))}async next(){var n,e,r;try{return e=this.with_pointer((n=>{return e=n,t.hakuban_remote_exchange_next_message_to_network(e);var e})),r=await new et(this.local_exchange,this,N,E,e).await_and_drop(),this.local_exchange.notify(),r}catch(t){if((n=t)instanceof at)return null;throw n}}async send(n){var e,r;try{return r=this.with_pointer((e=>function(n,e){const r=I(e,t.__wbindgen_malloc),i=l;return t.hakuban_remote_exchange_send_message_from_network(n,r,i)}(e,new Uint8Array(n)))),await new et(this.local_exchange,this,J,W,r).await_and_drop(),this.local_exchange.notify()}catch(t){if((e=t)instanceof at)return null;throw e}}},jt=class{constructor(t,n,e={}){this.connect=this.connect.bind(this),this.ping=this.ping.bind(this),this.send=this.send.bind(this),this.local_exchange=t,this.uri=n,this.options=e,this._status_change({connected:!1}),this.socket=void 0,this.reconnection_timer=void 0,this.reconnect_on_close=!0,this.connect()}status(){return Promise.resolve([this.status,this.next_status_promise])}_status_change(t){var n;if(this.status=t,n=this.next_status_promise_resolve,this.next_status_promise=new Promise((t=>{this.next_status_promise_resolve=t})),null!=n)return n([this.status,this.next_status_promise])}disconnect(){if(this.reconnect_on_close=!1,null!=this.socket)return this.socket.close()}connect(){var t;null!=this.reconnection_timer&&clearTimeout(this.reconnection_timer),this.reconnection_timer=void 0;try{this.socket=new WebSocket(this.uri)}catch(n){return t=n,console.error("Error connecting to hakuban remote exchange:",t),this._status_change({connected:!1,error:t}),!1}return this.socket.binaryType="arraybuffer",this.socket.onopen=()=>(this.options.debug&&console.debug("Connected to hakuban remote exchange"),this.remote_exchange=new xt(this.local_exchange,!0,!0,!0),this.forwarding_to_network_stopped=new Promise((async n=>{var e;try{for(;null!=this.remote_exchange&&null!=(e=await this.remote_exchange.next());)this.send(D(e))}catch(n){t=n,console.error("Error processing hakuban connection:",t),null!=this.socket&&this.socket.close()}return n()})),this._status_change({connected:!0})),this.socket.onclose=async t=>{if(this.options.debug&&null!=this.remote_exchange&&console.debug("Disconnected from hakuban remote exchange"),this.options.debug&&null==this.remote_exchange&&console.debug("Failed to connect to hakuban remote exchange"),this._status_change({connected:!1,disconnect_reason:t.reason,clean_disconnect:t.wasClean}),this.socket=void 0,null!=this.keep_alive_interval&&(clearInterval(this.keep_alive_interval),this.keep_alive_interval=null),null!=this.reconnection_timer&&(clearTimeout(this.reconnection_timer),this.reconnection_timer=null),null!=this.remote_exchange&&(await this.remote_exchange.drop(),await this.forwarding_to_network_stopped,this.forwarding_to_network_stopped=null,this.remote_exchange=null),this.reconnect_on_close)return this.reconnection_timer=setTimeout(this.connect,1e3)},this.socket.onmessage=async n=>{if(null!=this.remote_exchange)try{return await this.remote_exchange.send(n.data)}catch(n){if(t=n,console.error("Error processing hakuban connection:",t),null!=this.socket)return this.socket.close()}}}ping(){if(this.socket)return this.socket.send(new Uint8Array)}send(t){if(t.length>0)return this.socket.send(t),this.keep_alive_interval&&clearInterval(this.keep_alive_interval),this.keep_alive_interval=setInterval(this.ping,1e4)}},At=async function(t,n){var e;return e=await X(t),rt(n),e};export{mt as LocalExchange,_t as ObjectDescriptor,yt as ObjectExposeContract,bt as ObjectObserveContract,ht as ObjectState,ct as TagDescriptor,kt as TagExposeContract,vt as TagObserveContract,jt as WebsocketConnector,At as initialize};
1
+ let t;function n(n){const e=t.__externref_table_alloc();return t.__wbindgen_export_2.set(e,n),e}const e="undefined"!=typeof TextDecoder?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):{decode:()=>{throw Error("TextDecoder not available")}};"undefined"!=typeof TextDecoder&&e.decode();let r=null;function i(){return null!==r&&0!==r.byteLength||(r=new Uint8Array(t.memory.buffer)),r}function o(t,n){return t>>>=0,e.decode(i().subarray(t,t+n))}let s=0;const a="undefined"!=typeof TextEncoder?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},c="function"==typeof a.encodeInto?function(t,n){return a.encodeInto(t,n)}:function(t,n){const e=a.encode(t);return n.set(e),{read:t.length,written:e.length}};function _(t,n,e){if(void 0===e){const e=a.encode(t),r=n(e.length,1)>>>0;return i().subarray(r,r+e.length).set(e),s=e.length,r}let r=t.length,o=n(r,1)>>>0;const _=i();let u=0;for(;u<r;u++){const n=t.charCodeAt(u);if(n>127)break;_[o+u]=n}if(u!==r){0!==u&&(t=t.slice(u)),o=e(o,r,r=u+3*t.length,1)>>>0;const n=i().subarray(o+u,o+r);u+=c(t,n).written,o=e(o,r,u,1)>>>0}return s=u,o}let u=null;function h(){return(null===u||!0===u.buffer.detached||void 0===u.buffer.detached&&u.buffer!==t.memory.buffer)&&(u=new DataView(t.memory.buffer)),u}function l(t){return null==t}function d(n){t.hakuban_object_expose_contract_drop(n)}function f(n){return t.hakuban_object_expose_contract_next(n)>>>0}function p(n){t.hakuban_object_observe_contract_drop(n)}function g(n){return t.hakuban_object_observe_contract_next(n)>>>0}function w(n){t.hakuban_object_state_sink_drop(n)}function b(n){return t.hakuban_object_state_sink_next(n)>>>0}function m(n){t.hakuban_object_state_sink_params_drop(n)}function y(n){t.hakuban_object_state_stream_drop(n)}function v(n){return t.hakuban_object_state_stream_next(n)>>>0}function x(n){t.hakuban_tag_observe_contract_drop(n)}function k(n){return t.hakuban_tag_observe_contract_next(n)>>>0}function j(n){t.hakuban_upstream_connection_drop(n)}function z(n){return t.hakuban_upstream_connection_next_message_to_network(n)>>>0}function O(t,n){return t>>>=0,i().subarray(t/1,t/1+n)}function I(n){const e=t.hakuban_message_serialize(n);var r=O(e[0],e[1]).slice();return t.__wbindgen_free(e[0],1*e[1],1),r}function S(t,n){const e=n(1*t.length,1)>>>0;return i().set(t,e/1),s=t.length,e}let L=null;function T(){return null!==L&&0!==L.byteLength||(L=new BigUint64Array(t.memory.buffer)),L}function P(e,r,i,o){const a=function(t,n){const e=n(8*t.length,8)>>>0;return T().set(t,e/8),s=t.length,e}(e,t.__wbindgen_malloc),c=s,_=function(t,e){const r=e(4*t.length,4)>>>0;for(let e=0;e<t.length;e++){const i=n(t[e]);h().setUint32(r+4*e,i,!0)}return s=t.length,r}(r,t.__wbindgen_malloc),u=s,l=S(i,t.__wbindgen_malloc),d=s,f=t.hakuban_object_state_new(a,c,_,u,l,d,o);return Q.__wrap(f)}function A(n){t.hakuban_object_state_drop(n)}let E=null;function R(n,e){return n>>>=0,(null!==E&&0!==E.byteLength||(E=new BigInt64Array(t.memory.buffer)),E).subarray(n/8,n/8+e)}function D(n){const e=t.hakuban_object_state_format(n);var r=function(n,e){n>>>=0;const r=h(),i=[];for(let o=n;o<n+4*e;o+=4)i.push(t.__wbindgen_export_2.get(r.getUint32(o,!0)));return t.__externref_drop_slice(n,e),i}(e[0],e[1]).slice();return t.__wbindgen_free(e[0],4*e[1],4),r}function U(n){t.hakuban_tag_descriptor_drop(n)}let B=null;function N(){return null!==B&&0!==B.byteLength||(B=new Uint32Array(t.memory.buffer)),B}function W(n,e){const r=_(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=s,o=function(t,n){const e=n(4*t.length,4)>>>0;return N().set(t,e/4),s=t.length,e}(e,t.__wbindgen_malloc),a=s,c=t.hakuban_object_descriptor_new(r,i,o,a);return Q.__wrap(c)}function J(n){t.hakuban_object_descriptor_drop(n)}function C(n){const e=t.hakuban_object_descriptor_tags(n);var r,i,o=(r=e[0],i=e[1],r>>>=0,N().subarray(r/4,r/4+i)).slice();return t.__wbindgen_free(e[0],4*e[1],4),o}function F(n){t.hakuban_tag_expose_contract_drop(n)}function q(n){return t.hakuban_tag_expose_contract_next(n)>>>0}function M(n){t.hakuban_exchange_drop(n)}function G(n){const e=t.hakuban_exchange_notified(n);var r,i,o=(r=e[0],i=e[1],r>>>=0,T().subarray(r/8,r/8+i)).slice();return t.__wbindgen_free(e[0],8*e[1],8),o}function H(n,e,r){const i=t.hakuban_future_poll(n,e,r);return Q.__wrap(i)}function V(n){t.hakuban_future_drop(n)}Object.freeze({Ok:0,0:"Ok",Pointer:1,1:"Pointer",Pending:2,2:"Pending",EndOfStream:3,3:"EndOfStream",InvalidString:4,4:"InvalidString",InvalidJSON:5,5:"InvalidJSON",InvalidURL:6,6:"InvalidURL",InvalidLogLevel:7,7:"InvalidLogLevel",LoggerInitializationError:8,8:"LoggerInitializationError",ConnectionTerminated:9,9:"ConnectionTerminated"});const K="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((n=>t.__wbg_wasmresult_free(n>>>0,1)));class Q{static __wrap(t){t>>>=0;const n=Object.create(Q.prototype);return n.__wbg_ptr=t,K.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,K.unregister(this),t}free(){const n=this.__destroy_into_raw();t.__wbg_wasmresult_free(n,0)}get status(){return t.__wbg_get_wasmresult_status(this.__wbg_ptr)}set status(n){t.__wbg_set_wasmresult_status(this.__wbg_ptr,n)}get pointer(){const n=t.__wbg_get_wasmresult_pointer(this.__wbg_ptr);return 4294967297===n?void 0:n}set pointer(n){t.__wbg_set_wasmresult_pointer(this.__wbg_ptr,l(n)?4294967297:n>>>0)}get error_message(){const n=t.__wbg_get_wasmresult_error_message(this.__wbg_ptr);let e;return 0!==n[0]&&(e=o(n[0],n[1]).slice(),t.__wbindgen_free(n[0],1*n[1],1)),e}set error_message(n){var e=l(n)?0:_(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=s;t.__wbg_set_wasmresult_error_message(this.__wbg_ptr,e,r)}}function X(){const e={wbg:{}};return e.wbg.__wbg_call_672a4d21634d4a24=function(){return function(e,r){try{return e.apply(this,r)}catch(e){const r=n(e);t.__wbindgen_exn_store(r)}}((function(t,n){return t.call(n)}),arguments)},e.wbg.__wbg_debug_3cb59063b29f58c1=function(t){console.debug(t)},e.wbg.__wbg_error_524f506f44df1645=function(t){console.error(t)},e.wbg.__wbg_error_7534b8e9a36f1ab4=function(n,e){let r,i;try{r=n,i=e,console.error(o(n,e))}finally{t.__wbindgen_free(r,i,1)}},e.wbg.__wbg_info_3daf2e093e091b66=function(t){console.info(t)},e.wbg.__wbg_log_c222819a41e063d3=function(t){console.log(t)},e.wbg.__wbg_new_8a6f238a6ece86ea=function(){return new Error},e.wbg.__wbg_newnoargs_105ed471475aaf50=function(t,n){return new Function(o(t,n))},e.wbg.__wbg_now_2c95c9de01293173=function(t){return t.now()},e.wbg.__wbg_performance_7a3ffd0b17f663ad=function(t){return t.performance},e.wbg.__wbg_stack_0ed75d68575b0f3c=function(n,e){const r=_(e.stack,t.__wbindgen_malloc,t.__wbindgen_realloc),i=s;h().setInt32(n+4,i,!0),h().setInt32(n+0,r,!0)},e.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07=function(){const t="undefined"==typeof global?null:global;return l(t)?0:n(t)},e.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0=function(){const t="undefined"==typeof globalThis?null:globalThis;return l(t)?0:n(t)},e.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819=function(){const t="undefined"==typeof self?null:self;return l(t)?0:n(t)},e.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40=function(){const t="undefined"==typeof window?null:window;return l(t)?0:n(t)},e.wbg.__wbg_warn_4ca3906c248c47c4=function(t){console.warn(t)},e.wbg.__wbindgen_init_externref_table=function(){const n=t.__wbindgen_export_2,e=n.grow(4);n.set(0,void 0),n.set(e+0,void 0),n.set(e+1,null),n.set(e+2,!0),n.set(e+3,!1)},e.wbg.__wbindgen_is_undefined=function(t){return void 0===t},e.wbg.__wbindgen_string_get=function(n,e){const r="string"==typeof e?e:void 0;var i=l(r)?0:_(r,t.__wbindgen_malloc,t.__wbindgen_realloc),o=s;h().setInt32(n+4,o,!0),h().setInt32(n+0,i,!0)},e.wbg.__wbindgen_string_new=function(t,n){return o(t,n)},e.wbg.__wbindgen_throw=function(t,n){throw new Error(o(t,n))},e}async function Y(n){if(void 0!==t)return t;void 0!==n&&(Object.getPrototypeOf(n)===Object.prototype?({module_or_path:n}=n):console.warn("using deprecated parameters for the initialization function; pass a single object instead")),void 0===n&&(n=new URL("hakuban_bg.wasm",import.meta.url));const e=X();("string"==typeof n||"function"==typeof Request&&n instanceof Request||"function"==typeof URL&&n instanceof URL)&&(n=fetch(n));const{instance:i,module:o}=await async function(t,n){if("function"==typeof Response&&t instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(t,n)}catch(n){if("application/wasm"==t.headers.get("Content-Type"))throw n;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n)}const e=await t.arrayBuffer();return await WebAssembly.instantiate(e,n)}{const e=await WebAssembly.instantiate(t,n);return e instanceof WebAssembly.Instance?{instance:e,module:t}:e}}(await n,e);return function(n,e){return t=n.exports,Y.__wbindgen_wasm_module=e,E=null,L=null,u=null,B=null,r=null,t.__wbindgen_start(),t}(i,o)}var Z,$,tt=function(t){if(1===t.status)return t.pointer;throw"hakuban wasm call failed: "+t.status},nt=class{constructor(t,n,e,r,i,o){this.exchange=t,this.future_owner=n,this.poll_function=e,this.drop_function=r,this._pointer=i,this.debug_description=o}async await_and_drop(t=null){var n,e,r,i;try{for(n=new Promise((t=>this.lock_id=this.future_owner.drop_lock(t)));;)switch(e=this.exchange.notified(),this.debug_description&&"trace"===st()&&console.debug("polling "+this.debug_description,e.id),r=this.exchange.with_pointer((t=>this.poll_function(t,this._pointer,e.id))),this.debug_description&&"trace"===st()&&console.debug("polled "+this.debug_description,e.id,r.status),this.exchange.notify(),r.status){case 0:return!0;case 1:return r.pointer;case 2:switch(i=[e,n],null!=t&&i.push(t),await Promise.race(i)){case"ABORT":return!1;case"DROP":return null}break;case 3:return null;default:throw console.error(r.error_message),r.status}}finally{this.drop_function(this._pointer),this.future_owner.drop_release(this.lock_id),null!=e&&this.exchange.return_notified(e)}}};Z=!1,$=void 0;var et,rt,it,ot=function(n,e=!1){var r;if(!Z||!e)return 0===(r=function(n){const e=_(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=s,i=t.hakuban_logger_initialize(e,r);return Q.__wrap(i)}(n)).status?(Z=!0,$=n):console.error("Failed to initialize logger, error "+r.error_message)},st=function(){return $};it=new FinalizationRegistry((function(t){return t[0](t[1])})),et=function(t,n){var e,r,i,o,s;try{return e=!1,null!=(s=n(t))&&"function"==typeof s.then?(e=!0,s.finally((()=>{var n,e,r,i,o;for(o=[],n=0,e=(i=[t].flat()).length;n<e;n++)r=i[n],o.push(r.drop());return o}))):s}finally{if(!e)for(r=0,i=(o=[t].flat()).length;r<i;r++)o[r].drop()}},rt=function(t,n){return null!=n?et(t,n):t};var at,ct=class{constructor(){this.message="PointerAlreadyDropped"}},_t=class t{initialize_pointer(t,n,e){return this._exchange=t,this._pointer=n,this._drop_function=e,this._was_dropped=null,this._drop_locks_sequence=0,this._drop_locks={},it.register(this,[this._drop_function,this._pointer],this)}dropped(){return null!=this._was_dropped}drop(){return null==this._was_dropped&&(this._was_dropped=new Promise((async t=>{var n,e,r,i;if(null!=this._pointer){if(Object.keys(this._drop_locks).length>0){for(n=new Promise((t=>{this._all_locks_dropped_set=t})),e=0,r=(i=Object.values(this._drop_locks)).length;e<r;e++)(0,i[e])("DROP");await n}if(Object.keys(this._drop_locks).length>0)throw"Hakuban internal error: drop was attempted with existing drop locks";it.unregister(this),this._drop_function(this._pointer),null!=this._exchange&&this._exchange.notify()}return this._pointer=!1,t()}))),this._was_dropped}with_pointer(t){if(this.dropped())throw new ct;return t(this._pointer)}do_and_drop_or_return(t){return rt(this,t)}drop_lock(n){var e;return null!=this._was_dropped&&raise(t.prototype.PointerAlreadyDropped),e=this._drop_locks_sequence++,this._drop_locks[e]=n,e}drop_release(t){if(delete this._drop_locks[t],null!=this._was_dropped&&0===Object.keys(this._drop_locks).length)return this._all_locks_dropped_set()}},ut=class extends _t{constructor(n,e,r=null){var i,s;super(),null!=r?(this.json=JSON.parse(function(n){let e,r;try{const i=t.hakuban_object_descriptor_json(n);return e=i[0],r=i[1],o(i[0],i[1])}finally{t.__wbindgen_free(e,r,1)}}(r)),this.tags=function(){var t,n,e,i;for(i=[],t=0,n=(e=C(r)).length;t<n;t++)s=e[t],i.push(new ht(null,null,s));return i}()):(this.json=e,this.tags=function(){var t,e,r;for(r=[],t=0,e=n.length;t<e;t++)i=n[t],r.push(i instanceof ht?i:new ht(i));return r}(),r=tt(W(JSON.stringify(this.json),function(){var t,n,e,r;for(r=[],t=0,n=(e=this.tags).length;t<n;t++)i=e[t],r.push(i._pointer);return r}.call(this)))),this.initialize_pointer(null,r,J)}},ht=class extends _t{constructor(n){var e;super(),this.json=n,e=tt(function(n){const e=_(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=s,i=t.hakuban_tag_descriptor_new(e,r);return Q.__wrap(i)}(JSON.stringify(this.json))),this.initialize_pointer(null,e,U)}};at=[0,0,0];var lt,dt,ft,pt,gt=class n extends _t{constructor(n=null,e=null,r=null,i=0,o=null){var s,a,c;if(super(),null!=o)this.initialize_pointer(null,o,A),this.version=function(){var n,e,r,i;for(i=[],n=0,e=(r=function(n){const e=t.hakuban_object_state_version(n);var r=R(e[0],e[1]).slice();return t.__wbindgen_free(e[0],8*e[1],8),r}(o)).length;n<e;n++)c=r[n],i.push(c);return i}(),this.synchronized_us_ago=function(n){const e=t.hakuban_object_state_synchronized_ago(n);return BigInt.asUintN(64,e)}(o),this.format=D(o),this.data=(new TextDecoder).decode(function(n){const e=t.hakuban_object_state_data(n);var r=O(e[0],e[1]).slice();return t.__wbindgen_free(e[0],1*e[1],1),r}(o));else{if(null==e){for(s=(new Date).getTime(),e=[0,Math.floor(s/1e3),s%1e3*1e3];e[1]===at[1]&&e[2]<=at[2];)e[2]++;at=e}this.version=function(){var t,n,r;for(r=[],t=0,n=e.length;t<n;t++)a=e[t],r.push(BigInt(a));return r}(),null==r&&(r=[]),this.format=[r].flat(Infinity),this.synchronized_us_ago=BigInt(i),this.data=n}}static from_pointer(t,e){return new n(null,null,null,null,e)}with_pointer(t){var n;if(this.dropped())throw new PointerAlreadyDropped;return null!=this._pointer||(n=tt(P(this.version,this.format,(new TextEncoder).encode(this.data),this.synchronized_us_ago)),this.initialize_pointer(null,n,A)),t(this._pointer)}with_data(t){return new n(t,this.version,this.format,this.synchronized_us_ago)}with_version(t){return new n(this.data,t,this.format,this.synchronized_us_ago)}with_format(t){return new n(this.data,this.version,t,this.synchronized_us_ago)}with_synchronized_us_ago(t){return new n(this.data,this.version,this.format,t)}json_deserialize(){if("JSON"!==this.format[this.format.length-1])throw"Invalid data format";return new n(JSON.parse(this.data),this.version,this.format.slice(0,-1),this.synchronized_us_ago)}json_serialize(){return new n(JSON.stringify(this.data),this.version,this.format.concat("JSON"),this.synchronized_us_ago)}},wt=class{static mixin(t,n,e,r){var i;return t.next=async function(t){var i,o,s;try{return o=this.with_pointer((t=>n(t))),null!=(s=await new nt(this.exchange,this,H,V,o,r+".next").await_and_drop())?null!=e?await new e(this.exchange,s).do_and_drop_or_return(t):s:null}catch(t){if((i=t)instanceof ct)return null;throw i}},t.for_each_concurrent=async function(t){var n,e,r,i,o;for await(e of(i=function(n,e,r){return new Promise((async i=>{try{return await t(r)}finally{await r.drop(),delete n[e]}}))},o={},r=0,this))o[n=++r]=i(o,n,e);return await Promise.all(Object.values(o))},t.for_each=async function(t){var n,e;for await(n of(e=[],this))try{e.push(await t(n))}finally{await n.drop()}return e},i=class{constructor(t){this.next=async function(){var n;return null!=(n=await t.next())?{done:!1,value:n}:{done:!0}},this.return=function(n){return t.drop(),{done:!0,value:n}}}},t[Symbol.asyncIterator]=function(){return new i(this)}}},bt=class extends _t{constructor(t,n){super(),wt.mixin(this,v,(function(t,n){return new gt(null,null,null,null,n)}),"ObjectStateStream"),this.exchange=t,this.initialize_pointer(this.exchange,n,y)}descriptor(){return this.with_pointer((function(n){return new ut(null,null,(e=n,t.hakuban_object_state_stream_descriptor(e)>>>0));var e}))}},mt=class extends _t{constructor(t,n){super(),this.initialize_pointer(null,n,m)}},yt=class extends _t{constructor(t,n){super(),wt.mixin(this,b,mt),this.exchange=t,this.initialize_pointer(this.exchange,n,w)}descriptor(){return this.with_pointer((function(n){return new ut(null,null,(e=n,t.hakuban_object_state_sink_descriptor(e)>>>0));var e}))}async send(n){var e,r;try{return r=this.with_pointer((e=>n.with_pointer((n=>function(n,e){return t.hakuban_object_state_sink_push(n,e)>>>0}(e,n))))),await new nt(this.exchange,this,H,V,r).await_and_drop(),!0}catch(t){if((e=t)instanceof ct)return null;throw e}}},vt=class extends _t{constructor(n,e){super(),wt.mixin(this,g,bt),this.exchange=n,this.descriptor=e[0]instanceof ut?e[0]:new ut(...e),this.exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.exchange,function(n,e){return t.hakuban_object_observe_contract_new(n,e)>>>0}(n,e),p))))),this.exchange.notify()}},xt=class extends _t{constructor(n,e,r){super(),wt.mixin(this,f,yt),this.exchange=n,this.descriptor=e[0]instanceof ut?e[0]:new ut(...e),this.exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.exchange,function(n,e,r){return t.hakuban_object_expose_contract_new(n,e,r)>>>0}(n,e,r),d))))),this.exchange.notify()}},kt=class extends _t{constructor(n,e){super(),wt.mixin(this,k,bt),this.exchange=n,this.descriptor=e,this.descriptor instanceof ht||(this.descriptor=new ht(this.descriptor)),this.exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.exchange,function(n,e){return t.hakuban_tag_observe_contract_new(n,e)>>>0}(n,e),x))))),this.exchange.notify()}},jt=class extends _t{constructor(n,e,r){super(),wt.mixin(this,q,yt),this.exchange=n,this.descriptor=e,this.descriptor instanceof ht||(this.descriptor=new ht(this.descriptor)),this.exchange.with_pointer((n=>this.descriptor.with_pointer((e=>this.initialize_pointer(this.exchange,function(n,e,r){return t.hakuban_tag_expose_contract_new(n,e,r)>>>0}(n,e,r),F))))),this.exchange.notify()}},zt=class extends _t{constructor(n="wasm"){super(),this.name=n,this._notification_sequence=BigInt(0),this._notification_resolve={},this.initialize_pointer(null,tt(function(){const n=t.hakuban_exchange_new();return Q.__wrap(n)}(this.name)),M)}object_observe_contract(t,n){return new dt(this,[t,n])}object_expose_contract(t,n){return new lt(this,[t,n])}tag_observe_contract(t){return new pt(this,t)}tag_expose_contract(t){return new ft(this,t)}notified(){var t,n;return t=++this._notification_sequence,(n=new Promise((n=>this._notification_resolve[t]=n))).id=t,n}notify(){var t,n,e,r,i;for(i=[],t=0,e=(r=this.with_pointer((function(t){return G(t)}))).length;t<e;t++)n=r[t],null!=this._notification_resolve[n]?(this._notification_resolve[n](!0),i.push(delete this._notification_resolve[n])):i.push(void 0);return i}return_notified(t){return delete this._notification_resolve[t.id]}};dt=class{constructor(t,n){this.exchange=t,this.descriptor=n}build(t){return new vt(this.exchange,this.descriptor).do_and_drop_or_return(t)}},lt=class{constructor(t,n){this.exchange=t,this.descriptor=n,this.capacity=1}with_capacity(t){return this.capacity=t}build(t){return new xt(this.exchange,this.descriptor,this.capacity).do_and_drop_or_return(t)}},pt=class{constructor(t,n){this.exchange=t,this.descriptor=n}build(t){return new kt(this.exchange,this.descriptor).do_and_drop_or_return(t)}},ft=class{constructor(t,n){this.exchange=t,this.descriptor=n,this.capacity=1}with_capacity(t){return this.capacity=t}build(t){return new jt(this.exchange,this.descriptor,this.capacity).do_and_drop_or_return(t)}};var Ot=class extends _t{constructor(n,e,r){super(),wt.mixin(this,z,void 0,"UpstreamConnection"),this.exchange=n,this.exchange.with_pointer((n=>this.initialize_pointer(this.exchange,function(n,e,r){const i=_(e,t.__wbindgen_malloc,t.__wbindgen_realloc),o=s,a=_(r,t.__wbindgen_malloc,t.__wbindgen_realloc),c=s;return t.hakuban_upstream_connection_new(n,i,o,a,c)>>>0}(n,e,r),j)))}async send(n){var e,r;try{return r=this.with_pointer((e=>function(n,e){const r=S(e,t.__wbindgen_malloc),i=s;return t.hakuban_upstream_connection_send_message_from_network(n,r,i)>>>0}(e,new Uint8Array(n)))),await new nt(this.exchange,this,H,V,r,"UpstreamConnection.send").await_and_drop()}catch(t){if((e=t)instanceof ct)return null;throw e}}},It=class{constructor(t,n){this.connect=this.connect.bind(this),this.ping=this.ping.bind(this),this.send=this.send.bind(this),this.exchange=t,this.uri=n,this._status_change({connected:!1}),this.socket=void 0,this.reconnection_timer=void 0,this.reconnect_on_close=!0,this.connect()}status(){return Promise.resolve([this.status,this.next_status_promise])}_status_change(t){var n;if(this.status=t,n=this.next_status_promise_resolve,this.next_status_promise=new Promise((t=>{this.next_status_promise_resolve=t})),null!=n)return n([this.status,this.next_status_promise])}disconnect(){if(this.reconnect_on_close=!1,null!=this.socket)return this.socket.close()}connect(){var t;null!=this.reconnection_timer&&clearTimeout(this.reconnection_timer),this.reconnection_timer=void 0;try{this.socket=new WebSocket(this.uri)}catch(n){return t=n,console.error("Error connecting to remote exchange:",t),this._status_change({connected:!1,error:t}),!1}return this.socket.binaryType="arraybuffer",this.socket.onopen=n=>(console.debug("Connected to remote exchange"),this.upstream_connection=new Ot(this.exchange,"js-client","unknown"),this.forwarding_to_network_stopped=new Promise((async n=>{var e;try{for await(e of this.upstream_connection)this.send(I(e))}catch(n){t=n,console.error("Error processing hakuban connection:",t),null!=this.socket&&this.socket.close()}return n()})),this._status_change({connected:!0})),this.socket.onclose=async t=>{if(console.debug("Disconnected from remote exchange"),console.debug("Failed to connect to remote exchange"),this._status_change({connected:!1,disconnect_reason:t.reason,clean_disconnect:t.wasClean}),this.socket=void 0,null!=this.keep_alive_interval&&(clearInterval(this.keep_alive_interval),this.keep_alive_interval=null),null!=this.reconnection_timer&&(clearTimeout(this.reconnection_timer),this.reconnection_timer=null),null!=this.upstream_connection&&(await this.upstream_connection.drop(),await this.forwarding_to_network_stopped,this.forwarding_to_network_stopped=null,this.upstream_connection=null),this.reconnect_on_close)return this.reconnection_timer=setTimeout(this.connect,1e3)},this.socket.onmessage=async n=>{if(!(0===n.data.byteLength||0===n.data.length||"string"==typeof n.data||n.data instanceof String)&&null!=this.upstream_connection)try{return await this.upstream_connection.send(n.data)}catch(n){if(t=n,console.error("Error processing hakuban connection:",t),null!=this.socket)return this.socket.close()}}}ping(){if(null!=this.socket)return this.socket.send(".")}send(t){return this.socket.send(t),this.keep_alive_interval&&clearInterval(this.keep_alive_interval),this.keep_alive_interval=setInterval(this.ping,1e4)}},St=async function(t,n){var e;return e=await Y(t),ot(n),e};export{zt as Exchange,ut as ObjectDescriptor,xt as ObjectExposeContract,vt as ObjectObserveContract,gt as ObjectState,ht as TagDescriptor,jt as TagExposeContract,kt as TagObserveContract,It as WebsocketConnector,St as initialize};
2
2
  //# sourceMappingURL=hakuban.min.js.map