Keyborg/server/public/js/shared.bundle.js
2025-01-22 20:05:24 +03:00

2 lines
6.1 KiB
JavaScript

var T=class r{constructor(e){this._promise=e;this._promise=e}static fromPromise(e,t){let n=e.then(E=>new s(E)).catch(E=>new a(t(E)));return new r(n)}static fromSafePromise(e){let t=e.then(n=>new s(n));return new r(t)}static fromThrowable(e,t){return(...n)=>{try{return f(e(n))}catch(E){return p(t?t(E):E)}}}async unwrap(){let e=await this._promise;if(e.isErr())throw e.error;return e.value}async match(e,t){let n=await this._promise;return n.isErr()?t(n.error):e(n.value)}map(e){return new r(this._promise.then(t=>t.isErr()?new a(t.error):new s(e(t.value))))}mapAsync(e){return new r(this._promise.then(async t=>t.isErr()?p(t.error):new s(await e(t.value))))}mapErr(e){return new r(this._promise.then(t=>t.isErr()?new a(e(t.error)):new s(t.value)))}mapErrAsync(e){return new r(this._promise.then(async t=>t.isErr()?p(await e(t.error)):new s(t.value)))}andThen(e){return new r(this._promise.then(t=>t.isErr()?p(t.error):e(t.value)))}nullableToOption(){return this.map(e=>e?U(e):v)}flatten(){return new r(this._promise.then(e=>e.flatten()))}flattenOption(e){return new r(this._promise.then(t=>t.flattenOption(e)))}flattenOptionOrDefault(e){return new r(this._promise.then(t=>t.flattenOptionOrDefault(e)))}matchOption(e,t){return new r(this._promise.then(n=>n.matchOption(e,t)))}matchOptionAndFlatten(e,t){return new r(this._promise.then(n=>n.matchOptionAndFlatten(e,t)))}then(e,t){return this._promise.then(e,t)}};function f(r){return new T(Promise.resolve(new s(r)))}function p(r){return new T(Promise.resolve(new a(r)))}var s=class r{constructor(e){this.value=e;this.value=e,Object.defineProperties(this,{tag:{writable:!1,enumerable:!1}})}tag="Ok";isErr(){return!1}ifErr(e){return this}isErrOrNone(){return this.value instanceof i}isOk(){return!0}ifOk(e){return e(this.value),this}unwrap(){return this.value}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}match(e,t){return e(this.value)}map(e){let t=e(this.value);return new r(t)}mapAsync(e){return T.fromSafePromise(e(this.value))}mapOption(e){return this.value instanceof i||this.value instanceof l?o(this.value.map(e)):o(U(e(this.value)))}andThen(e){return e(this.value)}andThenAsync(e){return e(this.value)}mapErr(e){return new r(this.value)}mapErrAsync(e){return f(this.value)}flatten(){return h(this)}flattenOption(e){return this.value instanceof i||this.value instanceof l?this.value.okOrElse(e):new r(this.value)}flattenOptionOr(e){return this.value instanceof i||this.value instanceof l?this.value.unwrapOr(e):new r(this.value)}matchOption(e,t){return this.value instanceof i||this.value instanceof l?o(this.value.match(e,t)):o(e(this.value))}toNullable(){return this.value}toAsync(){return f(this.value)}void(){return o()}toJSON(){return{tag:"ok",value:this.value}}},a=class r{constructor(e){this.error=e;this.error=e,Object.defineProperties(this,{tag:{writable:!1,configurable:!1,enumerable:!1}})}tag="Err";isErr(){return!0}ifErr(e){return e(this.error),this}isOk(){return!1}ifOk(e){return this}isErrOrNone(){return!0}unwrap(){let e=`Tried to unwrap error: ${O(this.error)}`;throw new Error(e)}unwrapOr(e){return e}unwrapOrElse(e){return e()}match(e,t){return t(this.error)}map(e){return new r(this.error)}mapAsync(e){return p(this.error)}mapErr(e){let t=e(this.error);return new r(t)}mapErrAsync(e){return T.fromPromise(new Promise(()=>{throw""}),()=>e(this.error))}mapOption(e){return u(this.error)}andThen(e){return new r(this.error)}flatten(){return h(this)}flattenOption(e){return new r(this.error)}flattenOptionOr(e){return new r(this.error)}matchOption(e,t){return u(this.error)}toNullable(){return null}toAsync(){return p(this.error)}void(){return u(this.error)}toJSON(){return{tag:"err",error:this.error}}};function o(r){return new s(r)}function u(r){return new a(r)}function b(r,e){return(...t)=>{try{let n=r(...t);return o(n)}catch(n){return u(e?e(n):n)}}}function O(r){if(r instanceof Error)return r.message?r.message:"code"in r&&typeof r.code=="string"?r.code:"An unknown error occurred";if(typeof r=="string")return r;if(typeof r=="object"&&r!==null&&"message"in r){let e=r;return typeof e.message=="string"?e.message:String(e.message)}return"An unknown error occurred"}function h(r){let e=r;for(;e instanceof s;)e=e.value;return e}var c=class extends Error{constructor(e){super(`Failed to parse ${e} as result`)}};function B(r){let e;if(typeof r=="string")try{e=JSON.parse(r)}catch(n){return u(new c(O(n)))}else e=r;if(typeof e!="object"||e===null)return u(new c("Expected an object but received type ${typeof data}."));let t=e;if("tag"in t)switch(t.tag){case"ok":{if("value"in t)return o(t.value);break}case"err":{if("error"in t)return u(t.error);break}}return u(new c("Object does not contain 'tag' and 'value' or 'error' property"))}var l=class r{constructor(e){this.value=e;Object.defineProperties(this,{tag:{writable:!1,enumerable:!1}})}tag="Some";isSome(){return!0}ifSome(e){return e(this.value),this}isNone(){return!1}ifNone(e){return this}map(e){return new r(e(this.value))}flatMap(e){return e(this.value)}andThen(e){return e(this.value)}unwrap(){return this.value}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}or(e){return this}orElse(e){return this}match(e,t){return e(this.value)}toJSON(){return{value:this.value}}toString(){return`Some(${this.value})`}toNullable(){return this.value}toBoolean(){return!0}okOrElse(e){return o(this.value)}},i=class r{tag="None";constructor(){Object.defineProperties(this,{tag:{writable:!1,enumerable:!1}})}isSome(){return!1}ifSome(e){return this}isNone(){return!0}ifNone(e){return e(),this}map(e){return new r}andThen(e){return v}flatMap(e){return new r}unwrap(){throw new Error("Tried to unwrap a non-existent value")}unwrapOr(e){return e}unwrapOrElse(e){return e()}or(e){return e}orElse(e){return e()}match(e,t){return t()}toJSON(){return{_tag:this._tag}}toString(){return"None"}toNullable(){return null}toBoolean(){return!1}okOrElse(e){return u(e())}};function U(r){return new l(r)}var v=new i;function S(r){return r?U(r):v}export{a as Err,i as None,s as Ok,T as ResultAsync,B as ResultFromJSON,l as Some,u as err,p as errAsync,h as flattenResult,S as fromNullableVal,b as fromThrowable,O as getMessageFromError,v as none,o as ok,f as okAsync,U as some};