hakuban 0.7.1 → 0.7.3

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 Array(32).fill(void 0);function e(t){return n[t]}n.push(void 0,null,!0,!1);let r=n.length;function i(t){const i=e(t);return function(t){t<36||(n[t]=r,r=t)}(t),i}let o=0,a=new Uint8Array;function s(){return 0===a.byteLength&&(a=new Uint8Array(t.memory.buffer)),a}const _=new TextEncoder("utf-8"),c="function"==typeof _.encodeInto?function(t,n){return _.encodeInto(t,n)}:function(t,n){const e=_.encode(t);return n.set(e),{read:t.length,written:e.length}};function l(t,n,e){if(void 0===e){const e=_.encode(t),r=n(e.length);return s().subarray(r,r+e.length).set(e),o=e.length,r}let r=t.length,i=n(r);const a=s();let l=0;for(;l<r;l++){const n=t.charCodeAt(l);if(n>127)break;a[i+l]=n}if(l!==r){0!==l&&(t=t.slice(l)),i=e(i,r,r=l+3*t.length);const n=s().subarray(i+l,i+r);l+=c(t,n).written}return o=l,i}let h=new Int32Array;function u(){return 0===h.byteLength&&(h=new Int32Array(t.memory.buffer)),h}const d=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});function w(t,n){return d.decode(s().subarray(t,t+n))}function f(t){r===n.length&&n.push(n.length+1);const e=r;return r=n[e],n[e]=t,e}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)}d.decode();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=l(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=o,a=function(t,n){const e=n(4*t.length);return y().set(t,e/4),o=t.length,e}(e,t.__wbindgen_malloc),s=o,_=t.hakuban_object_descriptor_new(r,i,a,s);return Q.__wrap(_)}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 s().set(t,e/1),o=t.length,e}function O(n,e,r,i){const a=function(t,n){const e=n(8*t.length);return z().set(t,e/8),o=t.length,e}(n,t.__wbindgen_malloc),s=o,_=function(t,n){const e=n(4*t.length),r=y();for(let n=0;n<t.length;n++)r[e/4+n]=f(t[n]);return o=t.length,e}(e,t.__wbindgen_malloc),c=o,l=I(r,t.__wbindgen_malloc),h=o,u=t.hakuban_object_state_new(a,s,_,c,l,h,i);return Q.__wrap(u)}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 a=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_state_format(a,n);var e=u()[a/4+0],r=u()[a/4+1],o=function(t,n){const e=y().subarray(t/4,t/4+n),r=[];for(let t=0;t<e.length;t++)r.push(i(e[t]));return r}(e,r).slice();return t.__wbindgen_free(e,4*r),o}finally{t.__wbindgen_add_to_stack_pointer(16)}}function R(t,n){return s().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=u()[o/4+0],r=u()[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=u()[s/4+0],r=u()[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(f(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_object_drop_ref=function(t){i(t)},n.wbg.__wbindgen_string_get=function(n,r){const i=e(r),a="string"==typeof i?i:void 0;var s=null==a?0:l(a,t.__wbindgen_malloc,t.__wbindgen_realloc),_=o;u()[n/4+1]=_,u()[n/4+0]=s},n.wbg.__wbindgen_string_new=function(t,n){return f(w(t,n))},n.wbg.__wbg_now_8172cd917e5eda6b=function(t){return e(t).now()},n.wbg.__wbg_debug_f15cb542ea509609=function(t){console.debug(e(t))},n.wbg.__wbg_error_ef9a0be47931175f=function(t){console.error(e(t))},n.wbg.__wbg_info_2874fdd5393f35ce=function(t){console.info(e(t))},n.wbg.__wbg_log_4b5638ad60bdc54a=function(t){console.log(e(t))},n.wbg.__wbg_warn_58110c4a199df084=function(t){console.warn(e(t))},n.wbg.__wbg_newnoargs_b5b063fc6c2f0376=function(t,n){return f(new Function(w(t,n)))},n.wbg.__wbg_get_765201544a2b6869=function(){return G((function(t,n){return f(Reflect.get(e(t),e(n)))}),arguments)},n.wbg.__wbg_call_97ae9d8645dc388b=function(){return G((function(t,n){return f(e(t).call(e(n)))}),arguments)},n.wbg.__wbg_self_6d479506f72c6a71=function(){return G((function(){return f(self.self)}),arguments)},n.wbg.__wbg_window_f2557cc78490aceb=function(){return G((function(){return f(window.window)}),arguments)},n.wbg.__wbg_globalThis_7f206bda628d5286=function(){return G((function(){return f(globalThis.globalThis)}),arguments)},n.wbg.__wbg_global_ba75c50d1cf384f4=function(){return G((function(){return f(global.global)}),arguments)},n.wbg.__wbindgen_is_undefined=function(t){return void 0===e(t)},n.wbg.__wbindgen_object_clone_ref=function(t){return f(e(t))},n.wbg.__wbg_new_abda76e883ba8a5f=function(){return f(new Error)},n.wbg.__wbg_stack_658279fe44541cf6=function(n,r){const i=l(e(r).stack,t.__wbindgen_malloc,t.__wbindgen_realloc),a=o;u()[n/4+1]=a,u()[n/4+0]=i},n.wbg.__wbg_error_f851667af71bcfc6=function(n,e){try{console.error(w(n,e))}finally{t.__wbindgen_free(n,e)}},n.wbg.__wbindgen_debug_string=function(n,r){const i=l(g(e(r)),t.__wbindgen_malloc,t.__wbindgen_realloc),a=o;u()[n/4+1]=a,u()[n/4+0]=i},n.wbg.__wbindgen_throw=function(t,n){throw new Error(w(t,n))},n}async function X(n){void 0===n&&(n=new URL("hakuban_bg.wasm",import.meta.url));const e=V();("string"==typeof n||"function"==typeof Request&&n instanceof Request||"function"==typeof URL&&n instanceof URL)&&(n=fetch(n));const{instance:r,module:i}=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,X.__wbindgen_wasm_module=e,S=new BigInt64Array,A=new BigUint64Array,h=new Int32Array,b=new Uint32Array,a=new Uint8Array,t}(r,i)}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=l(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=o;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 i,o;super(),null!=r?(this.json=JSON.parse(function(n){try{const i=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_descriptor_json(i,n);var e=u()[i/4+0],r=u()[i/4+1];return w(e,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(e,r)}}(r)),this.tags=function(){var n,e,i,a;for(a=[],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=u()[o/4+0],r=u()[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++)o=i[n],a.push(new ct(null,null,o));return a}()):(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 ct?i:new ct(i));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++)i=e[t],r.push(i._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=l(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=o,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=u()[o/4+0],r=u()[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=u()[o/4+0],r=u()[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=u()[o/4+0],r=u()[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=u()[o/4+0],r=u()[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=l(n,t.__wbindgen_malloc,t.__wbindgen_realloc),r=o,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=o;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;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};
2
2
  //# sourceMappingURL=hakuban.min.js.map