@instantdb/resumable-stream 0.22.150 → 0.22.151
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/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
|
-
> @instantdb/resumable-stream@0.22.
|
|
2
|
+
> @instantdb/resumable-stream@0.22.151 build /home/runner/work/instant/instant/client/packages/resumable-stream
|
|
3
3
|
> rm -rf dist; npm run build:tshy && npm run build:standalone && npm run check-exports
|
|
4
4
|
|
|
5
5
|
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
|
|
6
6
|
npm warn Unknown user config "always-auth". This will stop working in the next major version of npm.
|
|
7
7
|
|
|
8
|
-
> @instantdb/resumable-stream@0.22.
|
|
8
|
+
> @instantdb/resumable-stream@0.22.151 build:tshy
|
|
9
9
|
> tshy
|
|
10
10
|
|
|
11
11
|
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
|
|
12
12
|
npm warn Unknown user config "always-auth". This will stop working in the next major version of npm.
|
|
13
13
|
|
|
14
|
-
> @instantdb/resumable-stream@0.22.
|
|
14
|
+
> @instantdb/resumable-stream@0.22.151 build:standalone
|
|
15
15
|
> vite build
|
|
16
16
|
|
|
17
17
|
[36mvite v5.4.14 [32mbuilding for production...[36m[39m
|
|
@@ -21,15 +21,15 @@ rendering chunks...
|
|
|
21
21
|
computing gzip size...
|
|
22
22
|
[2mdist/standalone/[22m[36mindex.umd.cjs [39m[1m[2m66.70 kB[22m[1m[22m[2m │ gzip: 20.96 kB[22m
|
|
23
23
|
[2mdist/standalone/[22m[36mindex.js [39m[1m[2m105.89 kB[22m[1m[22m[2m │ gzip: 27.68 kB[22m
|
|
24
|
-
[32m✓ built in
|
|
24
|
+
[32m✓ built in 1.11s[39m
|
|
25
25
|
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
|
|
26
26
|
npm warn Unknown user config "always-auth". This will stop working in the next major version of npm.
|
|
27
27
|
|
|
28
|
-
> @instantdb/resumable-stream@0.22.
|
|
28
|
+
> @instantdb/resumable-stream@0.22.151 check-exports
|
|
29
29
|
> attw --pack .
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
@instantdb/resumable-stream v0.22.
|
|
32
|
+
@instantdb/resumable-stream v0.22.151
|
|
33
33
|
|
|
34
34
|
Build tools:
|
|
35
35
|
- @arethetypeswrong/cli@^0.17.4
|
package/dist/standalone/index.js
CHANGED
|
@@ -833,7 +833,7 @@ class Ie extends B {
|
|
|
833
833
|
}
|
|
834
834
|
}
|
|
835
835
|
typeof window < "u" && typeof window.localStorage < "u" && (window.localStorage.getItem("devBackend"), window.localStorage.getItem("__instantLogging"), window.localStorage.getItem("__devtoolLocalDash"));
|
|
836
|
-
const Ae = "v0.22.
|
|
836
|
+
const Ae = "v0.22.151";
|
|
837
837
|
class ue {
|
|
838
838
|
constructor(t, n, i, s = { indexed: !1, unique: !1 }) {
|
|
839
839
|
d(this, "valueType");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function($,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):($=typeof globalThis<"u"?globalThis:$||self,_($.instant={}))})(this,function($){"use strict";var Qi=Object.defineProperty;var wn=$=>{throw TypeError($)};var Gi=($,_,x)=>_ in $?Qi($,_,{enumerable:!0,configurable:!0,writable:!0,value:x}):$[_]=x;var d=($,_,x)=>Gi($,typeof _!="symbol"?_+"":_,x),Pt=($,_,x)=>_.has($)||wn("Cannot "+x);var g=($,_,x)=>(Pt($,_,"read from private field"),x?x.call($):_.get($)),X=($,_,x)=>_.has($)?wn("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add($):_.set($,x),he=($,_,x,R)=>(Pt($,_,"write to private field"),R?R.call($,x):_.set($,x),x),Y=($,_,x)=>(Pt($,_,"access private method"),x);var je,N,Oe,W,F,U,In,it,vn,On,$n,Ze,et,tt,jt,kn,nt;const _=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function x(e){return typeof e=="string"&&_.test(e)}const R=[];for(let e=0;e<256;++e)R.push((e+256).toString(16).slice(1));function En(e,t=0){return(R[e[t+0]]+R[e[t+1]]+R[e[t+2]]+R[e[t+3]]+"-"+R[e[t+4]]+R[e[t+5]]+"-"+R[e[t+6]]+R[e[t+7]]+"-"+R[e[t+8]]+R[e[t+9]]+"-"+R[e[t+10]]+R[e[t+11]]+R[e[t+12]]+R[e[t+13]]+R[e[t+14]]+R[e[t+15]]).toLowerCase()}let st;const _n=new Uint8Array(16);function Cn(){if(!st){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");st=crypto.getRandomValues.bind(crypto)}return st(_n)}const Mt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function xn(e,t,n){var s;if(Mt.randomUUID&&!e)return Mt.randomUUID();e=e||{};const i=e.random??((s=e.rng)==null?void 0:s.call(e))??Cn();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,En(i)}const P={Remove:"remove",Replace:"replace",Add:"add"},Ut=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),Je=Symbol.iterator,Z={mutable:"mutable",immutable:"immutable"},rt={};function Me(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Dt(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const i=Reflect.getOwnPropertyDescriptor(n,t);if(i)return i;n=Reflect.getPrototypeOf(n)}}}function Nt(e){return Object.getPrototypeOf(e)===Set.prototype}function Lt(e){return Object.getPrototypeOf(e)===Map.prototype}function H(e){var t;return(t=e.copy)!==null&&t!==void 0?t:e.original}function ot(e){return!!E(e)}function E(e){return typeof e!="object"?null:e==null?void 0:e[Ut]}function at(e){var t;const n=E(e);return n?(t=n.copy)!==null&&t!==void 0?t:n.original:e}function ge(e,t){if(!e||typeof e!="object")return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(t!=null&&t.mark)&&((n=t.mark(e,Z))===Z.immutable||typeof n=="function")}function Wt(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,i=E(pe(n,e.key));if(i!==null&&(i==null?void 0:i.original)!==e.original)return null;const s=e.parent.type===3,r=s?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(s&&n.size>r||Me(n,r)))return null;t.push(r)}if(e.parent)return Wt(e.parent,t);t.reverse();try{Tn(e.copy,t)}catch{return null}return t}function Ue(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function pe(e,t){return Ue(e)===2?e.get(t):e[t]}function ct(e,t,n){Ue(e)===2?e.set(t,n):e[t]=n}function ut(e,t){const n=E(e);return(n?H(n):e)[t]}function we(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function Se(e,t){return t?e:[""].concat(e).map(n=>{const i=`${n}`;return i.indexOf("/")===-1&&i.indexOf("~")===-1?i:i.replace(/~/g,"~0").replace(/\//g,"~1")}).join("/")}function Tn(e,t){for(let n=0;n<t.length-1;n+=1){const i=t[n];if(e=pe(Ue(e)===3?Array.from(e):e,i),typeof e!="object")throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}return e}function Rn(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach(n=>{let i=Reflect.getOwnPropertyDescriptor(e,n);if(i.enumerable&&i.configurable&&i.writable){t[n]=e[n];return}i.writable||(i.writable=!0,i.configurable=!0),(i.get||i.set)&&(i={configurable:!0,writable:!0,enumerable:i.enumerable,value:e[n]}),Reflect.defineProperty(t,n,i)}),t}const An=Object.prototype.propertyIsEnumerable;function Pn(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!Nt(e)){const i=Object.getPrototypeOf(e).constructor;return new i(e.values())}return Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values())}else if(e instanceof Map){if(!Lt(e)){const i=Object.getPrototypeOf(e).constructor;return new i(e)}return new Map(e)}else if(t!=null&&t.mark&&(n=t.mark(e,Z),n!==void 0)&&n!==Z.mutable){if(n===Z.immutable)return Rn(e);if(typeof n=="function"){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}else if(typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype){const i={};return Object.keys(e).forEach(s=>{i[s]=e[s]}),Object.getOwnPropertySymbols(e).forEach(s=>{An.call(e,s)&&(i[s]=e[s])}),i}else throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function L(e){e.copy||(e.copy=Pn(e.original,e.options))}function De(e){if(!ge(e))return at(e);if(Array.isArray(e))return e.map(De);if(e instanceof Map){const n=Array.from(e.entries()).map(([i,s])=>[i,De(s)]);if(!Lt(e)){const i=Object.getPrototypeOf(e).constructor;return new i(n)}return new Map(n)}if(e instanceof Set){const n=Array.from(e).map(De);if(!Nt(e)){const i=Object.getPrototypeOf(e).constructor;return new i(n)}return new Set(n)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=De(e[n]);return t}function Qe(e){return ot(e)?De(e):e}function se(e){var t;e.assignedMap=(t=e.assignedMap)!==null&&t!==void 0?t:new Map,e.operated||(e.operated=!0,e.parent&&se(e.parent))}function jn(e,t){const n=Ue(e);if(n===0)Reflect.ownKeys(e).forEach(i=>{t(i,e[i],e)});else if(n===1){let i=0;for(const s of e)t(i,s,e),i+=1}else e.forEach((i,s)=>t(s,i,e))}function Ft(e,t,n){if(ot(e)||!ge(e,n)||t.has(e)||Object.isFrozen(e))return;const i=e instanceof Set,s=i?new Map:void 0;if(t.add(e),jn(e,(r,o)=>{var a;if(ot(o)){const u=E(o);L(u);const c=!((a=u.assignedMap)===null||a===void 0)&&a.size||u.operated?u.copy:u.original;ct(i?s:e,r,c)}else Ft(o,t,n)}),s){const r=e,o=Array.from(r);r.clear(),o.forEach(a=>{r.add(s.has(a)?s.get(a):a)})}}function Mn(e,t){const n=e.type===3?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&Ft(pe(n,t),e.finalities.handledSet,e.options)}function ft(e){e.type===3&&e.copy&&(e.copy.clear(),e.setMap.forEach(t=>{e.copy.add(at(t))}))}function lt(e,t,n,i){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&i){const r=Wt(e);r&&t(e,r,n,i)}e.finalized=!0}}function dt(e,t,n,i){const s=E(n);s&&(s.callbacks||(s.callbacks=[]),s.callbacks.push((r,o)=>{var a;const u=e.type===3?e.setMap:e.copy;if(we(pe(u,t),n)){let c=s.original;s.copy&&(c=s.copy),ft(e),lt(e,i,r,o),e.options.enableAutoFreeze&&(e.options.updatedValues=(a=e.options.updatedValues)!==null&&a!==void 0?a:new WeakMap,e.options.updatedValues.set(c,s.original)),ct(u,t,c)}}),e.options.enableAutoFreeze&&s.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),ge(n,e.options)&&e.finalities.draft.push(()=>{const r=e.type===3?e.setMap:e.copy;we(pe(r,t),n)&&Mn(e,t)})}function Un(e,t,n,i,s){let{original:r,assignedMap:o,options:a}=e,u=e.copy;u.length<r.length&&([r,u]=[u,r],[n,i]=[i,n]);for(let c=0;c<r.length;c+=1)if(o.get(c.toString())&&u[c]!==r[c]){const l=t.concat([c]),f=Se(l,s);n.push({op:P.Replace,path:f,value:Qe(u[c])}),i.push({op:P.Replace,path:f,value:Qe(r[c])})}for(let c=r.length;c<u.length;c+=1){const l=t.concat([c]),f=Se(l,s);n.push({op:P.Add,path:f,value:Qe(u[c])})}if(r.length<u.length){const{arrayLengthAssignment:c=!0}=a.enablePatches;if(c){const l=t.concat(["length"]),f=Se(l,s);i.push({op:P.Replace,path:f,value:r.length})}else for(let l=u.length;r.length<l;l-=1){const f=t.concat([l-1]),m=Se(f,s);i.push({op:P.Remove,path:m})}}}function Dn({original:e,copy:t,assignedMap:n},i,s,r,o){n.forEach((a,u)=>{const c=pe(e,u),l=Qe(pe(t,u)),f=a?Me(e,u)?P.Replace:P.Add:P.Remove;if(we(c,l)&&f===P.Replace)return;const m=i.concat(u),y=Se(m,o);s.push(f===P.Remove?{op:f,path:y}:{op:f,path:y,value:l}),r.push(f===P.Add?{op:P.Remove,path:y}:f===P.Remove?{op:P.Add,path:y,value:c}:{op:P.Replace,path:y,value:c})})}function Nn({original:e,copy:t},n,i,s,r){let o=0;e.forEach(a=>{if(!t.has(a)){const u=n.concat([o]),c=Se(u,r);i.push({op:P.Remove,path:c,value:a}),s.unshift({op:P.Add,path:c,value:a})}o+=1}),o=0,t.forEach(a=>{if(!e.has(a)){const u=n.concat([o]),c=Se(u,r);i.push({op:P.Add,path:c,value:a}),s.unshift({op:P.Remove,path:c,value:a})}o+=1})}function Ne(e,t,n,i){const{pathAsArray:s=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return Dn(e,t,n,i,s);case 1:return Un(e,t,n,i,s);case 3:return Nn(e,t,n,i,s)}}const Ge=(e,t,n=!1)=>{if(typeof e=="object"&&e!==null&&(!ge(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},ht={get size(){return H(E(this)).size},has(e){return H(E(this)).has(e)},set(e,t){const n=E(this),i=H(n);return(!i.has(e)||!we(i.get(e),t))&&(L(n),se(n),n.assignedMap.set(e,!0),n.copy.set(e,t),dt(n,e,t,Ne)),this},delete(e){if(!this.has(e))return!1;const t=E(this);return L(t),se(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=E(this);if(this.size){L(e),se(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){const n=E(this);H(n).forEach((i,s)=>{e.call(t,this.get(s),s,this)})},get(e){var t,n;const i=E(this),s=H(i).get(e),r=((n=(t=i.options).mark)===null||n===void 0?void 0:n.call(t,s,Z))===Z.mutable;if(i.options.strict&&Ge(s,i.options,r),r||i.finalized||!ge(s,i.options)||s!==i.original.get(e))return s;const o=rt.createDraft({original:s,parentDraft:i,key:e,finalities:i.finalities,options:i.options});return L(i),i.copy.set(e,o),o},keys(){return H(E(this)).keys()},values(){const e=this.keys();return{[Je]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[Je]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[Je](){return this.entries()}},Ln=Reflect.ownKeys(ht),zt=(e,t,{isValuesIterator:n})=>()=>{var i,s;const r=t.next();if(r.done)return r;const o=r.value;let a=e.setMap.get(o);const u=E(a),c=((s=(i=e.options).mark)===null||s===void 0?void 0:s.call(i,a,Z))===Z.mutable;if(e.options.strict&&Ge(o,e.options,c),!c&&!u&&ge(o,e.options)&&!e.finalized&&e.original.has(o)){const l=rt.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,l),a=l}else u&&(a=u.proxy);return{done:!1,value:n?a:[a,a]}},He={get size(){return E(this).setMap.size},has(e){const t=E(this);if(t.setMap.has(e))return!0;L(t);const n=E(e);return!!(n&&t.setMap.has(n.original))},add(e){const t=E(this);return this.has(e)||(L(t),se(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),dt(t,e,e,Ne)),this},delete(e){if(!this.has(e))return!1;const t=E(this);L(t),se(t);const n=E(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=E(this);L(e),se(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=E(this);L(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:zt(e,t,{isValuesIterator:!0})}},entries(){const e=E(this);L(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:zt(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[Je](){return this.values()},forEach(e,t){const n=this.values();let i=n.next();for(;!i.done;)e.call(t,i.value,i.value,this),i=n.next()}};Set.prototype.difference&&Object.assign(He,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const Wn=Reflect.ownKeys(He),Vt=new WeakSet,Jt={get(e,t,n){var i,s;const r=(i=e.copy)===null||i===void 0?void 0:i[t];if(r&&Vt.has(r))return r;if(t===Ut)return e;let o;if(e.options.mark){const c=t==="size"&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(o=e.options.mark(c,Z),o===Z.mutable)return e.options.strict&&Ge(c,e.options,!0),c}const a=H(e);if(a instanceof Map&&Ln.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(ht,"size").get.call(e.proxy);const c=ht[t];if(c)return c.bind(e.proxy)}if(a instanceof Set&&Wn.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(He,"size").get.call(e.proxy);const c=He[t];if(c)return c.bind(e.proxy)}if(!Me(a,t)){const c=Dt(a,t);return c?"value"in c?c.value:(s=c.get)===null||s===void 0?void 0:s.call(e.proxy):void 0}const u=a[t];if(e.options.strict&&Ge(u,e.options),e.finalized||!ge(u,e.options))return u;if(u===ut(e.original,t)){if(L(e),e.copy[t]=Qt({original:e.original[t],parentDraft:e,key:e.type===1?Number(t):t,finalities:e.finalities,options:e.options}),typeof o=="function"){const c=E(e.copy[t]);return L(c),se(c),c.copy}return e.copy[t]}return u},set(e,t,n){var i;if(e.type===3||e.type===2)throw new Error("Map/Set draft does not support any property assignment.");let s;if(e.type===1&&t!=="length"&&!(Number.isInteger(s=Number(t))&&s>=0&&(t===0||s===0||String(s)===String(t))))throw new Error("Only supports setting array indices and the 'length' property.");const r=Dt(H(e),t);if(r!=null&&r.set)return r.set.call(e.proxy,n),!0;const o=ut(H(e),t),a=E(o);return a&&we(a.original,n)?(e.copy[t]=n,e.assignedMap=(i=e.assignedMap)!==null&&i!==void 0?i:new Map,e.assignedMap.set(t,!1),!0):(we(n,o)&&(n!==void 0||Me(e.original,t))||(L(e),se(e),Me(e.original,t)&&we(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,dt(e,t,n,Ne)),!0)},has(e,t){return t in H(e)},ownKeys(e){return Reflect.ownKeys(H(e))},getOwnPropertyDescriptor(e,t){const n=H(e),i=Reflect.getOwnPropertyDescriptor(n,t);return i&&{writable:!0,configurable:e.type!==1||t!=="length",enumerable:i.enumerable,value:n[t]}},getPrototypeOf(e){return Reflect.getPrototypeOf(e.original)},setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return e.type===1?Jt.set.call(this,e,t,void 0,e.proxy):(ut(e.original,t)!==void 0||t in e.original?(L(e),se(e),e.assignedMap.set(t,!1)):(e.assignedMap=(n=e.assignedMap)!==null&&n!==void 0?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function Qt(e){const{original:t,parentDraft:n,key:i,finalities:s,options:r}=e,o=Ue(t),a={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:s,options:r,setMap:o===3?new Map(t.entries()):void 0};(i||"key"in e)&&(a.key=i);const{proxy:u,revoke:c}=Proxy.revocable(o===1?Object.assign([],a):a,Jt);if(s.revoke.push(c),Vt.add(u),a.proxy=u,n){const l=n;l.finalities.draft.push((f,m)=>{var y,I;const w=E(u);let h=l.type===3?l.setMap:l.copy;const O=pe(h,i),b=E(O);if(b){let k=b.original;b.operated&&(k=at(O)),ft(b),lt(b,Ne,f,m),l.options.enableAutoFreeze&&(l.options.updatedValues=(y=l.options.updatedValues)!==null&&y!==void 0?y:new WeakMap,l.options.updatedValues.set(k,b.original)),ct(h,i,k)}(I=w.callbacks)===null||I===void 0||I.forEach(k=>{k(f,m)})})}else{const l=E(u);l.finalities.draft.push((f,m)=>{ft(l),lt(l,Ne,f,m)})}return u}rt.createDraft=Qt,Object.prototype.constructor.toString();function Ee(){return xn()}function Fn(e,t){return e.localeCompare(t)}function zn(){let e=Fn;if(typeof Intl=="object"&&Intl.hasOwnProperty("Collator"))try{e=Intl.Collator("en-US").compare}catch{}return e}zn();function Vn(){const t={__etype:1,__ops:1,create:1,update:1,link:1,unlink:1,delete:1,merge:1,ruleParams:1};return new Set(Object.keys(t))}const Jn=Vn();function Be(e,t,n){const i={__etype:e,__ops:n};return new Proxy(i,{get:(s,r)=>{if(r==="__ops")return n;if(r==="__etype")return e;if(Jn.has(r))return(o,a)=>Be(e,t,[...n,a?[r,e,t,o,a]:[r,e,t,o]])}})}function Qn(e,t){return`lookup__${e}__${JSON.stringify(t)}`}function Gt(e){return e.startsWith("lookup__")}function Ht(e){const[t,n,...i]=e.split("__");return[n,JSON.parse(i.join("__"))]}function Gn(e){return new Proxy({__etype:e},{get(t,n){if(n==="lookup")return(s,r)=>Be(e,Ht(Qn(s,r)),[]);if(n==="__etype")return e;const i=n;return Gt(i)?Be(e,Ht(i),[]):Be(e,i,[])}})}function Bt(){return new Proxy({},{get(e,t){return Gn(t)}})}Bt();function Hn(e){return e.__ops}class q extends Error{constructor(n,i){super(n);d(this,"hint");this.hint=i;const s=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,s),Error.captureStackTrace&&Error.captureStackTrace(this,q),this.name="InstantError"}get[Symbol.toStringTag](){return"InstantError"}}class Ie extends q{constructor(n){var r;const i=((r=n.body)==null?void 0:r.message)||`API Error (${n.status})`;super(i,n.body.hint);d(this,"body");d(this,"status");const s=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,s),Error.captureStackTrace&&Error.captureStackTrace(this,Ie),this.name="InstantAPIError",this.status=n.status,this.body=n.body}get[Symbol.toStringTag](){return"InstantAPIError"}}typeof window<"u"&&typeof window.localStorage<"u"&&(window.localStorage.getItem("devBackend"),window.localStorage.getItem("__instantLogging"),window.localStorage.getItem("__devtoolLocalDash"));const _e="v0.22.150";class ce{constructor(t,n,i,s={indexed:!1,unique:!1}){d(this,"valueType");d(this,"required");d(this,"isIndexed");d(this,"config");d(this,"metadata",{});this.valueType=t,this.required=n,this.isIndexed=i,this.config=s}clientRequired(){return new ce(this.valueType,!1,this.isIndexed,this.config)}optional(){return new ce(this.valueType,!1,this.isIndexed,this.config)}unique(){return new ce(this.valueType,this.required,this.isIndexed,{...this.config,unique:!0})}indexed(){return new ce(this.valueType,this.required,!0,{...this.config,indexed:!0})}}class C extends Error{constructor(t,n){const i=n?`At path '${n}': ${t}`:t;super(i),this.name="QueryValidationError"}}const qt=["where","order","limit","last","first","offset","after","before","fields","aggregate"],Bn=e=>e.valueType||"unknown",Kt=(e,t,n=!1)=>{if(n||e==null)return!0;switch(t){case"string":return typeof e=="string";case"number":return typeof e=="number"&&!isNaN(e);case"boolean":return typeof e=="boolean";case"date":return e instanceof Date||typeof e=="string"||typeof e=="number";default:return!0}},qn=(e,t,n,i,s,r,o)=>{const a=r.valueType==="json",u=(c,l,f)=>{if(!Kt(f,l,a))throw new C(`Invalid value for operator '${c}' on attribute '${i}' in entity '${s}'. Expected ${l}, but received: ${typeof f}`,o)};switch(e){case"in":case"$in":if(!Array.isArray(t))throw new C(`Operator '${e}' for attribute '${i}' in entity '${s}' must be an array, but received: ${typeof t}`,o);for(const c of t)u(e,n,c);break;case"$not":case"$ne":case"$gt":case"$lt":case"$gte":case"$lte":u(e,n,t);break;case"$like":case"$ilike":if(u(e,"string",t),e==="$ilike"&&!r.isIndexed)throw new C(`Operator '${e}' can only be used with indexed attributes, but '${i}' in entity '${s}' is not indexed`,o);break;case"$isNull":u(e,"boolean",t);break;default:throw new C(`Unknown operator '${e}' for attribute '${i}' in entity '${s}'`,o)}},Ce=(e,t,n,i,s)=>{const r=Bn(n),o=n.valueType==="json";if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(o)return;const u=e;for(const[c,l]of Object.entries(u))qn(c,l,r,t,i,n,`${s}.${c}`)}else if(!Kt(e,r,o))throw new C(`Invalid value for attribute '${t}' in entity '${i}'. Expected ${r}, but received: ${typeof e}`,s)},Kn=(e,t,n,i,s)=>{const r=e.split(".");if(r.length<2)throw new C(`Invalid dot notation path '${e}'. Must contain at least one dot.`,s);let o=n;for(let l=0;l<r.length-1;l++){const f=r[l],m=i.entities[o];if(!m)throw new C(`Entity '${o}' does not exist in schema while traversing dot notation path '${e}'.`,s);const y=m.links[f];if(!y){const I=Object.keys(m.links);throw new C(`Link '${f}' does not exist on entity '${o}' in dot notation path '${e}'. Available links: ${I.length>0?I.join(", "):"none"}`,s)}o=y.entityName}const a=r[r.length-1],u=i.entities[o];if(!u)throw new C(`Target entity '${o}' does not exist in schema for dot notation path '${e}'.`,s);if(a==="id"){if(typeof t=="string"&&!x(t))throw new C(`Invalid value for id field in entity '${o}'. Expected a UUID, but received: ${t}`,s);Ce(t,e,new ce("string",!1,!0),n,s);return}const c=u.attrs[a];if(Object.keys(u.links).includes(a)){if(typeof t=="string"&&!x(t))throw new C(`Invalid value for link '${a}' in entity '${o}'. Expected a UUID, but received: ${t}`,s);Ce(t,e,new ce("string",!1,!0),n,s);return}if(!c){const l=Object.keys(u.attrs);throw new C(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${l.length>0?l.join(", ")+", id":"id"}`,s)}Ce(t,e,c,n,s)},Xt=(e,t,n,i)=>{for(const[s,r]of Object.entries(e)){if(s==="or"||s==="and"){if(Array.isArray(r))for(const c of r)typeof c=="object"&&c!==null&&Xt(c,t,n,`${i}.${s}[${c}]`);continue}if(s==="id"){Ce(r,"id",new ce("string",!1,!0),t,`${i}.id`);continue}if(s.includes(".")){Kn(s,r,t,n,`${i}.${s}`);continue}const o=n.entities[t];if(!o)continue;const a=o.attrs[s],u=o.links[s];if(!a&&!u){const c=Object.keys(o.attrs),l=Object.keys(o.links);throw new C(`Attribute or link '${s}' does not exist on entity '${t}'. Available attributes: ${c.length>0?c.join(", "):"none"}. Available links: ${l.length>0?l.join(", "):"none"}`,`${i}.${s}`)}if(a)Ce(r,s,a,t,`${i}.${s}`);else if(u){if(typeof r=="string"&&!x(r))throw new C(`Invalid value for link '${s}' in entity '${t}'. Expected a UUID, but received: ${r}`,`${i}.${s}`);const c=new ce("string",!1,!0);Ce(r,s,c,t,`${i}.${s}`)}}},Xn=(e,t,n,i,s=0)=>{for(const o of Object.keys(e))if(!qt.includes(o))throw new C(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${qt.join(", ")}. Found: ${o}`,i);const r=["offset","before","after","first","last"];for(const o of r)if(e[o]!==void 0&&s>0)throw new C(`'${o}' can only be used on top-level namespaces. It cannot be used in nested queries.`,i);if(e.where&&n){if(typeof e.where!="object"||e.where===null)throw new C(`'where' clause must be an object in entity '${t}', but received: ${typeof e.where}`,i?`${i}.where`:void 0);Xt(e.where,t,n,i?`${i}.where`:"where")}},Yt=(e,t,n,i,s=0)=>{var r;if(!e||typeof e!="object")throw new C(`Query part for entity '${t}' must be an object, but received: ${typeof e}`,i);for(const o of Object.keys(e))if(o!=="$"){if(n&&!(o in n.entities[t].links)){const u=Object.keys(n.entities[t].links);throw new C(`Link '${o}' does not exist on entity '${t}'. Available links: ${u.length>0?u.join(", "):"none"}`,`${i}.${o}`)}const a=e[o];if(typeof a=="object"&&a!==null){const u=(r=n==null?void 0:n.entities[t].links[o])==null?void 0:r.entityName;u&&Yt(a,u,n,`${i}.${o}`,s+1)}}else{const a=e[o];if(typeof a!="object"||a===null)throw new C(`Query parameter '$' must be an object in entity '${t}', but received: ${typeof a}`,`${i}.$`);Xn(a,t,n,`${i}.$`,s)}},Zt=(e,t)=>{if(typeof e!="object"||e===null)throw new C(`Query must be an object, but received: ${typeof e}${e===null?" (null)":""}`);if(Array.isArray(e))throw new C(`Query must be an object, but received: ${typeof e}`);const n=e;for(const i of Object.keys(n)){if(Array.isArray(e[i]))throw new C(`Query keys must be strings, but found key of type: ${typeof i}`,i);if(typeof i!="string")throw new C(`Query keys must be strings, but found key of type: ${typeof i}`,i);if(i!=="$$ruleParams"){if(t&&!t.entities[i]){const s=Object.keys(t.entities);throw new C(`Entity '${i}' does not exist in schema. Available entities: ${s.length>0?s.join(", "):"none"}`,i)}Yt(n[i],i,t,i,0)}}},en=e=>typeof e!="string"?!1:Gt(e)?!0:x(e);class K extends Error{constructor(t){super(t),this.name="TransactionValidationError"}}const tn=e=>e.length>0?e.join(", "):"none",Yn=(e,t)=>new K(`Entity '${e}' does not exist in schema. Available entities: ${tn(t)}`),pt={string:e=>typeof e=="string",number:e=>typeof e=="number"&&!isNaN(e),boolean:e=>typeof e=="boolean",date:e=>e instanceof Date||typeof e=="string"||typeof e=="number",json:()=>!0},Zn=(e,t)=>{var n;return e==null?!0:((n=pt[t.valueType])==null?void 0:n.call(pt,e))??!1},nn=(e,t)=>{const n=t.entities[e];if(!n)throw Yn(e,Object.keys(t.entities));return n},mt=(e,t,n)=>{const i=nn(e,n);if(typeof t!="object"||t===null)throw new K(`Arguments for data operation on entity '${e}' must be an object, but received: ${typeof t}`);for(const[s,r]of Object.entries(t)){if(s==="id")continue;const o=i.attrs[s];if(o&&!Zn(r,o))throw new K(`Invalid value for attribute '${s}' in entity '${e}'. Expected ${o.valueType}, but received: ${typeof r}`)}},sn=(e,t,n)=>{const i=nn(e,n);if(typeof t!="object"||t===null)throw new K(`Arguments for link operation on entity '${e}' must be an object, but received: ${typeof t}`);for(const[s,r]of Object.entries(t)){if(!i.links[s]){const a=Object.keys(i.links);throw new K(`Link '${s}' does not exist on entity '${e}'. Available links: ${tn(a)}`)}if(r!=null){if(Array.isArray(r)){for(const a of r)if(!en(a))throw new K(`Invalid entity ID in link '${s}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`)}else if(!en(r))throw new K(`Invalid UUID in link '${s}' for entity '${e}'. Expected a UUID, but received: ${r}`)}}},ei={create:mt,update:mt,merge:mt,link:sn,unlink:sn,delete:()=>{}},ti=(e,t)=>{if(!t)return;const[n,i,s,r]=e;if(!Array.isArray(s)&&!x(s))throw new K(`Invalid id for entity '${i}'. Expected a UUID, but received: ${s}`);if(typeof i!="string")throw new K(`Entity name must be a string, but received: ${typeof i}`);const o=ei[n];o&&r!==void 0&&o(i,r,t)},ni=(e,t)=>{const n=Array.isArray(e)?e:[e];for(const i of n){if(!i||typeof i!="object")throw new K(`Transaction chunk must be an object, but received: ${typeof i}`);if(!Array.isArray(i.__ops))throw new K(`Transaction chunk must have __ops array, but received: ${typeof i.__ops}`);for(const s of i.__ops){if(!Array.isArray(s))throw new K(`Transaction operation must be an array, but received: ${typeof s}`);ti(s,t)}}};let ii=0;class si{constructor(t,n,i){d(this,"type","sse");d(this,"initParams",null);d(this,"sendQueue",[]);d(this,"sendPromise");d(this,"closeFired",!1);d(this,"sseInitTimeout");d(this,"ES");d(this,"messageUrl");d(this,"conn");d(this,"url");d(this,"id");d(this,"onopen");d(this,"onmessage");d(this,"onclose");d(this,"onerror");this.id=`${this.type}_${ii++}`,this.url=n,this.messageUrl=i||this.url,this.ES=t,this.conn=new t(n),this.sseInitTimeout=setTimeout(()=>{this.initParams||this.handleError()},1e4),this.conn.onmessage=s=>{const r=JSON.parse(s.data);if(Array.isArray(r))for(const o of r)this.handleMessage(o);else this.handleMessage(r)},this.conn.onerror=s=>{this.handleError()}}handleMessage(t){if(t.op==="sse-init"){this.initParams={machineId:t["machine-id"],sessionId:t["session-id"],sseToken:t["sse-token"]},this.onopen&&this.onopen({target:this}),clearTimeout(this.sseInitTimeout);return}this.onmessage&&this.onmessage({target:this,message:t})}handleError(){try{this.onerror&&this.onerror({target:this})}finally{this.handleClose()}}handleClose(){this.conn.close(),this.onclose&&!this.closeFired&&(this.closeFired=!0,this.onclose({target:this}))}async postMessages(t){var n,i,s;try{(await fetch(this.messageUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({machine_id:(n=this.initParams)==null?void 0:n.machineId,session_id:(i=this.initParams)==null?void 0:i.sessionId,sse_token:(s=this.initParams)==null?void 0:s.sseToken,messages:t})})).ok||this.handleError()}catch{this.handleError()}}async flushQueue(){if(this.sendPromise||!this.sendQueue.length)return;const t=this.sendQueue;this.sendQueue=[];const n=this.postMessages(t);this.sendPromise=n,n.then(()=>{this.sendPromise=null,this.flushQueue()})}send(t){if(!this.isOpen()||!this.initParams)throw this.isConnecting()?new Error("Failed to execute 'send' on 'EventSource': Still in CONNECTING state."):this.conn.readyState===this.ES.CLOSED?new Error("EventSource is already in CLOSING or CLOSED state."):new Error("EventSource is in invalid state.");this.sendQueue.push(t),this.flushQueue()}isOpen(){return this.conn.readyState===this.ES.OPEN&&this.initParams!==null}isConnecting(){return this.conn.readyState===this.ES.CONNECTING||this.conn.readyState===this.ES.OPEN&&this.initParams===null}close(){this.handleClose()}}var rn;(function(e){e.InitialSyncBatch="InitialSyncBatch",e.InitialSyncComplete="InitialSyncComplete",e.LoadFromStorage="LoadFromStorage",e.SyncTransaction="SyncTransaction",e.Error="Error"})(rn||(rn={}));function ri({WStream:e,opts:t,startStream:n,appendStream:i,registerStream:s}){const r=t.clientId;let o=null,a=null,u=null;const c=Ee();let l=!1,f=!1;const m=[],y=[],I=[];let w=!1,h=0,O=0;const b=[],k=new TextEncoder;function te(){f=!0;for(const p of m)p(a??void 0)}function D(p){return m.push(p),f&&p(a??void 0),()=>{const v=m.indexOf(p);v!==-1&&m.splice(v,1)}}function z(p){return I.push(p),()=>{const v=I.indexOf(p);v!==-1&&I.splice(v,1)}}t.waitUntil&&t.waitUntil(new Promise(p=>{I.push(p)}));function Q(){for(const p of I)try{p()}catch{}}function le(p){return y.push(p),o&&p(o),()=>{const v=y.indexOf(p);v!==-1&&y.splice(v,1)}}function oe(p){o=p;for(const v of y)v(o)}function $e(){w=!0}function Rt(p){let v=h,V=0,G=0;for(const{byteLen:ie}of b){const de=v+ie;if(de>p)break;v=de,V++,G+=ie}V>0&&(h+=G,O-=G,b.splice(0,V))}function ne(p,v){a=v,te(),p.error(v),Q()}async function ae(){const p=await n({clientId:r,reconnectToken:c,ruleParams:t.ruleParams});switch(p.type){case"ok":{const{streamId:v,offset:V}=p;o=v,Rt(V),b.length&&i({streamId:v,chunks:b.map(G=>G.chunk),offset:h}),w=!1;break}case"disconnect":{$e();break}case"error":{u&&ne(u,p.error);break}}}function B(){$e(),ae()}function Ve({offset:p,done:v}){Rt(p),v&&(l=!0,Q())}function zi(p){return l?(ne(p,new q("Stream has been closed.")),null):o||(ne(p,new q("Stream has not been initialized.")),null)}async function Vi(p){u=p;let v=!0,V=0;for(;v;){let G=Date.now()+Math.min(15e3,500*(V-1));v=!1;const ie=await n({clientId:t.clientId,reconnectToken:c,ruleParams:t.ruleParams});switch(ie.type){case"ok":{const{streamId:de,offset:At}=ie;if(At!==0){const ke=new q("Write stream is corrupted");ne(p,ke);return}oe(de),s(de,{onDisconnect:$e,onFlush:Ve,onConnectionReconnect:ae,onAppendFailed:B}),w=!1;return}case"disconnect":{v=!0,$e(),V++,await new Promise(de=>{setTimeout(de,Math.max(0,G-Date.now()))});break}case"error":{ne(p,ie.error);return}}}}class Ji extends e{constructor(v,V){super(v,V)}async streamId(){return o||new Promise((v,V)=>{const G=[],ie=()=>{for(const ke of G)ke()},de=ke=>{v(ke),ie()},At=ke=>{V(ke||new q("Stream is closed.")),ie()};G.push(le(de)),G.push(D(At))})}}return{stream:new Ji({async start(p){try{await Vi(p)}catch(v){ne(p,v)}},write(p,v){const V=zi(v);if(V){const G=k.encode(p).length;b.push({chunk:p,byteLen:G});const ie=h+O;O+=G,w||i({streamId:V,chunks:[p],offset:ie})}},close(){o?i({streamId:o,chunks:[],offset:h+O,isDone:!0}):Q(),te()},abort(p){o?i({streamId:o,chunks:[],offset:h+O,isDone:!0,abortReason:p}):Q(),te()}}),addCompleteCb:z,closed(){return f}}}class oi{constructor(){d(this,"items",[]);d(this,"resolvers",[]);d(this,"isClosed",!1)}push(t){if(this.isClosed)return;const n=this.resolvers.shift();n?n({value:t,done:!1}):this.items.push(t)}close(){for(this.isClosed=!0;this.resolvers.length>0;)this.resolvers.shift()({value:void 0,done:!0})}async*[Symbol.asyncIterator](){for(;;)if(this.items.length>0)yield this.items.shift();else{if(this.isClosed)return;{const{value:t,done:n}=await new Promise(i=>{this.resolvers.push(i)});if(n||!t)return;yield t}}}}function ai({RStream:e,opts:t,startStream:n,cancelStream:i}){let s=t.byteOffset||0,r=!1;const o=new TextDecoder("utf-8"),a=new TextEncoder;let u,c=!1;const l=[];function f(){c=!0;for(const b of l)b()}function m(b){return l.push(b),()=>{const k=l.indexOf(b);k!==-1&&l.splice(k,1)}}function y(b,k){b.error(k),f()}let I=0;async function w(b,k){u=Ee();const te={...b||{},eventId:u};for await(const D of n(te)){if(r)return;if(D.type==="reconnect")return{retry:!0};if(D.type==="error"){y(k,D.error);return}if(D.offset>s){y(k,new q("Stream is corrupted.")),r=!0;return}let z=s-D.offset;if(D.files&&D.files.length){const Q=new AbortController;let le=fetch(D.files[0].url,{signal:Q.signal});for(let oe=0;oe<D.files.length;oe++){const $e=D.files[oe+1],ne=await le;if($e&&(le=fetch($e.url,{signal:Q.signal})),!ne.ok){if(I++,I>10){y(k,new q("Unable to process stream."));return}return{retry:!0}}if(ne.body)for await(const ae of ne.body){if(r){Q.abort();return}let B=ae;if(z>0&&(B=ae.subarray(z),z-=ae.length-B.length),!B.length)continue;s+=B.length;const Ve=o.decode(B);k.enqueue(Ve)}else{const ae=await ne.arrayBuffer();let B=ae;if(r){Q.abort();return}if(z>0&&(B=new Uint8Array(ae).subarray(z),z-=ae.byteLength-B.length),!B.byteLength)continue;s+=B.byteLength;const Ve=o.decode(B);k.enqueue(Ve)}}}if(I=0,D.content){let Q=D.content,le=a.encode(D.content);if(z>0){const oe=le.subarray(z);if(z-=le.length-oe.length,!oe.length)continue;le=oe,Q=o.decode(oe)}s+=le.length,k.enqueue(Q)}}}async function h(b){let k=!0,te=0;for(;k;){k=!1;let D=Date.now()+Math.min(15e3,500*(te-1));const z=await w({...t,offset:s},b);z!=null&&z.retry&&(k=!0,te++,D<Date.now()-3e5&&(te=0),await new Promise(Q=>{setTimeout(Q,Math.max(0,D-Date.now()))}))}!r&&!c&&(b.close(),f())}return{stream:new e({start(b){h(b)},cancel(b){r=!0,u&&i({eventId:u}),f()}}),addCloseCb:m,closed(){return c}}}class ci{constructor({WStream:t,RStream:n,trySend:i,log:s}){d(this,"trySend");d(this,"WStream");d(this,"RStream");d(this,"writeStreams",{});d(this,"startWriteStreamCbs",{});d(this,"readStreamIterators",{});d(this,"log");d(this,"activeStreams",new Set);this.WStream=t,this.RStream=n,this.trySend=i,this.log=s}createWriteStream(t){const{stream:n,addCompleteCb:i}=ri({WStream:this.WStream,startStream:this.startWriteStream.bind(this),appendStream:this.appendStream.bind(this),registerStream:this.registerWriteStream.bind(this),opts:t});return this.activeStreams.add(n),i(()=>{this.activeStreams.delete(n)}),n}createReadStream(t){const{stream:n,addCloseCb:i}=ai({RStream:this.RStream,opts:t,startStream:this.startReadStream.bind(this),cancelStream:this.cancelReadStream.bind(this)});return this.activeStreams.add(n),i(()=>{this.activeStreams.delete(n)}),n}startWriteStream(t){const n=Ee();let i=null;const s=new Promise(o=>{i=o});this.startWriteStreamCbs[n]=i;const r={op:"start-stream","client-id":t.clientId,"reconnect-token":t.reconnectToken};return t.ruleParams&&(r["rule-params"]=t.ruleParams),this.trySend(n,r),s}registerWriteStream(t,n){this.writeStreams[t]=n}appendStream({streamId:t,chunks:n,isDone:i,offset:s,abortReason:r}){const o={op:"append-stream","stream-id":t,chunks:n,offset:s,done:!!i};r&&(o["abort-reason"]=r),this.trySend(Ee(),o)}onAppendFailed(t){const n=this.writeStreams[t["stream-id"]];n&&n.onAppendFailed()}onStartStreamOk(t){const n=this.startWriteStreamCbs[t["client-event-id"]];if(!n){this.log.info("No stream for start-stream-ok",t);return}n({type:"ok",streamId:t["stream-id"],offset:t.offset}),delete this.startWriteStreamCbs[t["client-event-id"]]}onStreamFlushed(t){const n=t["stream-id"],i=this.writeStreams[n];if(!i){this.log.info("No stream cbs for stream-flushed",t);return}i.onFlush({offset:t.offset,done:t.done}),t.done&&delete this.writeStreams[n]}startReadStream({eventId:t,clientId:n,streamId:i,offset:s,ruleParams:r}){const o={op:"subscribe-stream"};if(!i&&!n)throw new Error("Must provide one of streamId or clientId to subscribe to the stream.");i&&(o["stream-id"]=i),n&&(o["client-id"]=n),s&&(o.offset=s),r&&(o["rule-params"]=r);const a=new oi;return this.readStreamIterators[t]=a,this.trySend(t,o),a}cancelReadStream({eventId:t}){const n={op:"unsubscribe-stream","subscribe-event-id":t};this.trySend(Ee(),n),delete this.readStreamIterators[t]}onStreamAppend(t){var s;const n=t["client-event-id"],i=this.readStreamIterators[n];if(!i){this.log.info("No iterator for read stream",t);return}if(t.error){t.retry?i.push({type:"reconnect"}):i.push({type:"error",error:new q(t.error)}),i.close(),delete this.readStreamIterators[n];return}((s=t.files)!=null&&s.length||t.content)&&i.push({type:"append",offset:t.offset,files:t.files,content:t.content}),t.done&&(i.close(),delete this.readStreamIterators[n])}onConnectionStatusChange(t){for(const n of Object.values(this.startWriteStreamCbs))n({type:"disconnect"});if(this.startWriteStreamCbs={},t!==ui.AUTHENTICATED)for(const{onDisconnect:n}of Object.values(this.writeStreams))n();else{for(const{onConnectionReconnect:n}of Object.values(this.writeStreams))n();for(const n of Object.values(this.readStreamIterators))n.push({type:"reconnect"}),n.close();this.readStreamIterators={}}}onRecieveError(t){const n=t["original-event"];switch(n.op){case"append-stream":{const i=n["stream-id"],s=this.writeStreams[i];s==null||s.onAppendFailed();break}case"start-stream":{const i=t["client-event-id"],s=this.startWriteStreamCbs[i];s&&(s({type:"error",error:new q(t.message||"Unknown error",t.hint)}),delete this.startWriteStreamCbs[i]);break}case"subscribe-stream":{const i=t["client-event-id"],s=this.readStreamIterators[i];s&&(s.push({type:"error",error:new q(t.message||"Unknown error",t.hint)}),s.close(),delete this.readStreamIterators[i]);break}}}hasActiveStreams(){return this.activeStreams.size>0}}const ui={AUTHENTICATED:"authenticated"};function fi(){return globalThis.__instantDbSchemaHashStore=globalThis.__instantDbSchemaHashStore??new WeakMap,globalThis.__instantDbSchemaHashStore}function li(){return globalThis.__instantDbStore=globalThis.__instantDbStore??{},globalThis.__instantDbStore}li(),fi();class on extends Error{constructor(t,n){super(t),this.name="ParseError",this.type=n.type,this.field=n.field,this.value=n.value,this.line=n.line}}function yt(e){}function di(e){if(typeof e=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:t=yt,onError:n=yt,onRetry:i=yt,onComment:s}=e;let r="",o=!0,a,u="",c="";function l(w){const h=o?w.replace(/^\xEF\xBB\xBF/,""):w,[O,b]=hi(`${r}${h}`);for(const k of O)f(k);r=b,o=!1}function f(w){if(w===""){y();return}if(w.startsWith(":")){s&&s(w.slice(w.startsWith(": ")?2:1));return}const h=w.indexOf(":");if(h!==-1){const O=w.slice(0,h),b=w[h+1]===" "?2:1,k=w.slice(h+b);m(O,k,w);return}m(w,"",w)}function m(w,h,O){switch(w){case"event":c=h;break;case"data":u=`${u}${h}
|
|
1
|
+
(function($,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):($=typeof globalThis<"u"?globalThis:$||self,_($.instant={}))})(this,function($){"use strict";var Qi=Object.defineProperty;var wn=$=>{throw TypeError($)};var Gi=($,_,x)=>_ in $?Qi($,_,{enumerable:!0,configurable:!0,writable:!0,value:x}):$[_]=x;var d=($,_,x)=>Gi($,typeof _!="symbol"?_+"":_,x),Pt=($,_,x)=>_.has($)||wn("Cannot "+x);var g=($,_,x)=>(Pt($,_,"read from private field"),x?x.call($):_.get($)),X=($,_,x)=>_.has($)?wn("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add($):_.set($,x),he=($,_,x,R)=>(Pt($,_,"write to private field"),R?R.call($,x):_.set($,x),x),Y=($,_,x)=>(Pt($,_,"access private method"),x);var je,N,Oe,W,F,U,In,it,vn,On,$n,Ze,et,tt,jt,kn,nt;const _=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function x(e){return typeof e=="string"&&_.test(e)}const R=[];for(let e=0;e<256;++e)R.push((e+256).toString(16).slice(1));function En(e,t=0){return(R[e[t+0]]+R[e[t+1]]+R[e[t+2]]+R[e[t+3]]+"-"+R[e[t+4]]+R[e[t+5]]+"-"+R[e[t+6]]+R[e[t+7]]+"-"+R[e[t+8]]+R[e[t+9]]+"-"+R[e[t+10]]+R[e[t+11]]+R[e[t+12]]+R[e[t+13]]+R[e[t+14]]+R[e[t+15]]).toLowerCase()}let st;const _n=new Uint8Array(16);function Cn(){if(!st){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");st=crypto.getRandomValues.bind(crypto)}return st(_n)}const Mt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function xn(e,t,n){var s;if(Mt.randomUUID&&!e)return Mt.randomUUID();e=e||{};const i=e.random??((s=e.rng)==null?void 0:s.call(e))??Cn();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,En(i)}const P={Remove:"remove",Replace:"replace",Add:"add"},Ut=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),Je=Symbol.iterator,Z={mutable:"mutable",immutable:"immutable"},rt={};function Me(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Dt(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const i=Reflect.getOwnPropertyDescriptor(n,t);if(i)return i;n=Reflect.getPrototypeOf(n)}}}function Nt(e){return Object.getPrototypeOf(e)===Set.prototype}function Lt(e){return Object.getPrototypeOf(e)===Map.prototype}function H(e){var t;return(t=e.copy)!==null&&t!==void 0?t:e.original}function ot(e){return!!E(e)}function E(e){return typeof e!="object"?null:e==null?void 0:e[Ut]}function at(e){var t;const n=E(e);return n?(t=n.copy)!==null&&t!==void 0?t:n.original:e}function ge(e,t){if(!e||typeof e!="object")return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(t!=null&&t.mark)&&((n=t.mark(e,Z))===Z.immutable||typeof n=="function")}function Wt(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,i=E(pe(n,e.key));if(i!==null&&(i==null?void 0:i.original)!==e.original)return null;const s=e.parent.type===3,r=s?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(s&&n.size>r||Me(n,r)))return null;t.push(r)}if(e.parent)return Wt(e.parent,t);t.reverse();try{Tn(e.copy,t)}catch{return null}return t}function Ue(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function pe(e,t){return Ue(e)===2?e.get(t):e[t]}function ct(e,t,n){Ue(e)===2?e.set(t,n):e[t]=n}function ut(e,t){const n=E(e);return(n?H(n):e)[t]}function we(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function Se(e,t){return t?e:[""].concat(e).map(n=>{const i=`${n}`;return i.indexOf("/")===-1&&i.indexOf("~")===-1?i:i.replace(/~/g,"~0").replace(/\//g,"~1")}).join("/")}function Tn(e,t){for(let n=0;n<t.length-1;n+=1){const i=t[n];if(e=pe(Ue(e)===3?Array.from(e):e,i),typeof e!="object")throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}return e}function Rn(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach(n=>{let i=Reflect.getOwnPropertyDescriptor(e,n);if(i.enumerable&&i.configurable&&i.writable){t[n]=e[n];return}i.writable||(i.writable=!0,i.configurable=!0),(i.get||i.set)&&(i={configurable:!0,writable:!0,enumerable:i.enumerable,value:e[n]}),Reflect.defineProperty(t,n,i)}),t}const An=Object.prototype.propertyIsEnumerable;function Pn(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!Nt(e)){const i=Object.getPrototypeOf(e).constructor;return new i(e.values())}return Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values())}else if(e instanceof Map){if(!Lt(e)){const i=Object.getPrototypeOf(e).constructor;return new i(e)}return new Map(e)}else if(t!=null&&t.mark&&(n=t.mark(e,Z),n!==void 0)&&n!==Z.mutable){if(n===Z.immutable)return Rn(e);if(typeof n=="function"){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}else if(typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype){const i={};return Object.keys(e).forEach(s=>{i[s]=e[s]}),Object.getOwnPropertySymbols(e).forEach(s=>{An.call(e,s)&&(i[s]=e[s])}),i}else throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function L(e){e.copy||(e.copy=Pn(e.original,e.options))}function De(e){if(!ge(e))return at(e);if(Array.isArray(e))return e.map(De);if(e instanceof Map){const n=Array.from(e.entries()).map(([i,s])=>[i,De(s)]);if(!Lt(e)){const i=Object.getPrototypeOf(e).constructor;return new i(n)}return new Map(n)}if(e instanceof Set){const n=Array.from(e).map(De);if(!Nt(e)){const i=Object.getPrototypeOf(e).constructor;return new i(n)}return new Set(n)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=De(e[n]);return t}function Qe(e){return ot(e)?De(e):e}function se(e){var t;e.assignedMap=(t=e.assignedMap)!==null&&t!==void 0?t:new Map,e.operated||(e.operated=!0,e.parent&&se(e.parent))}function jn(e,t){const n=Ue(e);if(n===0)Reflect.ownKeys(e).forEach(i=>{t(i,e[i],e)});else if(n===1){let i=0;for(const s of e)t(i,s,e),i+=1}else e.forEach((i,s)=>t(s,i,e))}function Ft(e,t,n){if(ot(e)||!ge(e,n)||t.has(e)||Object.isFrozen(e))return;const i=e instanceof Set,s=i?new Map:void 0;if(t.add(e),jn(e,(r,o)=>{var a;if(ot(o)){const u=E(o);L(u);const c=!((a=u.assignedMap)===null||a===void 0)&&a.size||u.operated?u.copy:u.original;ct(i?s:e,r,c)}else Ft(o,t,n)}),s){const r=e,o=Array.from(r);r.clear(),o.forEach(a=>{r.add(s.has(a)?s.get(a):a)})}}function Mn(e,t){const n=e.type===3?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&Ft(pe(n,t),e.finalities.handledSet,e.options)}function ft(e){e.type===3&&e.copy&&(e.copy.clear(),e.setMap.forEach(t=>{e.copy.add(at(t))}))}function lt(e,t,n,i){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&i){const r=Wt(e);r&&t(e,r,n,i)}e.finalized=!0}}function dt(e,t,n,i){const s=E(n);s&&(s.callbacks||(s.callbacks=[]),s.callbacks.push((r,o)=>{var a;const u=e.type===3?e.setMap:e.copy;if(we(pe(u,t),n)){let c=s.original;s.copy&&(c=s.copy),ft(e),lt(e,i,r,o),e.options.enableAutoFreeze&&(e.options.updatedValues=(a=e.options.updatedValues)!==null&&a!==void 0?a:new WeakMap,e.options.updatedValues.set(c,s.original)),ct(u,t,c)}}),e.options.enableAutoFreeze&&s.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),ge(n,e.options)&&e.finalities.draft.push(()=>{const r=e.type===3?e.setMap:e.copy;we(pe(r,t),n)&&Mn(e,t)})}function Un(e,t,n,i,s){let{original:r,assignedMap:o,options:a}=e,u=e.copy;u.length<r.length&&([r,u]=[u,r],[n,i]=[i,n]);for(let c=0;c<r.length;c+=1)if(o.get(c.toString())&&u[c]!==r[c]){const l=t.concat([c]),f=Se(l,s);n.push({op:P.Replace,path:f,value:Qe(u[c])}),i.push({op:P.Replace,path:f,value:Qe(r[c])})}for(let c=r.length;c<u.length;c+=1){const l=t.concat([c]),f=Se(l,s);n.push({op:P.Add,path:f,value:Qe(u[c])})}if(r.length<u.length){const{arrayLengthAssignment:c=!0}=a.enablePatches;if(c){const l=t.concat(["length"]),f=Se(l,s);i.push({op:P.Replace,path:f,value:r.length})}else for(let l=u.length;r.length<l;l-=1){const f=t.concat([l-1]),m=Se(f,s);i.push({op:P.Remove,path:m})}}}function Dn({original:e,copy:t,assignedMap:n},i,s,r,o){n.forEach((a,u)=>{const c=pe(e,u),l=Qe(pe(t,u)),f=a?Me(e,u)?P.Replace:P.Add:P.Remove;if(we(c,l)&&f===P.Replace)return;const m=i.concat(u),y=Se(m,o);s.push(f===P.Remove?{op:f,path:y}:{op:f,path:y,value:l}),r.push(f===P.Add?{op:P.Remove,path:y}:f===P.Remove?{op:P.Add,path:y,value:c}:{op:P.Replace,path:y,value:c})})}function Nn({original:e,copy:t},n,i,s,r){let o=0;e.forEach(a=>{if(!t.has(a)){const u=n.concat([o]),c=Se(u,r);i.push({op:P.Remove,path:c,value:a}),s.unshift({op:P.Add,path:c,value:a})}o+=1}),o=0,t.forEach(a=>{if(!e.has(a)){const u=n.concat([o]),c=Se(u,r);i.push({op:P.Add,path:c,value:a}),s.unshift({op:P.Remove,path:c,value:a})}o+=1})}function Ne(e,t,n,i){const{pathAsArray:s=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return Dn(e,t,n,i,s);case 1:return Un(e,t,n,i,s);case 3:return Nn(e,t,n,i,s)}}const Ge=(e,t,n=!1)=>{if(typeof e=="object"&&e!==null&&(!ge(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},ht={get size(){return H(E(this)).size},has(e){return H(E(this)).has(e)},set(e,t){const n=E(this),i=H(n);return(!i.has(e)||!we(i.get(e),t))&&(L(n),se(n),n.assignedMap.set(e,!0),n.copy.set(e,t),dt(n,e,t,Ne)),this},delete(e){if(!this.has(e))return!1;const t=E(this);return L(t),se(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=E(this);if(this.size){L(e),se(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){const n=E(this);H(n).forEach((i,s)=>{e.call(t,this.get(s),s,this)})},get(e){var t,n;const i=E(this),s=H(i).get(e),r=((n=(t=i.options).mark)===null||n===void 0?void 0:n.call(t,s,Z))===Z.mutable;if(i.options.strict&&Ge(s,i.options,r),r||i.finalized||!ge(s,i.options)||s!==i.original.get(e))return s;const o=rt.createDraft({original:s,parentDraft:i,key:e,finalities:i.finalities,options:i.options});return L(i),i.copy.set(e,o),o},keys(){return H(E(this)).keys()},values(){const e=this.keys();return{[Je]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[Je]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[Je](){return this.entries()}},Ln=Reflect.ownKeys(ht),zt=(e,t,{isValuesIterator:n})=>()=>{var i,s;const r=t.next();if(r.done)return r;const o=r.value;let a=e.setMap.get(o);const u=E(a),c=((s=(i=e.options).mark)===null||s===void 0?void 0:s.call(i,a,Z))===Z.mutable;if(e.options.strict&&Ge(o,e.options,c),!c&&!u&&ge(o,e.options)&&!e.finalized&&e.original.has(o)){const l=rt.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,l),a=l}else u&&(a=u.proxy);return{done:!1,value:n?a:[a,a]}},He={get size(){return E(this).setMap.size},has(e){const t=E(this);if(t.setMap.has(e))return!0;L(t);const n=E(e);return!!(n&&t.setMap.has(n.original))},add(e){const t=E(this);return this.has(e)||(L(t),se(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),dt(t,e,e,Ne)),this},delete(e){if(!this.has(e))return!1;const t=E(this);L(t),se(t);const n=E(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=E(this);L(e),se(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=E(this);L(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:zt(e,t,{isValuesIterator:!0})}},entries(){const e=E(this);L(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:zt(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[Je](){return this.values()},forEach(e,t){const n=this.values();let i=n.next();for(;!i.done;)e.call(t,i.value,i.value,this),i=n.next()}};Set.prototype.difference&&Object.assign(He,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const Wn=Reflect.ownKeys(He),Vt=new WeakSet,Jt={get(e,t,n){var i,s;const r=(i=e.copy)===null||i===void 0?void 0:i[t];if(r&&Vt.has(r))return r;if(t===Ut)return e;let o;if(e.options.mark){const c=t==="size"&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(o=e.options.mark(c,Z),o===Z.mutable)return e.options.strict&&Ge(c,e.options,!0),c}const a=H(e);if(a instanceof Map&&Ln.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(ht,"size").get.call(e.proxy);const c=ht[t];if(c)return c.bind(e.proxy)}if(a instanceof Set&&Wn.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(He,"size").get.call(e.proxy);const c=He[t];if(c)return c.bind(e.proxy)}if(!Me(a,t)){const c=Dt(a,t);return c?"value"in c?c.value:(s=c.get)===null||s===void 0?void 0:s.call(e.proxy):void 0}const u=a[t];if(e.options.strict&&Ge(u,e.options),e.finalized||!ge(u,e.options))return u;if(u===ut(e.original,t)){if(L(e),e.copy[t]=Qt({original:e.original[t],parentDraft:e,key:e.type===1?Number(t):t,finalities:e.finalities,options:e.options}),typeof o=="function"){const c=E(e.copy[t]);return L(c),se(c),c.copy}return e.copy[t]}return u},set(e,t,n){var i;if(e.type===3||e.type===2)throw new Error("Map/Set draft does not support any property assignment.");let s;if(e.type===1&&t!=="length"&&!(Number.isInteger(s=Number(t))&&s>=0&&(t===0||s===0||String(s)===String(t))))throw new Error("Only supports setting array indices and the 'length' property.");const r=Dt(H(e),t);if(r!=null&&r.set)return r.set.call(e.proxy,n),!0;const o=ut(H(e),t),a=E(o);return a&&we(a.original,n)?(e.copy[t]=n,e.assignedMap=(i=e.assignedMap)!==null&&i!==void 0?i:new Map,e.assignedMap.set(t,!1),!0):(we(n,o)&&(n!==void 0||Me(e.original,t))||(L(e),se(e),Me(e.original,t)&&we(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,dt(e,t,n,Ne)),!0)},has(e,t){return t in H(e)},ownKeys(e){return Reflect.ownKeys(H(e))},getOwnPropertyDescriptor(e,t){const n=H(e),i=Reflect.getOwnPropertyDescriptor(n,t);return i&&{writable:!0,configurable:e.type!==1||t!=="length",enumerable:i.enumerable,value:n[t]}},getPrototypeOf(e){return Reflect.getPrototypeOf(e.original)},setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return e.type===1?Jt.set.call(this,e,t,void 0,e.proxy):(ut(e.original,t)!==void 0||t in e.original?(L(e),se(e),e.assignedMap.set(t,!1)):(e.assignedMap=(n=e.assignedMap)!==null&&n!==void 0?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function Qt(e){const{original:t,parentDraft:n,key:i,finalities:s,options:r}=e,o=Ue(t),a={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:s,options:r,setMap:o===3?new Map(t.entries()):void 0};(i||"key"in e)&&(a.key=i);const{proxy:u,revoke:c}=Proxy.revocable(o===1?Object.assign([],a):a,Jt);if(s.revoke.push(c),Vt.add(u),a.proxy=u,n){const l=n;l.finalities.draft.push((f,m)=>{var y,I;const w=E(u);let h=l.type===3?l.setMap:l.copy;const O=pe(h,i),b=E(O);if(b){let k=b.original;b.operated&&(k=at(O)),ft(b),lt(b,Ne,f,m),l.options.enableAutoFreeze&&(l.options.updatedValues=(y=l.options.updatedValues)!==null&&y!==void 0?y:new WeakMap,l.options.updatedValues.set(k,b.original)),ct(h,i,k)}(I=w.callbacks)===null||I===void 0||I.forEach(k=>{k(f,m)})})}else{const l=E(u);l.finalities.draft.push((f,m)=>{ft(l),lt(l,Ne,f,m)})}return u}rt.createDraft=Qt,Object.prototype.constructor.toString();function Ee(){return xn()}function Fn(e,t){return e.localeCompare(t)}function zn(){let e=Fn;if(typeof Intl=="object"&&Intl.hasOwnProperty("Collator"))try{e=Intl.Collator("en-US").compare}catch{}return e}zn();function Vn(){const t={__etype:1,__ops:1,create:1,update:1,link:1,unlink:1,delete:1,merge:1,ruleParams:1};return new Set(Object.keys(t))}const Jn=Vn();function Be(e,t,n){const i={__etype:e,__ops:n};return new Proxy(i,{get:(s,r)=>{if(r==="__ops")return n;if(r==="__etype")return e;if(Jn.has(r))return(o,a)=>Be(e,t,[...n,a?[r,e,t,o,a]:[r,e,t,o]])}})}function Qn(e,t){return`lookup__${e}__${JSON.stringify(t)}`}function Gt(e){return e.startsWith("lookup__")}function Ht(e){const[t,n,...i]=e.split("__");return[n,JSON.parse(i.join("__"))]}function Gn(e){return new Proxy({__etype:e},{get(t,n){if(n==="lookup")return(s,r)=>Be(e,Ht(Qn(s,r)),[]);if(n==="__etype")return e;const i=n;return Gt(i)?Be(e,Ht(i),[]):Be(e,i,[])}})}function Bt(){return new Proxy({},{get(e,t){return Gn(t)}})}Bt();function Hn(e){return e.__ops}class q extends Error{constructor(n,i){super(n);d(this,"hint");this.hint=i;const s=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,s),Error.captureStackTrace&&Error.captureStackTrace(this,q),this.name="InstantError"}get[Symbol.toStringTag](){return"InstantError"}}class Ie extends q{constructor(n){var r;const i=((r=n.body)==null?void 0:r.message)||`API Error (${n.status})`;super(i,n.body.hint);d(this,"body");d(this,"status");const s=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,s),Error.captureStackTrace&&Error.captureStackTrace(this,Ie),this.name="InstantAPIError",this.status=n.status,this.body=n.body}get[Symbol.toStringTag](){return"InstantAPIError"}}typeof window<"u"&&typeof window.localStorage<"u"&&(window.localStorage.getItem("devBackend"),window.localStorage.getItem("__instantLogging"),window.localStorage.getItem("__devtoolLocalDash"));const _e="v0.22.151";class ce{constructor(t,n,i,s={indexed:!1,unique:!1}){d(this,"valueType");d(this,"required");d(this,"isIndexed");d(this,"config");d(this,"metadata",{});this.valueType=t,this.required=n,this.isIndexed=i,this.config=s}clientRequired(){return new ce(this.valueType,!1,this.isIndexed,this.config)}optional(){return new ce(this.valueType,!1,this.isIndexed,this.config)}unique(){return new ce(this.valueType,this.required,this.isIndexed,{...this.config,unique:!0})}indexed(){return new ce(this.valueType,this.required,!0,{...this.config,indexed:!0})}}class C extends Error{constructor(t,n){const i=n?`At path '${n}': ${t}`:t;super(i),this.name="QueryValidationError"}}const qt=["where","order","limit","last","first","offset","after","before","fields","aggregate"],Bn=e=>e.valueType||"unknown",Kt=(e,t,n=!1)=>{if(n||e==null)return!0;switch(t){case"string":return typeof e=="string";case"number":return typeof e=="number"&&!isNaN(e);case"boolean":return typeof e=="boolean";case"date":return e instanceof Date||typeof e=="string"||typeof e=="number";default:return!0}},qn=(e,t,n,i,s,r,o)=>{const a=r.valueType==="json",u=(c,l,f)=>{if(!Kt(f,l,a))throw new C(`Invalid value for operator '${c}' on attribute '${i}' in entity '${s}'. Expected ${l}, but received: ${typeof f}`,o)};switch(e){case"in":case"$in":if(!Array.isArray(t))throw new C(`Operator '${e}' for attribute '${i}' in entity '${s}' must be an array, but received: ${typeof t}`,o);for(const c of t)u(e,n,c);break;case"$not":case"$ne":case"$gt":case"$lt":case"$gte":case"$lte":u(e,n,t);break;case"$like":case"$ilike":if(u(e,"string",t),e==="$ilike"&&!r.isIndexed)throw new C(`Operator '${e}' can only be used with indexed attributes, but '${i}' in entity '${s}' is not indexed`,o);break;case"$isNull":u(e,"boolean",t);break;default:throw new C(`Unknown operator '${e}' for attribute '${i}' in entity '${s}'`,o)}},Ce=(e,t,n,i,s)=>{const r=Bn(n),o=n.valueType==="json";if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(o)return;const u=e;for(const[c,l]of Object.entries(u))qn(c,l,r,t,i,n,`${s}.${c}`)}else if(!Kt(e,r,o))throw new C(`Invalid value for attribute '${t}' in entity '${i}'. Expected ${r}, but received: ${typeof e}`,s)},Kn=(e,t,n,i,s)=>{const r=e.split(".");if(r.length<2)throw new C(`Invalid dot notation path '${e}'. Must contain at least one dot.`,s);let o=n;for(let l=0;l<r.length-1;l++){const f=r[l],m=i.entities[o];if(!m)throw new C(`Entity '${o}' does not exist in schema while traversing dot notation path '${e}'.`,s);const y=m.links[f];if(!y){const I=Object.keys(m.links);throw new C(`Link '${f}' does not exist on entity '${o}' in dot notation path '${e}'. Available links: ${I.length>0?I.join(", "):"none"}`,s)}o=y.entityName}const a=r[r.length-1],u=i.entities[o];if(!u)throw new C(`Target entity '${o}' does not exist in schema for dot notation path '${e}'.`,s);if(a==="id"){if(typeof t=="string"&&!x(t))throw new C(`Invalid value for id field in entity '${o}'. Expected a UUID, but received: ${t}`,s);Ce(t,e,new ce("string",!1,!0),n,s);return}const c=u.attrs[a];if(Object.keys(u.links).includes(a)){if(typeof t=="string"&&!x(t))throw new C(`Invalid value for link '${a}' in entity '${o}'. Expected a UUID, but received: ${t}`,s);Ce(t,e,new ce("string",!1,!0),n,s);return}if(!c){const l=Object.keys(u.attrs);throw new C(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${l.length>0?l.join(", ")+", id":"id"}`,s)}Ce(t,e,c,n,s)},Xt=(e,t,n,i)=>{for(const[s,r]of Object.entries(e)){if(s==="or"||s==="and"){if(Array.isArray(r))for(const c of r)typeof c=="object"&&c!==null&&Xt(c,t,n,`${i}.${s}[${c}]`);continue}if(s==="id"){Ce(r,"id",new ce("string",!1,!0),t,`${i}.id`);continue}if(s.includes(".")){Kn(s,r,t,n,`${i}.${s}`);continue}const o=n.entities[t];if(!o)continue;const a=o.attrs[s],u=o.links[s];if(!a&&!u){const c=Object.keys(o.attrs),l=Object.keys(o.links);throw new C(`Attribute or link '${s}' does not exist on entity '${t}'. Available attributes: ${c.length>0?c.join(", "):"none"}. Available links: ${l.length>0?l.join(", "):"none"}`,`${i}.${s}`)}if(a)Ce(r,s,a,t,`${i}.${s}`);else if(u){if(typeof r=="string"&&!x(r))throw new C(`Invalid value for link '${s}' in entity '${t}'. Expected a UUID, but received: ${r}`,`${i}.${s}`);const c=new ce("string",!1,!0);Ce(r,s,c,t,`${i}.${s}`)}}},Xn=(e,t,n,i,s=0)=>{for(const o of Object.keys(e))if(!qt.includes(o))throw new C(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${qt.join(", ")}. Found: ${o}`,i);const r=["offset","before","after","first","last"];for(const o of r)if(e[o]!==void 0&&s>0)throw new C(`'${o}' can only be used on top-level namespaces. It cannot be used in nested queries.`,i);if(e.where&&n){if(typeof e.where!="object"||e.where===null)throw new C(`'where' clause must be an object in entity '${t}', but received: ${typeof e.where}`,i?`${i}.where`:void 0);Xt(e.where,t,n,i?`${i}.where`:"where")}},Yt=(e,t,n,i,s=0)=>{var r;if(!e||typeof e!="object")throw new C(`Query part for entity '${t}' must be an object, but received: ${typeof e}`,i);for(const o of Object.keys(e))if(o!=="$"){if(n&&!(o in n.entities[t].links)){const u=Object.keys(n.entities[t].links);throw new C(`Link '${o}' does not exist on entity '${t}'. Available links: ${u.length>0?u.join(", "):"none"}`,`${i}.${o}`)}const a=e[o];if(typeof a=="object"&&a!==null){const u=(r=n==null?void 0:n.entities[t].links[o])==null?void 0:r.entityName;u&&Yt(a,u,n,`${i}.${o}`,s+1)}}else{const a=e[o];if(typeof a!="object"||a===null)throw new C(`Query parameter '$' must be an object in entity '${t}', but received: ${typeof a}`,`${i}.$`);Xn(a,t,n,`${i}.$`,s)}},Zt=(e,t)=>{if(typeof e!="object"||e===null)throw new C(`Query must be an object, but received: ${typeof e}${e===null?" (null)":""}`);if(Array.isArray(e))throw new C(`Query must be an object, but received: ${typeof e}`);const n=e;for(const i of Object.keys(n)){if(Array.isArray(e[i]))throw new C(`Query keys must be strings, but found key of type: ${typeof i}`,i);if(typeof i!="string")throw new C(`Query keys must be strings, but found key of type: ${typeof i}`,i);if(i!=="$$ruleParams"){if(t&&!t.entities[i]){const s=Object.keys(t.entities);throw new C(`Entity '${i}' does not exist in schema. Available entities: ${s.length>0?s.join(", "):"none"}`,i)}Yt(n[i],i,t,i,0)}}},en=e=>typeof e!="string"?!1:Gt(e)?!0:x(e);class K extends Error{constructor(t){super(t),this.name="TransactionValidationError"}}const tn=e=>e.length>0?e.join(", "):"none",Yn=(e,t)=>new K(`Entity '${e}' does not exist in schema. Available entities: ${tn(t)}`),pt={string:e=>typeof e=="string",number:e=>typeof e=="number"&&!isNaN(e),boolean:e=>typeof e=="boolean",date:e=>e instanceof Date||typeof e=="string"||typeof e=="number",json:()=>!0},Zn=(e,t)=>{var n;return e==null?!0:((n=pt[t.valueType])==null?void 0:n.call(pt,e))??!1},nn=(e,t)=>{const n=t.entities[e];if(!n)throw Yn(e,Object.keys(t.entities));return n},mt=(e,t,n)=>{const i=nn(e,n);if(typeof t!="object"||t===null)throw new K(`Arguments for data operation on entity '${e}' must be an object, but received: ${typeof t}`);for(const[s,r]of Object.entries(t)){if(s==="id")continue;const o=i.attrs[s];if(o&&!Zn(r,o))throw new K(`Invalid value for attribute '${s}' in entity '${e}'. Expected ${o.valueType}, but received: ${typeof r}`)}},sn=(e,t,n)=>{const i=nn(e,n);if(typeof t!="object"||t===null)throw new K(`Arguments for link operation on entity '${e}' must be an object, but received: ${typeof t}`);for(const[s,r]of Object.entries(t)){if(!i.links[s]){const a=Object.keys(i.links);throw new K(`Link '${s}' does not exist on entity '${e}'. Available links: ${tn(a)}`)}if(r!=null){if(Array.isArray(r)){for(const a of r)if(!en(a))throw new K(`Invalid entity ID in link '${s}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`)}else if(!en(r))throw new K(`Invalid UUID in link '${s}' for entity '${e}'. Expected a UUID, but received: ${r}`)}}},ei={create:mt,update:mt,merge:mt,link:sn,unlink:sn,delete:()=>{}},ti=(e,t)=>{if(!t)return;const[n,i,s,r]=e;if(!Array.isArray(s)&&!x(s))throw new K(`Invalid id for entity '${i}'. Expected a UUID, but received: ${s}`);if(typeof i!="string")throw new K(`Entity name must be a string, but received: ${typeof i}`);const o=ei[n];o&&r!==void 0&&o(i,r,t)},ni=(e,t)=>{const n=Array.isArray(e)?e:[e];for(const i of n){if(!i||typeof i!="object")throw new K(`Transaction chunk must be an object, but received: ${typeof i}`);if(!Array.isArray(i.__ops))throw new K(`Transaction chunk must have __ops array, but received: ${typeof i.__ops}`);for(const s of i.__ops){if(!Array.isArray(s))throw new K(`Transaction operation must be an array, but received: ${typeof s}`);ti(s,t)}}};let ii=0;class si{constructor(t,n,i){d(this,"type","sse");d(this,"initParams",null);d(this,"sendQueue",[]);d(this,"sendPromise");d(this,"closeFired",!1);d(this,"sseInitTimeout");d(this,"ES");d(this,"messageUrl");d(this,"conn");d(this,"url");d(this,"id");d(this,"onopen");d(this,"onmessage");d(this,"onclose");d(this,"onerror");this.id=`${this.type}_${ii++}`,this.url=n,this.messageUrl=i||this.url,this.ES=t,this.conn=new t(n),this.sseInitTimeout=setTimeout(()=>{this.initParams||this.handleError()},1e4),this.conn.onmessage=s=>{const r=JSON.parse(s.data);if(Array.isArray(r))for(const o of r)this.handleMessage(o);else this.handleMessage(r)},this.conn.onerror=s=>{this.handleError()}}handleMessage(t){if(t.op==="sse-init"){this.initParams={machineId:t["machine-id"],sessionId:t["session-id"],sseToken:t["sse-token"]},this.onopen&&this.onopen({target:this}),clearTimeout(this.sseInitTimeout);return}this.onmessage&&this.onmessage({target:this,message:t})}handleError(){try{this.onerror&&this.onerror({target:this})}finally{this.handleClose()}}handleClose(){this.conn.close(),this.onclose&&!this.closeFired&&(this.closeFired=!0,this.onclose({target:this}))}async postMessages(t){var n,i,s;try{(await fetch(this.messageUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({machine_id:(n=this.initParams)==null?void 0:n.machineId,session_id:(i=this.initParams)==null?void 0:i.sessionId,sse_token:(s=this.initParams)==null?void 0:s.sseToken,messages:t})})).ok||this.handleError()}catch{this.handleError()}}async flushQueue(){if(this.sendPromise||!this.sendQueue.length)return;const t=this.sendQueue;this.sendQueue=[];const n=this.postMessages(t);this.sendPromise=n,n.then(()=>{this.sendPromise=null,this.flushQueue()})}send(t){if(!this.isOpen()||!this.initParams)throw this.isConnecting()?new Error("Failed to execute 'send' on 'EventSource': Still in CONNECTING state."):this.conn.readyState===this.ES.CLOSED?new Error("EventSource is already in CLOSING or CLOSED state."):new Error("EventSource is in invalid state.");this.sendQueue.push(t),this.flushQueue()}isOpen(){return this.conn.readyState===this.ES.OPEN&&this.initParams!==null}isConnecting(){return this.conn.readyState===this.ES.CONNECTING||this.conn.readyState===this.ES.OPEN&&this.initParams===null}close(){this.handleClose()}}var rn;(function(e){e.InitialSyncBatch="InitialSyncBatch",e.InitialSyncComplete="InitialSyncComplete",e.LoadFromStorage="LoadFromStorage",e.SyncTransaction="SyncTransaction",e.Error="Error"})(rn||(rn={}));function ri({WStream:e,opts:t,startStream:n,appendStream:i,registerStream:s}){const r=t.clientId;let o=null,a=null,u=null;const c=Ee();let l=!1,f=!1;const m=[],y=[],I=[];let w=!1,h=0,O=0;const b=[],k=new TextEncoder;function te(){f=!0;for(const p of m)p(a??void 0)}function D(p){return m.push(p),f&&p(a??void 0),()=>{const v=m.indexOf(p);v!==-1&&m.splice(v,1)}}function z(p){return I.push(p),()=>{const v=I.indexOf(p);v!==-1&&I.splice(v,1)}}t.waitUntil&&t.waitUntil(new Promise(p=>{I.push(p)}));function Q(){for(const p of I)try{p()}catch{}}function le(p){return y.push(p),o&&p(o),()=>{const v=y.indexOf(p);v!==-1&&y.splice(v,1)}}function oe(p){o=p;for(const v of y)v(o)}function $e(){w=!0}function Rt(p){let v=h,V=0,G=0;for(const{byteLen:ie}of b){const de=v+ie;if(de>p)break;v=de,V++,G+=ie}V>0&&(h+=G,O-=G,b.splice(0,V))}function ne(p,v){a=v,te(),p.error(v),Q()}async function ae(){const p=await n({clientId:r,reconnectToken:c,ruleParams:t.ruleParams});switch(p.type){case"ok":{const{streamId:v,offset:V}=p;o=v,Rt(V),b.length&&i({streamId:v,chunks:b.map(G=>G.chunk),offset:h}),w=!1;break}case"disconnect":{$e();break}case"error":{u&&ne(u,p.error);break}}}function B(){$e(),ae()}function Ve({offset:p,done:v}){Rt(p),v&&(l=!0,Q())}function zi(p){return l?(ne(p,new q("Stream has been closed.")),null):o||(ne(p,new q("Stream has not been initialized.")),null)}async function Vi(p){u=p;let v=!0,V=0;for(;v;){let G=Date.now()+Math.min(15e3,500*(V-1));v=!1;const ie=await n({clientId:t.clientId,reconnectToken:c,ruleParams:t.ruleParams});switch(ie.type){case"ok":{const{streamId:de,offset:At}=ie;if(At!==0){const ke=new q("Write stream is corrupted");ne(p,ke);return}oe(de),s(de,{onDisconnect:$e,onFlush:Ve,onConnectionReconnect:ae,onAppendFailed:B}),w=!1;return}case"disconnect":{v=!0,$e(),V++,await new Promise(de=>{setTimeout(de,Math.max(0,G-Date.now()))});break}case"error":{ne(p,ie.error);return}}}}class Ji extends e{constructor(v,V){super(v,V)}async streamId(){return o||new Promise((v,V)=>{const G=[],ie=()=>{for(const ke of G)ke()},de=ke=>{v(ke),ie()},At=ke=>{V(ke||new q("Stream is closed.")),ie()};G.push(le(de)),G.push(D(At))})}}return{stream:new Ji({async start(p){try{await Vi(p)}catch(v){ne(p,v)}},write(p,v){const V=zi(v);if(V){const G=k.encode(p).length;b.push({chunk:p,byteLen:G});const ie=h+O;O+=G,w||i({streamId:V,chunks:[p],offset:ie})}},close(){o?i({streamId:o,chunks:[],offset:h+O,isDone:!0}):Q(),te()},abort(p){o?i({streamId:o,chunks:[],offset:h+O,isDone:!0,abortReason:p}):Q(),te()}}),addCompleteCb:z,closed(){return f}}}class oi{constructor(){d(this,"items",[]);d(this,"resolvers",[]);d(this,"isClosed",!1)}push(t){if(this.isClosed)return;const n=this.resolvers.shift();n?n({value:t,done:!1}):this.items.push(t)}close(){for(this.isClosed=!0;this.resolvers.length>0;)this.resolvers.shift()({value:void 0,done:!0})}async*[Symbol.asyncIterator](){for(;;)if(this.items.length>0)yield this.items.shift();else{if(this.isClosed)return;{const{value:t,done:n}=await new Promise(i=>{this.resolvers.push(i)});if(n||!t)return;yield t}}}}function ai({RStream:e,opts:t,startStream:n,cancelStream:i}){let s=t.byteOffset||0,r=!1;const o=new TextDecoder("utf-8"),a=new TextEncoder;let u,c=!1;const l=[];function f(){c=!0;for(const b of l)b()}function m(b){return l.push(b),()=>{const k=l.indexOf(b);k!==-1&&l.splice(k,1)}}function y(b,k){b.error(k),f()}let I=0;async function w(b,k){u=Ee();const te={...b||{},eventId:u};for await(const D of n(te)){if(r)return;if(D.type==="reconnect")return{retry:!0};if(D.type==="error"){y(k,D.error);return}if(D.offset>s){y(k,new q("Stream is corrupted.")),r=!0;return}let z=s-D.offset;if(D.files&&D.files.length){const Q=new AbortController;let le=fetch(D.files[0].url,{signal:Q.signal});for(let oe=0;oe<D.files.length;oe++){const $e=D.files[oe+1],ne=await le;if($e&&(le=fetch($e.url,{signal:Q.signal})),!ne.ok){if(I++,I>10){y(k,new q("Unable to process stream."));return}return{retry:!0}}if(ne.body)for await(const ae of ne.body){if(r){Q.abort();return}let B=ae;if(z>0&&(B=ae.subarray(z),z-=ae.length-B.length),!B.length)continue;s+=B.length;const Ve=o.decode(B);k.enqueue(Ve)}else{const ae=await ne.arrayBuffer();let B=ae;if(r){Q.abort();return}if(z>0&&(B=new Uint8Array(ae).subarray(z),z-=ae.byteLength-B.length),!B.byteLength)continue;s+=B.byteLength;const Ve=o.decode(B);k.enqueue(Ve)}}}if(I=0,D.content){let Q=D.content,le=a.encode(D.content);if(z>0){const oe=le.subarray(z);if(z-=le.length-oe.length,!oe.length)continue;le=oe,Q=o.decode(oe)}s+=le.length,k.enqueue(Q)}}}async function h(b){let k=!0,te=0;for(;k;){k=!1;let D=Date.now()+Math.min(15e3,500*(te-1));const z=await w({...t,offset:s},b);z!=null&&z.retry&&(k=!0,te++,D<Date.now()-3e5&&(te=0),await new Promise(Q=>{setTimeout(Q,Math.max(0,D-Date.now()))}))}!r&&!c&&(b.close(),f())}return{stream:new e({start(b){h(b)},cancel(b){r=!0,u&&i({eventId:u}),f()}}),addCloseCb:m,closed(){return c}}}class ci{constructor({WStream:t,RStream:n,trySend:i,log:s}){d(this,"trySend");d(this,"WStream");d(this,"RStream");d(this,"writeStreams",{});d(this,"startWriteStreamCbs",{});d(this,"readStreamIterators",{});d(this,"log");d(this,"activeStreams",new Set);this.WStream=t,this.RStream=n,this.trySend=i,this.log=s}createWriteStream(t){const{stream:n,addCompleteCb:i}=ri({WStream:this.WStream,startStream:this.startWriteStream.bind(this),appendStream:this.appendStream.bind(this),registerStream:this.registerWriteStream.bind(this),opts:t});return this.activeStreams.add(n),i(()=>{this.activeStreams.delete(n)}),n}createReadStream(t){const{stream:n,addCloseCb:i}=ai({RStream:this.RStream,opts:t,startStream:this.startReadStream.bind(this),cancelStream:this.cancelReadStream.bind(this)});return this.activeStreams.add(n),i(()=>{this.activeStreams.delete(n)}),n}startWriteStream(t){const n=Ee();let i=null;const s=new Promise(o=>{i=o});this.startWriteStreamCbs[n]=i;const r={op:"start-stream","client-id":t.clientId,"reconnect-token":t.reconnectToken};return t.ruleParams&&(r["rule-params"]=t.ruleParams),this.trySend(n,r),s}registerWriteStream(t,n){this.writeStreams[t]=n}appendStream({streamId:t,chunks:n,isDone:i,offset:s,abortReason:r}){const o={op:"append-stream","stream-id":t,chunks:n,offset:s,done:!!i};r&&(o["abort-reason"]=r),this.trySend(Ee(),o)}onAppendFailed(t){const n=this.writeStreams[t["stream-id"]];n&&n.onAppendFailed()}onStartStreamOk(t){const n=this.startWriteStreamCbs[t["client-event-id"]];if(!n){this.log.info("No stream for start-stream-ok",t);return}n({type:"ok",streamId:t["stream-id"],offset:t.offset}),delete this.startWriteStreamCbs[t["client-event-id"]]}onStreamFlushed(t){const n=t["stream-id"],i=this.writeStreams[n];if(!i){this.log.info("No stream cbs for stream-flushed",t);return}i.onFlush({offset:t.offset,done:t.done}),t.done&&delete this.writeStreams[n]}startReadStream({eventId:t,clientId:n,streamId:i,offset:s,ruleParams:r}){const o={op:"subscribe-stream"};if(!i&&!n)throw new Error("Must provide one of streamId or clientId to subscribe to the stream.");i&&(o["stream-id"]=i),n&&(o["client-id"]=n),s&&(o.offset=s),r&&(o["rule-params"]=r);const a=new oi;return this.readStreamIterators[t]=a,this.trySend(t,o),a}cancelReadStream({eventId:t}){const n={op:"unsubscribe-stream","subscribe-event-id":t};this.trySend(Ee(),n),delete this.readStreamIterators[t]}onStreamAppend(t){var s;const n=t["client-event-id"],i=this.readStreamIterators[n];if(!i){this.log.info("No iterator for read stream",t);return}if(t.error){t.retry?i.push({type:"reconnect"}):i.push({type:"error",error:new q(t.error)}),i.close(),delete this.readStreamIterators[n];return}((s=t.files)!=null&&s.length||t.content)&&i.push({type:"append",offset:t.offset,files:t.files,content:t.content}),t.done&&(i.close(),delete this.readStreamIterators[n])}onConnectionStatusChange(t){for(const n of Object.values(this.startWriteStreamCbs))n({type:"disconnect"});if(this.startWriteStreamCbs={},t!==ui.AUTHENTICATED)for(const{onDisconnect:n}of Object.values(this.writeStreams))n();else{for(const{onConnectionReconnect:n}of Object.values(this.writeStreams))n();for(const n of Object.values(this.readStreamIterators))n.push({type:"reconnect"}),n.close();this.readStreamIterators={}}}onRecieveError(t){const n=t["original-event"];switch(n.op){case"append-stream":{const i=n["stream-id"],s=this.writeStreams[i];s==null||s.onAppendFailed();break}case"start-stream":{const i=t["client-event-id"],s=this.startWriteStreamCbs[i];s&&(s({type:"error",error:new q(t.message||"Unknown error",t.hint)}),delete this.startWriteStreamCbs[i]);break}case"subscribe-stream":{const i=t["client-event-id"],s=this.readStreamIterators[i];s&&(s.push({type:"error",error:new q(t.message||"Unknown error",t.hint)}),s.close(),delete this.readStreamIterators[i]);break}}}hasActiveStreams(){return this.activeStreams.size>0}}const ui={AUTHENTICATED:"authenticated"};function fi(){return globalThis.__instantDbSchemaHashStore=globalThis.__instantDbSchemaHashStore??new WeakMap,globalThis.__instantDbSchemaHashStore}function li(){return globalThis.__instantDbStore=globalThis.__instantDbStore??{},globalThis.__instantDbStore}li(),fi();class on extends Error{constructor(t,n){super(t),this.name="ParseError",this.type=n.type,this.field=n.field,this.value=n.value,this.line=n.line}}function yt(e){}function di(e){if(typeof e=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:t=yt,onError:n=yt,onRetry:i=yt,onComment:s}=e;let r="",o=!0,a,u="",c="";function l(w){const h=o?w.replace(/^\xEF\xBB\xBF/,""):w,[O,b]=hi(`${r}${h}`);for(const k of O)f(k);r=b,o=!1}function f(w){if(w===""){y();return}if(w.startsWith(":")){s&&s(w.slice(w.startsWith(": ")?2:1));return}const h=w.indexOf(":");if(h!==-1){const O=w.slice(0,h),b=w[h+1]===" "?2:1,k=w.slice(h+b);m(O,k,w);return}m(w,"",w)}function m(w,h,O){switch(w){case"event":c=h;break;case"data":u=`${u}${h}
|
|
2
2
|
`;break;case"id":a=h.includes("\0")?void 0:h;break;case"retry":/^\d+$/.test(h)?i(parseInt(h,10)):n(new on(`Invalid \`retry\` value: "${h}"`,{type:"invalid-retry",value:h,line:O}));break;default:n(new on(`Unknown field "${w.length>20?`${w.slice(0,20)}…`:w}"`,{type:"unknown-field",field:w,value:h,line:O}));break}}function y(){u.length>0&&t({id:a,event:c||void 0,data:u.endsWith(`
|
|
3
3
|
`)?u.slice(0,-1):u}),a=void 0,u="",c=""}function I(w={}){r&&w.consume&&f(r),o=!0,a=void 0,u="",c="",r=""}return{feed:l,reset:I}}function hi(e){const t=[];let n="",i=0;for(;i<e.length;){const s=e.indexOf("\r",i),r=e.indexOf(`
|
|
4
4
|
`,i);let o=-1;if(s!==-1&&r!==-1?o=Math.min(s,r):s!==-1?o=s:r!==-1&&(o=r),o===-1){n=e.slice(i);break}else{const a=e.slice(i,o);t.push(a),i=o+1,e[i-1]==="\r"&&e[i]===`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instantdb/resumable-stream",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.151",
|
|
4
4
|
"description": "Instant's drop-in replacement for Vercel's resumable-stream package.",
|
|
5
5
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/resumable-stream",
|
|
6
6
|
"repository": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"vitest": "^1.6.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@instantdb/admin": "0.22.
|
|
53
|
+
"@instantdb/admin": "0.22.151"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"test": "vitest",
|