hakuban 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hakuban-with-wasm.js +176 -101
- package/hakuban-with-wasm.js.map +1 -1
- package/hakuban-with-wasm.min.js +1 -1
- package/hakuban-with-wasm.min.js.map +1 -1
- package/hakuban.js +176 -101
- package/hakuban.js.map +1 -1
- package/hakuban.min.js +1 -1
- package/hakuban.min.js.map +1 -1
- package/package.json +2 -2
package/hakuban.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let t;const e=new Array(32).fill(void 0);function n(t){return e[t]}e.push(void 0,null,!0,!1);let r=e.length;function s(t){const s=n(t);return function(t){t<36||(e[t]=r,r=t)}(t),s}let i=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});i.decode();let o=null;function _(){return null!==o&&o.buffer===t.memory.buffer||(o=new Uint8Array(t.memory.buffer)),o}function a(t,e){return i.decode(_().subarray(t,t+e))}function c(t){r===e.length&&e.push(e.length+1);const n=r;return r=e[n],e[n]=t,n}function h(t){const e=typeof t;if("number"==e||"boolean"==e||null==t)return`${t}`;if("string"==e)return`"${t}"`;if("symbol"==e){const e=t.description;return null==e?"Symbol":`Symbol(${e})`}if("function"==e){const e=t.name;return"string"==typeof e&&e.length>0?`Function(${e})`:"Function"}if(Array.isArray(t)){const e=t.length;let n="[";e>0&&(n+=h(t[0]));for(let r=1;r<e;r++)n+=", "+h(t[r]);return n+="]",n}const n=/\[object ([^\]]+)\]/.exec(toString.call(t));let r;if(!(n.length>1))return toString.call(t);if(r=n[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}let l=0,u=new TextEncoder("utf-8");const d="function"==typeof u.encodeInto?function(t,e){return u.encodeInto(t,e)}:function(t,e){const n=u.encode(t);return e.set(n),{read:t.length,written:n.length}};function b(t,e,n){if(void 0===n){const n=u.encode(t),r=e(n.length);return _().subarray(r,r+n.length).set(n),l=n.length,r}let r=t.length,s=e(r);const i=_();let o=0;for(;o<r;o++){const e=t.charCodeAt(o);if(e>127)break;i[s+o]=e}if(o!==r){0!==o&&(t=t.slice(o)),s=n(s,r,r=o+3*t.length);const e=_().subarray(s+o,s+r);o+=d(t,e).written}return l=o,s}let g=null;function p(){return null!==g&&g.buffer===t.memory.buffer||(g=new Int32Array(t.memory.buffer)),g}function w(e,n,r){t._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2cb5c9e37b253332(e,n,c(r))}const f=new Uint32Array(2),v=new BigUint64Array(f.buffer);function m(e){var n=b(e,t.__wbindgen_malloc,t.__wbindgen_realloc),r=l,s=t.hakuban_json_hash(n,r);return H.__wrap(s)}function y(e){t.hakuban_local_node_drop(e)}function j(e){t.hakuban_object_observe_drop(e)}function k(e){t.hakuban_object_observe_state_return(e)}function x(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_synchronized(s,e);var n=p()[s/4+0],r=p()[s/4+1];f[0]=n,f[1]=r;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}function z(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data_version(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}function O(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data_type(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}function S(t,e){return _().subarray(t/1,t/1+e)}function N(e){try{const i=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data(i,e);var n=p()[i/4+0],r=p()[i/4+1],s=S(n,r).slice();return t.__wbindgen_free(n,1*r),s}finally{t.__wbindgen_add_to_stack_pointer(16)}}function J(e){t.hakuban_object_descriptor_events_drop(e)}function I(e){t.hakuban_tag_observe_drop(e)}function T(t){return null==t}function R(e){t.hakuban_remote_node_drop(e)}function A(t,e){const n=e(1*t.length);return _().set(t,n/1),l=t.length,n}function F(e,n){try{const h=t.__wbindgen_add_to_stack_pointer(-16);var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;t.hakuban_remote_node_received_local_node_event(h,e,r,i);var o=p()[h/4+0],_=p()[h/4+1],a=p()[h/4+2];if(p()[h/4+3])throw s(a);var c=S(o,_).slice();return t.__wbindgen_free(o,1*_),c}finally{t.__wbindgen_add_to_stack_pointer(16)}}function q(e){t.hakuban_tag_expose_drop(e)}function P(e){t.hakuban_object_expose_drop(e)}function U(e,n){try{return e.apply(this,n)}catch(e){t.__wbindgen_exn_store(c(e))}}Object.freeze({None:0,0:"None",InvalidString:1,1:"InvalidString",InvalidJSON:2,2:"InvalidJSON",InvalidURL:3,3:"InvalidURL",ObjectNotFound:4,4:"ObjectNotFound"});class H{static __wrap(t){const e=Object.create(H.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmhashresult_free(e)}get error(){return t.__wbg_get_wasmhashresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmhashresult_error(this.ptr,e)}get hash(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.__wbg_get_wasmhashresult_hash(r,this.ptr);var e=p()[r/4+0],n=p()[r/4+1];f[0]=e,f[1]=n;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}set hash(e){v[0]=e;const n=f[0],r=f[1];t.__wbg_set_wasmhashresult_hash(this.ptr,n,r)}}class W{static __wrap(t){const e=Object.create(W.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmlocalnodenewresult_free(e)}get error(){return t.__wbg_get_wasmlocalnodenewresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmlocalnodenewresult_error(this.ptr,e)}get local_node_pointer(){return t.__wbg_get_wasmlocalnodenewresult_local_node_pointer(this.ptr)}set local_node_pointer(e){t.__wbg_set_wasmlocalnodenewresult_local_node_pointer(this.ptr,e)}}class B{static __wrap(t){const e=Object.create(B.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectexposeresult_free(e)}get error(){return t.__wbg_get_wasmobjectexposeresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectexposeresult_error(this.ptr,e)}get object_expose_pointer(){return t.__wbg_get_wasmobjectexposeresult_object_expose_pointer(this.ptr)}set object_expose_pointer(e){t.__wbg_set_wasmobjectexposeresult_object_expose_pointer(this.ptr,e)}}class D{static __wrap(t){const e=Object.create(D.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectexposestateresult_free(e)}get error(){return t.__wbg_get_wasmobjectexposestateresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectexposestateresult_error(this.ptr,e)}get changed(){return 0!==t.__wbg_get_wasmobjectexposestateresult_changed(this.ptr)}set changed(e){t.__wbg_set_wasmobjectexposestateresult_changed(this.ptr,e)}}class E{static __wrap(t){const e=Object.create(E.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectobserveresult_free(e)}get error(){return t.__wbg_get_wasmobjectobserveresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectobserveresult_error(this.ptr,e)}get object_observe_pointer(){return t.__wbg_get_wasmobjectobserveresult_object_observe_pointer(this.ptr)}set object_observe_pointer(e){t.__wbg_set_wasmobjectobserveresult_object_observe_pointer(this.ptr,e)}}class M{static __wrap(t){const e=Object.create(M.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmremotenodenewresult_free(e)}get error(){return t.__wbg_get_wasmremotenodenewresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmremotenodenewresult_error(this.ptr,e)}get remote_node_pointer(){return t.__wbg_get_wasmremotenodenewresult_remote_node_pointer(this.ptr)}set remote_node_pointer(e){t.__wbg_set_wasmremotenodenewresult_remote_node_pointer(this.ptr,e)}}class ${static __wrap(t){const e=Object.create($.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposeassignmentresult_free(e)}get error(){return t.__wbg_get_wasmtagexposeassignmentresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposeassignmentresult_error(this.ptr,e)}get assignment(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.__wbg_get_wasmtagexposeassignmentresult_assignment(r,this.ptr);var e=p()[r/4+0],n=p()[r/4+1];f[0]=e,f[1]=n;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}set assignment(e){v[0]=e;const n=f[0],r=f[1];t.__wbg_set_wasmtagexposeassignmentresult_assignment(this.ptr,n,r)}}class C{static __wrap(t){const e=Object.create(C.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposeresult_free(e)}get error(){return t.__wbg_get_wasmtagexposeresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposeresult_error(this.ptr,e)}get tag_expose_pointer(){return t.__wbg_get_wasmtagexposeresult_tag_expose_pointer(this.ptr)}set tag_expose_pointer(e){t.__wbg_set_wasmtagexposeresult_tag_expose_pointer(this.ptr,e)}}class L{static __wrap(t){const e=Object.create(L.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposesetobjectstateresult_free(e)}get error(){return t.__wbg_get_wasmtagexposesetobjectstateresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposesetobjectstateresult_error(this.ptr,e)}get changed(){return 0!==t.__wbg_get_wasmtagexposesetobjectstateresult_changed(this.ptr)}set changed(e){t.__wbg_set_wasmtagexposesetobjectstateresult_changed(this.ptr,e)}}class Q{static __wrap(t){const e=Object.create(Q.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagobserveobjectstateborrowresult_free(e)}get error(){return t.__wbg_get_wasmtagobserveobjectstateborrowresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagobserveobjectstateborrowresult_error(this.ptr,e)}get state_pointer(){return t.__wbg_get_wasmtagobserveobjectstateborrowresult_state_pointer(this.ptr)}set state_pointer(e){t.__wbg_set_wasmtagobserveobjectstateborrowresult_state_pointer(this.ptr,e)}}class G{static __wrap(t){const e=Object.create(G.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagobserveresult_free(e)}get error(){return t.__wbg_get_wasmtagobserveresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagobserveresult_error(this.ptr,e)}get tag_observe_pointer(){return t.__wbg_get_wasmtagobserveresult_tag_observe_pointer(this.ptr)}set tag_observe_pointer(e){t.__wbg_set_wasmtagobserveresult_tag_observe_pointer(this.ptr,e)}}async function K(e){void 0===e&&(e=new URL("hakuban_bg.wasm",import.meta.url));const r={wbg:{}};r.wbg.__wbindgen_object_drop_ref=function(t){s(t)},r.wbg.__wbindgen_string_new=function(t,e){return c(a(t,e))},r.wbg.__wbindgen_cb_drop=function(t){const e=s(t).original;if(1==e.cnt--)return e.a=0,!0;return!1},r.wbg.__wbg_debug_6e114a5b27d7915d=function(t){console.debug(n(t))},r.wbg.__wbg_error_ca520cb687b085a1=function(t){console.error(n(t))},r.wbg.__wbg_info_32ab782ec7072fac=function(t){console.info(n(t))},r.wbg.__wbg_log_fbd13631356d44e4=function(t){console.log(n(t))},r.wbg.__wbg_warn_97f10a6b0dbb8c5c=function(t){console.warn(n(t))},r.wbg.__wbg_now_5fa0ca001e042f8a=function(t){return n(t).now()},r.wbg.__wbg_newnoargs_f579424187aa1717=function(t,e){return c(new Function(a(t,e)))},r.wbg.__wbg_get_8bbb82393651dd9c=function(){return U((function(t,e){return c(Reflect.get(n(t),n(e)))}),arguments)},r.wbg.__wbg_call_89558c3e96703ca1=function(){return U((function(t,e){return c(n(t).call(n(e)))}),arguments)},r.wbg.__wbg_call_94697a95cb7e239c=function(){return U((function(t,e,r){return c(n(t).call(n(e),n(r)))}),arguments)},r.wbg.__wbg_new_4beacc9c71572250=function(e,n){try{var r={a:e,b:n},s=new Promise(((e,n)=>{const s=r.a;r.a=0;try{return function(e,n,r,s){t.wasm_bindgen__convert__closures__invoke2_mut__h3fbc4a767cc461bf(e,n,c(r),c(s))}(s,r.b,e,n)}finally{r.a=s}}));return c(s)}finally{r.a=r.b=0}},r.wbg.__wbg_resolve_4f8f547f26b30b27=function(t){return c(Promise.resolve(n(t)))},r.wbg.__wbg_then_a6860c82b90816ca=function(t,e){return c(n(t).then(n(e)))},r.wbg.__wbg_then_58a04e42527f52c6=function(t,e,r){return c(n(t).then(n(e),n(r)))},r.wbg.__wbg_self_e23d74ae45fb17d1=function(){return U((function(){return c(self.self)}),arguments)},r.wbg.__wbg_window_b4be7f48b24ac56e=function(){return U((function(){return c(window.window)}),arguments)},r.wbg.__wbg_globalThis_d61b1f48a57191ae=function(){return U((function(){return c(globalThis.globalThis)}),arguments)},r.wbg.__wbg_global_e7669da72fd7f239=function(){return U((function(){return c(global.global)}),arguments)},r.wbg.__wbindgen_is_undefined=function(t){return void 0===n(t)},r.wbg.__wbindgen_object_clone_ref=function(t){return c(n(t))},r.wbg.__wbg_new_693216e109162396=function(){return c(new Error)},r.wbg.__wbg_stack_0ddaca5d1abfb52f=function(e,r){var s=b(n(r).stack,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;p()[e/4+1]=i,p()[e/4+0]=s},r.wbg.__wbg_error_09919627ac0992f5=function(e,n){try{console.error(a(e,n))}finally{t.__wbindgen_free(e,n)}},r.wbg.__wbindgen_debug_string=function(e,r){var s=b(h(n(r)),t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;p()[e/4+1]=i,p()[e/4+0]=s},r.wbg.__wbindgen_throw=function(t,e){throw new Error(a(t,e))},r.wbg.__wbindgen_closure_wrapper2024=function(e,n,r){var s=function(e,n,r,s){const i={a:e,b:n,cnt:1,dtor:r},o=(...e)=>{i.cnt++;const n=i.a;i.a=0;try{return s(n,i.b,...e)}finally{0==--i.cnt?t.__wbindgen_export_2.get(i.dtor)(n,i.b):i.a=n}};return o.original=i,o}(e,n,490,w);return c(s)},("string"==typeof e||"function"==typeof Request&&e instanceof Request||"function"==typeof URL&&e instanceof URL)&&(e=fetch(e));const{instance:i,module:o}=await async function(t,e){if("function"==typeof Response&&t instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(t,e)}catch(e){if("application/wasm"==t.headers.get("Content-Type"))throw e;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",e)}const n=await t.arrayBuffer();return await WebAssembly.instantiate(n,e)}{const n=await WebAssembly.instantiate(t,e);return n instanceof WebAssembly.Instance?{instance:n,module:t}:n}}(await e,r);return t=i.exports,K.__wbindgen_wasm_module=o,t}var V;V=class{constructor(){this.queue=[],this.wake=null}push(t){if(this.queue.push(t),null!=this.wake)return this.wake(),this.wake=null}async shift(){for(var t;;){if(null!=(t=this.queue.shift()))return t;if(null!=this.wake)throw"2 concurrent shifts on a single queue";await new Promise((t=>(this.wake=t,null)))}}clear(){return this.queue=[]}};var X,Y,Z,tt,et,nt,rt,st,it,ot,_t,at,ct,ht,lt,ut,dt=class{constructor(t,e,n){var r;this.objects=this.objects.bind(this),this.object=this.object.bind(this),this.drop=this.drop.bind(this),this.contract=t,this.object_class=e,this.block=n,this._objects={},this.running_handlers={},this.event_queue=new V,r=new Promise((t=>(this.event_loop_stop=t,null))),this.event_loop_stopped=new Promise((async(t,e)=>{var n,s;for(s=this.contract.events();(n=await Promise.race([s.next(),r]))&&null!=n;)this.event_queue.push(n);return s.drop(),t()})),this.async_loop_stopped=new Promise((async(t,e)=>{for(var n,r,s,i,o;null!=(r=await this.event_queue.shift());)switch(r.action){case"Insert":if(null!=this._objects[r.descriptor.hash()])throw"Double insert";this._objects[r.descriptor.hash()]=new this.object_class(this.contract,r.descriptor),null!=this.block&&this.event_queue.push({action:"HandlerStart",descriptor:r.descriptor});break;case"Change":if(null==this._objects[r.descriptor.hash()])throw"Uh, oh, object missing :(";this._objects[r.descriptor.hash()].do_change("change");break;case"Remove":if(null==this._objects[r.descriptor.hash()])throw"Trying to remove non-existing object. Sad.";this._objects[r.descriptor.hash()].do_change("remove"),delete this._objects[r.descriptor.hash()];break;case"HandlerStart":null==(i=this._objects[r.descriptor.hash()])||i.handler_already_run||null!=this.running_handlers[r.descriptor.hash()]||(this.running_handlers[r.descriptor.hash()]=function(t,e,n,r){return new Promise((async function(s,i){return await e.run(n),r.push({action:"HandlerFinished",descriptor:t}),s()}))}(r.descriptor,i,this.block,this.event_queue));break;case"HandlerFinished":if(null==this.running_handlers[r.descriptor.hash()])throw"Handler finished but it was not running. That sucks.";delete this.running_handlers[r.descriptor.hash()],null!=this._objects[r.descriptor.hash()]&&this.event_queue.push({action:"HandlerStart",descriptor:r.descriptor});break;case"Drop":for(n in this.event_loop_stop(),await this.event_loop_stopped,o=this._objects)(i=o[n]).do_change("remove");for(;Object.keys(this.running_handlers).length>0;)"HandlerFinished"===(r=await this.event_queue.shift()).action&&delete this.running_handlers[r.descriptor.hash()];for(s in this.event_queue.clear(),this._objects)delete this._objects[s];return this.contract.drop(),this.contract=null,this.event_queue=null,void t();default:throw"Unknown action: "+r.action}return e("Queue died unexpectedly")}))}objects(){return Object.values(this._objects)}object(){return Object.values(this._objects)[0]}async drop(){if(this.contract)return this.event_queue.push({action:"Drop"}),await this.async_loop_stopped}},bt=class{constructor(t,e){this.run=this.run.bind(this),this.next_event=this.next_event.bind(this),this.next_change=this.next_change.bind(this),this.do_change=this.do_change.bind(this),this.contract=t,this.descriptor=e,this._changes=new V,this.handler_already_run=!1}async run(t){return this.handler_already_run=!0,await t(this)}next_event(){return this.next_change()}async next_change(){for(;;)switch(await this._changes.shift()){case"change":return!0;case"remove":return!1}}do_change(t){return this._changes.push(t)}},gt=function(t,e){if(!(t instanceof e))throw new Error("Bound instance method accessed before binding")};lt=!1;var pt=async function(t){return await K(t)},wt=async function(e,n=!1){var r,s,i,o;return!(!lt||!n)||(0===(r=await(s=e,i=b(s,t.__wbindgen_malloc,t.__wbindgen_realloc),o=l,t.hakuban_logger_initialize(i,o)))?lt=!0:(console.error("Failed to initialize logger, error "+r),!1))};ut=function(t){if(0!==t)throw"Hakuban error: "+t};var ft=function(t,e){return{data_type:["JSON"].concat(t),data:(new TextEncoder).encode(JSON.stringify(e))}},vt=function(t,e){if(0===t.length||"JSON"!==t[0])throw"Expected JSON data_type, got: "+t;return{data_type:t.slice(1),data:JSON.parse((new TextDecoder).decode(e))}},mt=class{constructor(t,e){var n;this.json=e,this.tags=function(){var e,r,s;for(s=[],e=0,r=t.length;e<r;e++)n=t[e],s.push(n instanceof yt?n:new yt(n));return s}()}as_json(){return JSON.stringify({tags:this.tags.map((function(t){return t.json})),json:this.json})}hash(){var t;return null==this._hash&&(this._hash=this.tags.map((function(t){return t.hash().toString()})).sort().join(",")+"|",t=m(JSON.stringify(this.json)),ut(t.error),this._hash+=t.hash.toString()),this._hash}},yt=class{constructor(t){this.json=t}as_json(){return JSON.stringify(this.json)}hash(){var t;return null==this._hash&&(t=m(JSON.stringify(this.json)),ut(t.error),this._hash=t.hash),this._hash}};X=new FinalizationRegistry((t=>y(t)));var jt=class{constructor(e="wasm"){var n,r,s,i,o;this.name=e,wt("warn",!0),r=this.name,s=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l,o=t.hakuban_local_node_new(s,i),n=W.__wrap(o),ut(n.error),this.pointer=n.local_node_pointer,X.register(this,this.pointer,this),this.with_default_serializer(ft),this.with_default_deserializer(vt)}destroy(){return y(this.pointer),X.unregister(this)}object(t,e){return new Y(this,this.default_serializer,this.default_deserializer,t,e)}tag(t){return new it(this,this.default_serializer,this.default_deserializer,t)}with_default_serializer(t){return this.default_serializer=t,this}with_default_deserializer(t){return this.default_deserializer=t,this}};Y=class{constructor(t,e,n,r,s){this.local_node=t,this.serializer=e,this.deserializer=n,this.tags=r,this.json=s}observe(){return new rt(this.local_node,new mt(this.tags,this.json),this.deserializer)}expose(){return new et(this.local_node,new mt(this.tags,this.json),this.serializer)}with_serializer(t){return this.serializer=t,this}with_deserializer(t){return this.deserializer=t,this}},it=class{constructor(t,e,n,r){this.local_node=t,this.serializer=e,this.deserializer=n,this.json=r}observe(){return new at(this.local_node,new yt(this.json),this.deserializer)}expose(){return new ot(this.local_node,new yt(this.json),this.serializer)}with_serializer(t){return this.serializer=t,this}with_deserializer(t){return this.deserializer=t,this}},tt=new FinalizationRegistry((t=>J(t))),Z=class{constructor(t){this.wait=this.wait.bind(this),this.next=this.next.bind(this),this.drop=this.drop.bind(this),this.pointer=t,tt.register(this,this.pointer,this)}wait(){return next()}next(){var e,n,r,i;return this.wait_released=new Promise((t=>(this.wait_release=t,null))),e=new Promise((t=>this.cancel_waiting_resolve=t)),r=this.pointer,i=e,(n=s(t.hakuban_object_descriptor_events_next(r,c(i)))).cancel=async t=>(this.cancel_waiting_resolve.resolve(t),await n),n.then((t=>{var e;return this.wait_release(),this.wait_released=null,this.cancel_waiting_resolve=null,{action:(e=JSON.parse(t)).action,descriptor:new mt(e.key.tags,e.key.json)}}))}async drop(){return null!=this.cancel_waiting_resolve&&(this.cancel_waiting_resolve(),await this.wait_released),tt.unregister(this),J(this.pointer),this.pointer=null}},st=new FinalizationRegistry((t=>j(t))),rt=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_state=this.object_state.bind(this),this.events=this.events.bind(this),this.async=this.async.bind(this),this.local_node=e,this.descriptor=n,this.deserializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_object_observe_new(e,r,s);return E.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.object_observe_pointer,st.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,j(this.pointer),st.unregister(this),this.pointer=null}object_state(){var e,n,r,s,i,o,_;return null==this.pointer?null:(_=this.pointer,0===(s=t.hakuban_object_observe_state_borrow(_))?null:(i=x(s),o=JSON.parse(z(s)),e=JSON.parse(O(s)),r=N(s),k(s),{version:o,data:(n=this.deserializer(e,r)).data,data_type:n.data_type,synchronized:i}))}events(){return new Z((e=this.pointer,t.hakuban_object_observe_events_get(e)));var e}async(t){return new dt(this,class extends bt{state(){var t;return null!=(t=this.contract)?t.object_state():void 0}data(){var t,e;return null!=(t=this.contract)&&null!=(e=t.object_state())?e.data:void 0}},t)}},nt=new FinalizationRegistry((t=>P(t))),et=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.set_object_state=this.set_object_state.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.desynchronize=this.desynchronize.bind(this),this.events=this.events.bind(this),this.async=this.async.bind(this),this.local_node=e,this.descriptor=n,this.serializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_object_expose_new(e,r,s);return B.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.object_expose_pointer,nt.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,P(this.pointer),nt.unregister(this)}set_object_state(e,n,r=[],s=0){var i,o;return o=this.serializer(r,n),"bigint"!=typeof s&&(s=BigInt(s)),i=function(e,n,r,s,i){var o=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),_=l,a=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),c=l,h=A(s,t.__wbindgen_malloc),u=l;v[0]=i;const d=f[0],g=f[1];var p=t.hakuban_object_expose_set_state(e,o,_,a,c,h,u,d,g);return D.__wrap(p)}(this.pointer,JSON.stringify(e),JSON.stringify(o.data_type),o.data,s),ut(i.error),i.changed}assignment(){return function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_expose_assignment(s,e);var n=p()[s/4+0],r=p()[s/4+1];return f[0]=n,f[1]=r,v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.pointer)}assigned(){return this.assignment()>0}desynchronize(e){return"bigint"!=typeof e&&(e=BigInt(e)),function(e,n){v[0]=n;const r=f[0],s=f[1];t.hakuban_object_expose_desynchronize(e,r,s)}(this.pointer,e)}events(){return new Z((e=this.pointer,t.hakuban_object_expose_events_get(e)));var e}async(t){return new dt(this,class t extends bt{constructor(t,e){super(t,e),this.run=this.run.bind(this),this.do_change=this.do_change.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.set_state=this.set_state.bind(this),this.set_data=this.set_data.bind(this),this._assignment=t.assignment()}async run(e){var n;return gt(this,t),await super.run(e),null!=(n=this.contract)?n.desynchronize(this._assignment):void 0}do_change(e){var n;return gt(this,t),this._assignment=null!=(n=this.contract)?n.assignment():void 0,super.do_change(e)}assignment(){var e;return gt(this,t),null!=(e=this.contract)?e.assignment():void 0}assigned(){var e;return gt(this,t),null!=(e=this.contract)?e.assigned():void 0}set_state(e,n,r=[]){var s;return gt(this,t),null!=(s=this.contract)?s.set_object_state(e,n,r,this._assignment):void 0}set_data(e){var n;return gt(this,t),n=(new Date).getTime(),this.set_state([1,Math.floor(n/1e3),n-1e3*Math.floor(n/1e3),0],e)}},t)}},ct=new FinalizationRegistry((t=>I(t))),at=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_descriptors=this.object_descriptors.bind(this),this.object_state=this.object_state.bind(this),this.async=this.async.bind(this),this.local_node=e,this.descriptor=n,this.deserializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_observe_new(e,r,s);return G.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.tag_observe_pointer,ct.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,I(this.pointer),ct.unregister(this)}object_descriptors(){var e,n,r,s,i,o;for(i=function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_observe_object_descriptors(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}(this.pointer),o=[],n=0,r=(s=JSON.parse(i)).length;n<r;n++)e=s[n],o.push(new mt(e.tags,e.json));return o}object_state(e){var n,r,s,i,o,_;return 4===(i=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_observe_object_state_borrow(e,r,s);return Q.__wrap(i)}(this.pointer,e.as_json())).error||0===i.state_pointer?null:(o=x(i.state_pointer),_=JSON.parse(z(i.state_pointer)),n=JSON.parse(O(i.state_pointer)),s=N(i.state_pointer),k(i.state_pointer),{version:_,data:(r=this.deserializer(n,s)).data,data_type:r.data_type,synchronized:o})}events(){return new Z((e=this.pointer,t.hakuban_tag_observe_events_get(e)));var e}async(t){return new dt(this,class extends bt{state(){var t;return null!=(t=this.contract)?t.object_state(this.descriptor):void 0}data(){var t,e;return null!=(t=this.contract)&&null!=(e=t.object_state(this.descriptor))?e.data:void 0}},t)}},_t=new FinalizationRegistry((t=>q(t))),ot=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_descriptors=this.object_descriptors.bind(this),this.set_object_state=this.set_object_state.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.desynchronize=this.desynchronize.bind(this),this.events=this.events.bind(this),this.async=this.async.bind(this),this.local_node=e,this.descriptor=n,this.serializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_expose_new(e,r,s);return C.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.tag_expose_pointer,_t.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,q(this.pointer),_t.unregister(this)}object_descriptors(){var e,n,r,s,i,o;for(i=function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_expose_object_descriptors(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}(this.pointer),o=[],n=0,r=(s=JSON.parse(i)).length;n<r;n++)e=s[n],o.push(new mt(e.tags,e.json));return o}set_object_state(e,n,r,s=[],i=0){var o,_;return _=this.serializer(s,r),"bigint"!=typeof i&&(i=BigInt(i)),o=function(e,n,r,s,i,o){var _=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),a=l,c=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),h=l,u=b(s,t.__wbindgen_malloc,t.__wbindgen_realloc),d=l,g=A(i,t.__wbindgen_malloc),p=l;v[0]=o;const w=f[0],m=f[1];var y=t.hakuban_tag_expose_set_object_state(e,_,a,c,h,u,d,g,p,w,m);return L.__wrap(y)}(this.pointer,e.as_json(),JSON.stringify(n),JSON.stringify(_.data_type),_.data,i),ut(o.error),o.changed}assignment(e){var n;return n=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_expose_assignment(e,r,s);return $.__wrap(i)}(this.pointer,e.as_json()),ut(n.error),n.assignment}assigned(t){return this.assignment(t)>0}desynchronize(e,n){var r;return"bigint"!=typeof n&&(n=BigInt(n)),r=function(e,n,r){var s=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;v[0]=r;const o=f[0],_=f[1];return t.hakuban_tag_expose_desynchronize(e,s,i,o,_)>>>0}(this.pointer,e.as_json(),n),ut(r)}events(){return new Z((e=this.pointer,t.hakuban_tag_expose_events_get(e)));var e}async(t){return new dt(this,class t extends bt{constructor(t,e){super(t,e),this.run=this.run.bind(this),this.do_change=this.do_change.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.set_state=this.set_state.bind(this),this.set_data=this.set_data.bind(this),this._assignment=t.assignment(this.descriptor)}async run(e){var n;return gt(this,t),await super.run(e),null!=(n=this.contract)?n.desynchronize(this.descriptor,this._assignment):void 0}do_change(e){var n;return gt(this,t),this._assignment=null!=(n=this.contract)?n.assignment(this.descriptor):void 0,super.do_change(e)}assignment(){var e;return gt(this,t),null!=(e=this.contract)?e.assignment(this.descriptor):void 0}assigned(){var e;return gt(this,t),null!=(e=this.contract)?e.assigned(this.descriptor):void 0}set_state(e,n,r=[]){var s;return gt(this,t),null!=(s=this.contract)?s.set_object_state(this.descriptor,e,n,r,this._assignment):void 0}set_data(e){var n;return gt(this,t),n=(new Date).getTime(),this.set_state([1,Math.floor(n/1e3),n-1e3*Math.floor(n/1e3),0],e)}},t)}},ht=new FinalizationRegistry((t=>R(t)));var kt=class{constructor(e,n,r={}){var s,i,o,_,a,c;this.connect=this.connect.bind(this),this.ping=this.ping.bind(this),this.send=this.send.bind(this),this.ack=this.ack.bind(this),this.local_node=e,this.uri=n,this.options=r,this.connected=!1,this.socket=void 0,this.error=void 0,this.reconnection_timer=void 0,this.reconnect_on_close=!0,this.ack_timer=void 0,i=this.local_node.pointer,o=!0,_=!0,a=!0,c=t.hakuban_remote_node_new(i,o,T(_)?16777215:_?1:0,T(a)?16777215:a?1:0),s=M.__wrap(c),ut(s.error),this.remote_node_pointer=s.remote_node_pointer,this.event_loop_stop=new Promise((t=>this.event_loop_stop_resolve=t)),this.event_loop_promise=this.event_loop(),ht.register(this,this.remote_node_pointer,this),this.connect()}async destroy(){return this.event_loop_stop_resolve(["stop"]),await this.event_loop_promise,this.reconnect_on_close=!1,this.keep_alive_interval&&clearInterval(this.keep_alive_interval),null!=this.reconnection_timer&&(clearTimeout(this.reconnection_timer),this.reconnection_timer=null),null!=this.socket&&(this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null,this.socket.close(),this.socket_onclose()),null!=this.ack_timer&&(clearTimeout(this.ack_timer),this.ack_timer=null),R(this.remote_node_pointer),ht.unregister(this)}connect(){var e;this.reconnection_timer=void 0;try{this.socket=new WebSocket(this.uri)}catch(t){return e=t,this.error={while:"connecting",error:e},null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),!1}return this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{var e;return this.options.debug&&console.debug("Connected to hakuban remote node"),this.connected=!0,this.error=void 0,null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),e=function(e){try{const _=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_remote_node_connected(_,e);var n=p()[_/4+0],r=p()[_/4+1],i=p()[_/4+2];if(p()[_/4+3])throw s(i);var o=S(n,r).slice();return t.__wbindgen_free(n,1*r),o}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer),this.send(e)},this.socket.onclose=this.socket_onclose=()=>{var e;if(this.options.debug&&console.debug("Disconnected from hakuban remote node"),this.keep_alive_interval&&clearInterval(this.keep_alive_interval),this.connected=!1,this.socket=void 0,e=this.remote_node_pointer,t.hakuban_remote_node_disconnected(e),null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),null!=this.reconnection_timer&&clearTimeout(this.reconnection_timer),this.reconnection_timer=null,this.reconnect_on_close)return this.reconnection_timer=setTimeout(this.connect,1e3)},this.socket.onerror=t=>(this.options.debug&&console.debug("Hakuban socket error",t),this.error={while:"connected",error:t}),this.socket.onmessage=e=>{var n;return n=function(e,n){try{const h=t.__wbindgen_add_to_stack_pointer(-16);var r=A(n,t.__wbindgen_malloc),i=l;t.hakuban_remote_node_received_message(h,e,r,i);var o=p()[h/4+0],_=p()[h/4+1],a=p()[h/4+2];if(p()[h/4+3])throw s(a);var c=S(o,_).slice();return t.__wbindgen_free(o,1*_),c}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer,new Uint8Array(e.data)),this.send(n),null!=this.ack_timer&&clearTimeout(this.ack_timer),this.ack_timer=setTimeout(this.ack,1e3),null}}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)}ack(){var e;if(null!=this.socket&&(e=function(e){try{const i=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_remote_node_ack(i,e);var n=p()[i/4+0],r=p()[i/4+1],s=S(n,r).slice();return t.__wbindgen_free(n,1*r),s}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer)).length>0)return this.send(e)}async event_loop(){var e,n,r,i,o,_,a;for(i=!1,n=null,e=new Promise((function(t){return n=t}));i||(i=(_=this.remote_node_pointer,a=e,s(t.hakuban_remote_node_next_local_node_event(_,c(a)))).then((function(t){return["local_node_event",t]}))),[o,r]=await Promise.any([this.event_loop_stop,i]),"local_node_event"===o;)i=!1,setTimeout((t=>{var e;if(this.connected)return e=F(this.remote_node_pointer,t),this.send(e)}),0,r);if(i)return n(!0),await i}onstatuschange(t){return this.onstatuschange_proc=t,null!=this.onstatuschange_proc&&this.onstatuschange_proc(),this}},xt=async function(t){return await pt(t)};export{vt as JSON_deserialize,ft as JSON_serialize,jt as LocalNode,mt as ObjectDescriptor,yt as TagDescriptor,kt as WebsocketConnector,xt as initialize,pt as initialize_wasm,wt as logger_initialize};
|
|
1
|
+
let t;const e=new Array(32).fill(void 0);function n(t){return e[t]}e.push(void 0,null,!0,!1);let r=e.length;function s(t){const s=n(t);return function(t){t<36||(e[t]=r,r=t)}(t),s}let i=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});i.decode();let o=null;function _(){return null!==o&&o.buffer===t.memory.buffer||(o=new Uint8Array(t.memory.buffer)),o}function a(t,e){return i.decode(_().subarray(t,t+e))}function c(t){r===e.length&&e.push(e.length+1);const n=r;return r=e[n],e[n]=t,n}function h(t){const e=typeof t;if("number"==e||"boolean"==e||null==t)return`${t}`;if("string"==e)return`"${t}"`;if("symbol"==e){const e=t.description;return null==e?"Symbol":`Symbol(${e})`}if("function"==e){const e=t.name;return"string"==typeof e&&e.length>0?`Function(${e})`:"Function"}if(Array.isArray(t)){const e=t.length;let n="[";e>0&&(n+=h(t[0]));for(let r=1;r<e;r++)n+=", "+h(t[r]);return n+="]",n}const n=/\[object ([^\]]+)\]/.exec(toString.call(t));let r;if(!(n.length>1))return toString.call(t);if(r=n[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}let l=0,u=new TextEncoder("utf-8");const d="function"==typeof u.encodeInto?function(t,e){return u.encodeInto(t,e)}:function(t,e){const n=u.encode(t);return e.set(n),{read:t.length,written:n.length}};function b(t,e,n){if(void 0===n){const n=u.encode(t),r=e(n.length);return _().subarray(r,r+n.length).set(n),l=n.length,r}let r=t.length,s=e(r);const i=_();let o=0;for(;o<r;o++){const e=t.charCodeAt(o);if(e>127)break;i[s+o]=e}if(o!==r){0!==o&&(t=t.slice(o)),s=n(s,r,r=o+3*t.length);const e=_().subarray(s+o,s+r);o+=d(t,e).written}return l=o,s}let g=null;function p(){return null!==g&&g.buffer===t.memory.buffer||(g=new Int32Array(t.memory.buffer)),g}function w(e,n,r){t._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2cb5c9e37b253332(e,n,c(r))}const f=new Uint32Array(2),v=new BigUint64Array(f.buffer);function m(e){var n=b(e,t.__wbindgen_malloc,t.__wbindgen_realloc),r=l,s=t.hakuban_json_hash(n,r);return U.__wrap(s)}function y(e){t.hakuban_local_node_drop(e)}function j(e){t.hakuban_object_observe_drop(e)}function k(e){t.hakuban_object_observe_state_return(e)}function x(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_synchronized(s,e);var n=p()[s/4+0],r=p()[s/4+1];f[0]=n,f[1]=r;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}function z(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data_version(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}function O(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data_type(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}function S(t,e){return _().subarray(t/1,t/1+e)}function N(e){try{const i=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_observe_state_data(i,e);var n=p()[i/4+0],r=p()[i/4+1],s=S(n,r).slice();return t.__wbindgen_free(n,1*r),s}finally{t.__wbindgen_add_to_stack_pointer(16)}}function J(e){t.hakuban_object_descriptor_events_drop(e)}function T(e){t.hakuban_tag_observe_drop(e)}function I(t){return null==t}function R(e){t.hakuban_remote_node_drop(e)}function A(t,e){const n=e(1*t.length);return _().set(t,n/1),l=t.length,n}function q(e,n){try{const h=t.__wbindgen_add_to_stack_pointer(-16);var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;t.hakuban_remote_node_received_local_node_event(h,e,r,i);var o=p()[h/4+0],_=p()[h/4+1],a=p()[h/4+2];if(p()[h/4+3])throw s(a);var c=S(o,_).slice();return t.__wbindgen_free(o,1*_),c}finally{t.__wbindgen_add_to_stack_pointer(16)}}function F(e){t.hakuban_tag_expose_drop(e)}function P(e){t.hakuban_object_expose_drop(e)}function D(e,n){try{return e.apply(this,n)}catch(e){t.__wbindgen_exn_store(c(e))}}Object.freeze({None:0,0:"None",InvalidString:1,1:"InvalidString",InvalidJSON:2,2:"InvalidJSON",InvalidURL:3,3:"InvalidURL",ObjectNotFound:4,4:"ObjectNotFound"});class U{static __wrap(t){const e=Object.create(U.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmhashresult_free(e)}get error(){return t.__wbg_get_wasmhashresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmhashresult_error(this.ptr,e)}get hash(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.__wbg_get_wasmhashresult_hash(r,this.ptr);var e=p()[r/4+0],n=p()[r/4+1];f[0]=e,f[1]=n;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}set hash(e){v[0]=e;const n=f[0],r=f[1];t.__wbg_set_wasmhashresult_hash(this.ptr,n,r)}}class E{static __wrap(t){const e=Object.create(E.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmlocalnodenewresult_free(e)}get error(){return t.__wbg_get_wasmlocalnodenewresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmlocalnodenewresult_error(this.ptr,e)}get local_node_pointer(){return t.__wbg_get_wasmlocalnodenewresult_local_node_pointer(this.ptr)}set local_node_pointer(e){t.__wbg_set_wasmlocalnodenewresult_local_node_pointer(this.ptr,e)}}class M{static __wrap(t){const e=Object.create(M.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectexposeresult_free(e)}get error(){return t.__wbg_get_wasmobjectexposeresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectexposeresult_error(this.ptr,e)}get object_expose_pointer(){return t.__wbg_get_wasmobjectexposeresult_object_expose_pointer(this.ptr)}set object_expose_pointer(e){t.__wbg_set_wasmobjectexposeresult_object_expose_pointer(this.ptr,e)}}class W{static __wrap(t){const e=Object.create(W.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectexposestateresult_free(e)}get error(){return t.__wbg_get_wasmobjectexposestateresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectexposestateresult_error(this.ptr,e)}get changed(){return 0!==t.__wbg_get_wasmobjectexposestateresult_changed(this.ptr)}set changed(e){t.__wbg_set_wasmobjectexposestateresult_changed(this.ptr,e)}}class B{static __wrap(t){const e=Object.create(B.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmobjectobserveresult_free(e)}get error(){return t.__wbg_get_wasmobjectobserveresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmobjectobserveresult_error(this.ptr,e)}get object_observe_pointer(){return t.__wbg_get_wasmobjectobserveresult_object_observe_pointer(this.ptr)}set object_observe_pointer(e){t.__wbg_set_wasmobjectobserveresult_object_observe_pointer(this.ptr,e)}}class ${static __wrap(t){const e=Object.create($.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmremotenodenewresult_free(e)}get error(){return t.__wbg_get_wasmremotenodenewresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmremotenodenewresult_error(this.ptr,e)}get remote_node_pointer(){return t.__wbg_get_wasmremotenodenewresult_remote_node_pointer(this.ptr)}set remote_node_pointer(e){t.__wbg_set_wasmremotenodenewresult_remote_node_pointer(this.ptr,e)}}class C{static __wrap(t){const e=Object.create(C.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposeassignmentresult_free(e)}get error(){return t.__wbg_get_wasmtagexposeassignmentresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposeassignmentresult_error(this.ptr,e)}get assignment(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.__wbg_get_wasmtagexposeassignmentresult_assignment(r,this.ptr);var e=p()[r/4+0],n=p()[r/4+1];f[0]=e,f[1]=n;return v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}set assignment(e){v[0]=e;const n=f[0],r=f[1];t.__wbg_set_wasmtagexposeassignmentresult_assignment(this.ptr,n,r)}}class L{static __wrap(t){const e=Object.create(L.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposeresult_free(e)}get error(){return t.__wbg_get_wasmtagexposeresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposeresult_error(this.ptr,e)}get tag_expose_pointer(){return t.__wbg_get_wasmtagexposeresult_tag_expose_pointer(this.ptr)}set tag_expose_pointer(e){t.__wbg_set_wasmtagexposeresult_tag_expose_pointer(this.ptr,e)}}class H{static __wrap(t){const e=Object.create(H.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagexposesetobjectstateresult_free(e)}get error(){return t.__wbg_get_wasmtagexposesetobjectstateresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagexposesetobjectstateresult_error(this.ptr,e)}get changed(){return 0!==t.__wbg_get_wasmtagexposesetobjectstateresult_changed(this.ptr)}set changed(e){t.__wbg_set_wasmtagexposesetobjectstateresult_changed(this.ptr,e)}}class Q{static __wrap(t){const e=Object.create(Q.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagobserveobjectstateborrowresult_free(e)}get error(){return t.__wbg_get_wasmtagobserveobjectstateborrowresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagobserveobjectstateborrowresult_error(this.ptr,e)}get state_pointer(){return t.__wbg_get_wasmtagobserveobjectstateborrowresult_state_pointer(this.ptr)}set state_pointer(e){t.__wbg_set_wasmtagobserveobjectstateborrowresult_state_pointer(this.ptr,e)}}class G{static __wrap(t){const e=Object.create(G.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const e=this.__destroy_into_raw();t.__wbg_wasmtagobserveresult_free(e)}get error(){return t.__wbg_get_wasmtagobserveresult_error(this.ptr)>>>0}set error(e){t.__wbg_set_wasmtagobserveresult_error(this.ptr,e)}get tag_observe_pointer(){return t.__wbg_get_wasmtagobserveresult_tag_observe_pointer(this.ptr)}set tag_observe_pointer(e){t.__wbg_set_wasmtagobserveresult_tag_observe_pointer(this.ptr,e)}}async function K(e){void 0===e&&(e=new URL("hakuban_bg.wasm",import.meta.url));const r={wbg:{}};r.wbg.__wbindgen_object_drop_ref=function(t){s(t)},r.wbg.__wbindgen_string_new=function(t,e){return c(a(t,e))},r.wbg.__wbindgen_cb_drop=function(t){const e=s(t).original;if(1==e.cnt--)return e.a=0,!0;return!1},r.wbg.__wbg_debug_6e114a5b27d7915d=function(t){console.debug(n(t))},r.wbg.__wbg_error_ca520cb687b085a1=function(t){console.error(n(t))},r.wbg.__wbg_info_32ab782ec7072fac=function(t){console.info(n(t))},r.wbg.__wbg_log_fbd13631356d44e4=function(t){console.log(n(t))},r.wbg.__wbg_warn_97f10a6b0dbb8c5c=function(t){console.warn(n(t))},r.wbg.__wbg_now_5fa0ca001e042f8a=function(t){return n(t).now()},r.wbg.__wbg_newnoargs_f579424187aa1717=function(t,e){return c(new Function(a(t,e)))},r.wbg.__wbg_get_8bbb82393651dd9c=function(){return D((function(t,e){return c(Reflect.get(n(t),n(e)))}),arguments)},r.wbg.__wbg_call_89558c3e96703ca1=function(){return D((function(t,e){return c(n(t).call(n(e)))}),arguments)},r.wbg.__wbg_call_94697a95cb7e239c=function(){return D((function(t,e,r){return c(n(t).call(n(e),n(r)))}),arguments)},r.wbg.__wbg_new_4beacc9c71572250=function(e,n){try{var r={a:e,b:n},s=new Promise(((e,n)=>{const s=r.a;r.a=0;try{return function(e,n,r,s){t.wasm_bindgen__convert__closures__invoke2_mut__h3fbc4a767cc461bf(e,n,c(r),c(s))}(s,r.b,e,n)}finally{r.a=s}}));return c(s)}finally{r.a=r.b=0}},r.wbg.__wbg_resolve_4f8f547f26b30b27=function(t){return c(Promise.resolve(n(t)))},r.wbg.__wbg_then_a6860c82b90816ca=function(t,e){return c(n(t).then(n(e)))},r.wbg.__wbg_then_58a04e42527f52c6=function(t,e,r){return c(n(t).then(n(e),n(r)))},r.wbg.__wbg_self_e23d74ae45fb17d1=function(){return D((function(){return c(self.self)}),arguments)},r.wbg.__wbg_window_b4be7f48b24ac56e=function(){return D((function(){return c(window.window)}),arguments)},r.wbg.__wbg_globalThis_d61b1f48a57191ae=function(){return D((function(){return c(globalThis.globalThis)}),arguments)},r.wbg.__wbg_global_e7669da72fd7f239=function(){return D((function(){return c(global.global)}),arguments)},r.wbg.__wbindgen_is_undefined=function(t){return void 0===n(t)},r.wbg.__wbindgen_object_clone_ref=function(t){return c(n(t))},r.wbg.__wbg_new_693216e109162396=function(){return c(new Error)},r.wbg.__wbg_stack_0ddaca5d1abfb52f=function(e,r){var s=b(n(r).stack,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;p()[e/4+1]=i,p()[e/4+0]=s},r.wbg.__wbg_error_09919627ac0992f5=function(e,n){try{console.error(a(e,n))}finally{t.__wbindgen_free(e,n)}},r.wbg.__wbindgen_debug_string=function(e,r){var s=b(h(n(r)),t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;p()[e/4+1]=i,p()[e/4+0]=s},r.wbg.__wbindgen_throw=function(t,e){throw new Error(a(t,e))},r.wbg.__wbindgen_closure_wrapper2024=function(e,n,r){var s=function(e,n,r,s){const i={a:e,b:n,cnt:1,dtor:r},o=(...e)=>{i.cnt++;const n=i.a;i.a=0;try{return s(n,i.b,...e)}finally{0==--i.cnt?t.__wbindgen_export_2.get(i.dtor)(n,i.b):i.a=n}};return o.original=i,o}(e,n,490,w);return c(s)},("string"==typeof e||"function"==typeof Request&&e instanceof Request||"function"==typeof URL&&e instanceof URL)&&(e=fetch(e));const{instance:i,module:o}=await async function(t,e){if("function"==typeof Response&&t instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(t,e)}catch(e){if("application/wasm"==t.headers.get("Content-Type"))throw e;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",e)}const n=await t.arrayBuffer();return await WebAssembly.instantiate(n,e)}{const n=await WebAssembly.instantiate(t,e);return n instanceof WebAssembly.Instance?{instance:n,module:t}:n}}(await e,r);return t=i.exports,K.__wbindgen_wasm_module=o,t}var V;V=class{constructor(){this.queue=[],this.wake=null}push(t){if(this.queue.push(t),null!=this.wake)return this.wake(),this.wake=null}async shift(){for(var t;;){if(null!=(t=this.queue.shift()))return t;if(null!=this.wake)throw"2 concurrent shifts on a single queue";await new Promise((t=>(this.wake=t,null)))}}clear(){return this.queue=[]}};var X,Y,Z,tt,et,nt,rt,st,it,ot,_t,at,ct,ht,lt,ut,dt=class{constructor(t,e){this.contract=t,this.managed_object_class=e,this._on_exception_policy="retry",this._retry_backoff=[.01,.1,1,10],this._terminate_on_deactivation=!1}on_exception(t){return this._on_exception_policy=t,this}retry_backoff(t){return this._retry_backoff=t,this}with_async(t){return new bt(this.contract,this.managed_object_class,t,this._retry_backoff,this._terminate_on_deactivation,this._on_exception_policy)}},bt=class{constructor(t,e,n,r,s,i){var o;this.objects=this.objects.bind(this),this.object=this.object.bind(this),this.drop=this.drop.bind(this),this.contract=t,this._existing_objects={},this._active_objects={},this.event_queue=new V,o=new Promise((t=>(this.event_loop_stop=t,null))),this.event_loop_stopped=new Promise((async(t,e)=>{var n,r;for(r=this.contract.events();(n=await Promise.race([r.next(),o]))&&null!=n;)this.event_queue.push(n);return r.drop(),t()})),this.async_loop_stopped=new Promise((async(t,s)=>{for(var o,_,a,c,h,l,u,d,b,g,p,w,f,v;null!=(h=await this.event_queue.shift());)switch(h.action){case"Insert":case"Change":case"Remove":case"Stopped":case"Timer":if(!(w=(o=this._existing_objects)[g=h.descriptor.hash()]||(o[g]=new e(this.contract,h.descriptor))).running&&null!=w.block_result&&(c=await w.block_result,w.block_result=null,null!=w.last_exception_at&&(u=Date.now()-w.last_exception_at,10,w.current_delay_index-=Math.floor(u/(1e3*r[r.length-1]*10)),w.current_delay_index<0&&(w.current_delay_index=0)),null!=c))switch(i){case"throw":case"raise":throw c.exception;case"retry":w.last_exception_at=Date.now(),w.earliest_next_run=Date.now()+1e3*r[w.current_delay_index],function(t,e,n){setTimeout((()=>n.push({action:"Timer",descriptor:e})),t)}(w.earliest_next_run-Date.now(),h.descriptor,this.event_queue),w.current_delay_index<r.length-1&&(w.current_delay_index+=1)}w.check_active()?(null!=n&&!w.running&&(null==w.earliest_next_run||Date.now()>=w.earliest_next_run)&&(a=h.descriptor,w.running=!0,w.block_result=function(t,e,n,r){return new Promise((async(t,s)=>{try{return await e.run(n),t(void 0)}catch(e){return c=e,console.error("Exception in hakuban manager lambda:",c),t(c)}finally{e.running=!1,r.push({action:"Stopped",descriptor:a})}}))}(h.descriptor,w,n,this.event_queue)),(_=this._active_objects)[p=h.descriptor.hash()]||(_[p]=w),w.change()):(delete this._active_objects[h.descriptor.hash()],w.running?w.stop():delete this._existing_objects[h.descriptor.hash()]);break;case"Drop":for(d in this.event_loop_stop(),await this.event_loop_stopped,f={...this._existing_objects})(w=f[d]).running?w.stop():delete this._existing_objects[d];for(;Object.keys(this._existing_objects).length>0;)"Stopped"===(h=await this.event_queue.shift()).action&&delete this._existing_objects[h.descriptor.hash()];for(this.event_queue.clear(),l=0,b=(v=Object.keys(this._active_objects)).length;l<b;l++)d=v[l],delete this._active_objects[d];return this.contract.drop(),this.contract=null,this.event_queue=null,void t();default:throw"Unknown action: "+h.action}return s("Queue died unexpectedly")}))}objects(){return Object.values(this._active_objects)}object(){return Object.values(this._active_objects)[0]}async drop(){if(this.contract)return this.event_queue.push({action:"Drop"}),await this.async_loop_stopped}},gt=class{constructor(t,e){this.run=this.run.bind(this),this.next_event=this.next_event.bind(this),this.next_change=this.next_change.bind(this),this.change=this.change.bind(this),this.stop=this.stop.bind(this),this.contract=t,this.descriptor=e,this._changes=new V,this.current_delay_index=0}async run(t){return await t(this)}next_event(){return this.next_change()}async next_change(){for(;;)switch(await this._changes.shift()){case"change":return!0;case"stop":return!1}}change(){return this._changes.push("change")}stop(){return this._changes.push("stop")}},pt=function(t,e){if(!(t instanceof e))throw new Error("Bound instance method accessed before binding")};lt=!1;var wt=async function(t){return await K(t)},ft=async function(e,n=!1){var r,s,i,o;return!(!lt||!n)||(0===(r=await(s=e,i=b(s,t.__wbindgen_malloc,t.__wbindgen_realloc),o=l,t.hakuban_logger_initialize(i,o)))?lt=!0:(console.error("Failed to initialize logger, error "+r),!1))};ut=function(t){if(0!==t)throw"Hakuban error: "+t};var vt=function(t,e){return{data_type:["JSON"].concat(t),data:(new TextEncoder).encode(JSON.stringify(e))}},mt=function(t,e){if(0===t.length||"JSON"!==t[0])throw"Expected JSON data_type, got: "+t;return{data_type:t.slice(1),data:JSON.parse((new TextDecoder).decode(e))}},yt=class{constructor(t,e){var n;this.json=e,this.tags=function(){var e,r,s;for(s=[],e=0,r=t.length;e<r;e++)n=t[e],s.push(n instanceof jt?n:new jt(n));return s}()}as_json(){return JSON.stringify({tags:this.tags.map((function(t){return t.json})),json:this.json})}hash(){var t;return null==this._hash&&(this._hash=this.tags.map((function(t){return t.hash().toString()})).sort().join(",")+"|",t=m(JSON.stringify(this.json)),ut(t.error),this._hash+=t.hash.toString()),this._hash}},jt=class{constructor(t){this.json=t}as_json(){return JSON.stringify(this.json)}hash(){var t;return null==this._hash&&(t=m(JSON.stringify(this.json)),ut(t.error),this._hash=t.hash),this._hash}};X=new FinalizationRegistry((t=>y(t)));var kt=class{constructor(e="wasm"){var n,r,s,i,o;this.name=e,ft("warn",!0),r=this.name,s=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l,o=t.hakuban_local_node_new(s,i),n=E.__wrap(o),ut(n.error),this.pointer=n.local_node_pointer,X.register(this,this.pointer,this),this.with_default_serializer(vt),this.with_default_deserializer(mt)}destroy(){return y(this.pointer),X.unregister(this)}object(t,e){return new Y(this,this.default_serializer,this.default_deserializer,t,e)}tag(t){return new it(this,this.default_serializer,this.default_deserializer,t)}with_default_serializer(t){return this.default_serializer=t,this}with_default_deserializer(t){return this.default_deserializer=t,this}};Y=class{constructor(t,e,n,r,s){this.local_node=t,this.serializer=e,this.deserializer=n,this.tags=r,this.json=s}observe(){return new rt(this.local_node,new yt(this.tags,this.json),this.deserializer)}expose(){return new et(this.local_node,new yt(this.tags,this.json),this.serializer)}with_serializer(t){return this.serializer=t,this}with_deserializer(t){return this.deserializer=t,this}},it=class{constructor(t,e,n,r){this.local_node=t,this.serializer=e,this.deserializer=n,this.json=r}observe(){return new at(this.local_node,new jt(this.json),this.deserializer)}expose(){return new ot(this.local_node,new jt(this.json),this.serializer)}with_serializer(t){return this.serializer=t,this}with_deserializer(t){return this.deserializer=t,this}},tt=new FinalizationRegistry((t=>J(t))),Z=class{constructor(t){this.wait=this.wait.bind(this),this.next=this.next.bind(this),this.drop=this.drop.bind(this),this.pointer=t,tt.register(this,this.pointer,this)}wait(){return next()}next(){var e,n,r,i;return this.wait_released=new Promise((t=>(this.wait_release=t,null))),e=new Promise((t=>this.cancel_waiting_resolve=t)),r=this.pointer,i=e,(n=s(t.hakuban_object_descriptor_events_next(r,c(i)))).cancel=async t=>(this.cancel_waiting_resolve.resolve(t),await n),n.then((t=>{var e;return this.wait_release(),this.wait_released=null,this.cancel_waiting_resolve=null,{action:(e=JSON.parse(t)).action,descriptor:new yt(e.key.tags,e.key.json)}}))}async drop(){return null!=this.cancel_waiting_resolve&&(this.cancel_waiting_resolve(),await this.wait_released),tt.unregister(this),J(this.pointer),this.pointer=null}},st=new FinalizationRegistry((t=>j(t))),rt=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_state=this.object_state.bind(this),this.events=this.events.bind(this),this.manage=this.manage.bind(this),this.local_node=e,this.descriptor=n,this.deserializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_object_observe_new(e,r,s);return B.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.object_observe_pointer,st.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,j(this.pointer),st.unregister(this),this.pointer=null}object_state(){var e,n,r,s,i,o,_;return null==this.pointer?null:(_=this.pointer,0===(s=t.hakuban_object_observe_state_borrow(_))?null:(i=x(s),o=JSON.parse(z(s)),e=JSON.parse(O(s)),r=N(s),k(s),{version:o,data:(n=this.deserializer(e,r)).data,data_type:n.data_type,synchronized:i}))}events(){return new Z((e=this.pointer,t.hakuban_object_observe_events_get(e)));var e}manage(){return new dt(this,class extends gt{state(){var t;return null!=(t=this.contract)?t.object_state():void 0}data(){var t,e;return null!=(t=this.contract)&&null!=(e=t.object_state())?e.data:void 0}check_active(){return!!this.state()}})}},nt=new FinalizationRegistry((t=>P(t))),et=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.set_object_state=this.set_object_state.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.desynchronize=this.desynchronize.bind(this),this.events=this.events.bind(this),this.manage=this.manage.bind(this),this.local_node=e,this.descriptor=n,this.serializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_object_expose_new(e,r,s);return M.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.object_expose_pointer,nt.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,P(this.pointer),nt.unregister(this)}set_object_state(e,n,r=[],s=0){var i,o;return o=this.serializer(r,n),"bigint"!=typeof s&&(s=BigInt(s)),i=function(e,n,r,s,i){var o=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),_=l,a=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),c=l,h=A(s,t.__wbindgen_malloc),u=l;v[0]=i;const d=f[0],g=f[1];var p=t.hakuban_object_expose_set_state(e,o,_,a,c,h,u,d,g);return W.__wrap(p)}(this.pointer,JSON.stringify(e),JSON.stringify(o.data_type),o.data,s),ut(i.error),i.changed}assignment(){return function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_object_expose_assignment(s,e);var n=p()[s/4+0],r=p()[s/4+1];return f[0]=n,f[1]=r,v[0]}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.pointer)}assigned(){return this.assignment()>0}desynchronize(e){return"bigint"!=typeof e&&(e=BigInt(e)),function(e,n){v[0]=n;const r=f[0],s=f[1];t.hakuban_object_expose_desynchronize(e,r,s)}(this.pointer,e)}events(){return new Z((e=this.pointer,t.hakuban_object_expose_events_get(e)));var e}manage(){return new dt(this,class t extends gt{constructor(t,e){super(t,e),this.run=this.run.bind(this),this.do_change=this.do_change.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.set_state=this.set_state.bind(this),this.set_data=this.set_data.bind(this),this._assignment=t.assignment()}async run(e){var n;return pt(this,t),await super.run(e),null!=(n=this.contract)?n.desynchronize(this._assignment):void 0}do_change(e){var n;return pt(this,t),this._assignment=null!=(n=this.contract)?n.assignment():void 0,super.do_change(e)}assignment(){var e;return pt(this,t),null!=(e=this.contract)?e.assignment():void 0}assigned(){var e;return pt(this,t),null!=(e=this.contract)?e.assigned():void 0}set_state(e,n,r=[]){var s;return pt(this,t),null!=(s=this.contract)?s.set_object_state(e,n,r,this._assignment):void 0}set_data(e){var n;return pt(this,t),n=(new Date).getTime(),this.set_state([1,Math.floor(n/1e3),n-1e3*Math.floor(n/1e3),0],e)}check_active(){return this.assigned()}})}},ct=new FinalizationRegistry((t=>T(t))),at=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_descriptors=this.object_descriptors.bind(this),this.object_state=this.object_state.bind(this),this.local_node=e,this.descriptor=n,this.deserializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_observe_new(e,r,s);return G.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.tag_observe_pointer,ct.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,T(this.pointer),ct.unregister(this)}object_descriptors(){var e,n,r,s,i,o;for(i=function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_observe_object_descriptors(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}(this.pointer),o=[],n=0,r=(s=JSON.parse(i)).length;n<r;n++)e=s[n],o.push(new yt(e.tags,e.json));return o}object_state(e){var n,r,s,i,o,_;return 4===(i=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_observe_object_state_borrow(e,r,s);return Q.__wrap(i)}(this.pointer,e.as_json())).error||0===i.state_pointer?null:(o=x(i.state_pointer),_=JSON.parse(z(i.state_pointer)),n=JSON.parse(O(i.state_pointer)),s=N(i.state_pointer),k(i.state_pointer),{version:_,data:(r=this.deserializer(n,s)).data,data_type:r.data_type,synchronized:o})}events(){return new Z((e=this.pointer,t.hakuban_tag_observe_events_get(e)));var e}manage(){return new dt(this,class extends gt{state(){var t;return null!=(t=this.contract)?t.object_state(this.descriptor):void 0}data(){var t,e;return null!=(t=this.contract)&&null!=(e=t.object_state(this.descriptor))?e.data:void 0}check_active(){return!!this.state()}})}},_t=new FinalizationRegistry((t=>F(t))),ot=class{constructor(e,n,r){var s;this.drop=this.drop.bind(this),this.object_descriptors=this.object_descriptors.bind(this),this.set_object_state=this.set_object_state.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.desynchronize=this.desynchronize.bind(this),this.events=this.events.bind(this),this.manage=this.manage.bind(this),this.local_node=e,this.descriptor=n,this.serializer=r,s=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_expose_new(e,r,s);return L.__wrap(i)}(this.local_node.pointer,this.descriptor.as_json()),ut(s.error),this.pointer=s.tag_expose_pointer,_t.register(this,this.pointer,this),this.dropped=!1}drop(){return this.dropped=!0,F(this.pointer),_t.unregister(this)}object_descriptors(){var e,n,r,s,i,o;for(i=function(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_tag_expose_object_descriptors(s,e);var n=p()[s/4+0],r=p()[s/4+1];return a(n,r)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_free(n,r)}}(this.pointer),o=[],n=0,r=(s=JSON.parse(i)).length;n<r;n++)e=s[n],o.push(new yt(e.tags,e.json));return o}set_object_state(e,n,r,s=[],i=0){var o,_;return _=this.serializer(s,r),"bigint"!=typeof i&&(i=BigInt(i)),o=function(e,n,r,s,i,o){var _=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),a=l,c=b(r,t.__wbindgen_malloc,t.__wbindgen_realloc),h=l,u=b(s,t.__wbindgen_malloc,t.__wbindgen_realloc),d=l,g=A(i,t.__wbindgen_malloc),p=l;v[0]=o;const w=f[0],m=f[1];var y=t.hakuban_tag_expose_set_object_state(e,_,a,c,h,u,d,g,p,w,m);return H.__wrap(y)}(this.pointer,e.as_json(),JSON.stringify(n),JSON.stringify(_.data_type),_.data,i),ut(o.error),o.changed}assignment(e){var n;return n=function(e,n){var r=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),s=l,i=t.hakuban_tag_expose_assignment(e,r,s);return C.__wrap(i)}(this.pointer,e.as_json()),ut(n.error),n.assignment}assigned(t){return this.assignment(t)>0}desynchronize(e,n){var r;return"bigint"!=typeof n&&(n=BigInt(n)),r=function(e,n,r){var s=b(n,t.__wbindgen_malloc,t.__wbindgen_realloc),i=l;v[0]=r;const o=f[0],_=f[1];return t.hakuban_tag_expose_desynchronize(e,s,i,o,_)>>>0}(this.pointer,e.as_json(),n),ut(r)}events(){return new Z((e=this.pointer,t.hakuban_tag_expose_events_get(e)));var e}manage(){return new dt(this,class t extends gt{constructor(t,e){super(t,e),this.run=this.run.bind(this),this.do_change=this.do_change.bind(this),this.assignment=this.assignment.bind(this),this.assigned=this.assigned.bind(this),this.set_state=this.set_state.bind(this),this.set_data=this.set_data.bind(this),this._assignment=t.assignment(this.descriptor)}async run(e){var n;return pt(this,t),await super.run(e),null!=(n=this.contract)?n.desynchronize(this.descriptor,this._assignment):void 0}do_change(e){var n;return pt(this,t),this._assignment=null!=(n=this.contract)?n.assignment(this.descriptor):void 0,super.do_change(e)}assignment(){var e;return pt(this,t),null!=(e=this.contract)?e.assignment(this.descriptor):void 0}assigned(){var e;return pt(this,t),null!=(e=this.contract)?e.assigned(this.descriptor):void 0}set_state(e,n,r=[]){var s;return pt(this,t),null!=(s=this.contract)?s.set_object_state(this.descriptor,e,n,r,this._assignment):void 0}set_data(e){var n;return pt(this,t),n=(new Date).getTime(),this.set_state([1,Math.floor(n/1e3),n-1e3*Math.floor(n/1e3),0],e)}check_active(){return this.assigned()}})}},ht=new FinalizationRegistry((t=>R(t)));var xt=class{constructor(e,n,r={}){var s,i,o,_,a,c;this.connect=this.connect.bind(this),this.ping=this.ping.bind(this),this.send=this.send.bind(this),this.ack=this.ack.bind(this),this.local_node=e,this.uri=n,this.options=r,this.connected=!1,this.socket=void 0,this.error=void 0,this.reconnection_timer=void 0,this.reconnect_on_close=!0,this.ack_timer=void 0,i=this.local_node.pointer,o=!0,_=!0,a=!0,c=t.hakuban_remote_node_new(i,o,I(_)?16777215:_?1:0,I(a)?16777215:a?1:0),s=$.__wrap(c),ut(s.error),this.remote_node_pointer=s.remote_node_pointer,this.event_loop_stop=new Promise((t=>this.event_loop_stop_resolve=t)),this.event_loop_promise=this.event_loop(),ht.register(this,this.remote_node_pointer,this),this.connect()}async destroy(){return this.event_loop_stop_resolve(["stop"]),await this.event_loop_promise,this.reconnect_on_close=!1,this.keep_alive_interval&&clearInterval(this.keep_alive_interval),null!=this.reconnection_timer&&(clearTimeout(this.reconnection_timer),this.reconnection_timer=null),null!=this.socket&&(this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null,this.socket.close(),this.socket_onclose()),null!=this.ack_timer&&(clearTimeout(this.ack_timer),this.ack_timer=null),R(this.remote_node_pointer),ht.unregister(this)}connect(){var e;this.reconnection_timer=void 0;try{this.socket=new WebSocket(this.uri)}catch(t){return e=t,this.error={while:"connecting",error:e},null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),!1}return this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{var e;return this.options.debug&&console.debug("Connected to hakuban remote node"),this.connected=!0,this.error=void 0,null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),e=function(e){try{const _=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_remote_node_connected(_,e);var n=p()[_/4+0],r=p()[_/4+1],i=p()[_/4+2];if(p()[_/4+3])throw s(i);var o=S(n,r).slice();return t.__wbindgen_free(n,1*r),o}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer),this.send(e)},this.socket.onclose=this.socket_onclose=()=>{var e;if(this.options.debug&&console.debug("Disconnected from hakuban remote node"),this.keep_alive_interval&&clearInterval(this.keep_alive_interval),this.connected=!1,this.socket=void 0,e=this.remote_node_pointer,t.hakuban_remote_node_disconnected(e),null!=this.onstatuschange_proc&&this.onstatuschange_proc(this),null!=this.reconnection_timer&&clearTimeout(this.reconnection_timer),this.reconnection_timer=null,this.reconnect_on_close)return this.reconnection_timer=setTimeout(this.connect,1e3)},this.socket.onerror=t=>(this.options.debug&&console.debug("Hakuban socket error",t),this.error={while:"connected",error:t}),this.socket.onmessage=e=>{var n;return n=function(e,n){try{const h=t.__wbindgen_add_to_stack_pointer(-16);var r=A(n,t.__wbindgen_malloc),i=l;t.hakuban_remote_node_received_message(h,e,r,i);var o=p()[h/4+0],_=p()[h/4+1],a=p()[h/4+2];if(p()[h/4+3])throw s(a);var c=S(o,_).slice();return t.__wbindgen_free(o,1*_),c}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer,new Uint8Array(e.data)),this.send(n),null!=this.ack_timer&&clearTimeout(this.ack_timer),this.ack_timer=setTimeout(this.ack,1e3),null}}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)}ack(){var e;if(null!=this.socket&&(e=function(e){try{const i=t.__wbindgen_add_to_stack_pointer(-16);t.hakuban_remote_node_ack(i,e);var n=p()[i/4+0],r=p()[i/4+1],s=S(n,r).slice();return t.__wbindgen_free(n,1*r),s}finally{t.__wbindgen_add_to_stack_pointer(16)}}(this.remote_node_pointer)).length>0)return this.send(e)}async event_loop(){var e,n,r,i,o,_,a;for(i=!1,n=null,e=new Promise((function(t){return n=t}));i||(i=(_=this.remote_node_pointer,a=e,s(t.hakuban_remote_node_next_local_node_event(_,c(a)))).then((function(t){return["local_node_event",t]}))),[o,r]=await Promise.any([this.event_loop_stop,i]),"local_node_event"===o;)i=!1,setTimeout((t=>{var e;if(this.connected)return e=q(this.remote_node_pointer,t),this.send(e)}),0,r);if(i)return n(!0),await i}onstatuschange(t){return this.onstatuschange_proc=t,null!=this.onstatuschange_proc&&this.onstatuschange_proc(),this}},zt=async function(t){return await wt(t)};export{mt as JSON_deserialize,vt as JSON_serialize,kt as LocalNode,yt as ObjectDescriptor,jt as TagDescriptor,xt as WebsocketConnector,zt as initialize,wt as initialize_wasm,ft as logger_initialize};
|
|
2
2
|
//# sourceMappingURL=hakuban.min.js.map
|