@instantdb/resumable-stream 0.22.168 → 0.22.169
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.169 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.169 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.169 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[2m67.23 kB[22m[1m[22m[2m │ gzip: 21.11 kB[22m
|
|
23
23
|
[2mdist/standalone/[22m[36mindex.js [39m[1m[2m107.11 kB[22m[1m[22m[2m │ gzip: 28.01 kB[22m
|
|
24
|
-
[32m✓ built in 1.
|
|
24
|
+
[32m✓ built in 1.13s[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.169 check-exports
|
|
29
29
|
> attw --pack .
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
@instantdb/resumable-stream v0.22.
|
|
32
|
+
@instantdb/resumable-stream v0.22.169
|
|
33
33
|
|
|
34
34
|
Build tools:
|
|
35
35
|
- @arethetypeswrong/cli@^0.17.4
|
package/dist/standalone/index.js
CHANGED
|
@@ -834,7 +834,7 @@ class Oe extends H {
|
|
|
834
834
|
}
|
|
835
835
|
}
|
|
836
836
|
typeof window < "u" && typeof window.localStorage < "u" && (window.localStorage.getItem("devBackend"), window.localStorage.getItem("__instantLogging"), window.localStorage.getItem("__devtoolLocalDash"));
|
|
837
|
-
const Me = "v0.22.
|
|
837
|
+
const Me = "v0.22.169";
|
|
838
838
|
class ue {
|
|
839
839
|
constructor(t, n, i, s = { indexed: !1, unique: !1 }) {
|
|
840
840
|
l(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 In=$=>{throw TypeError($)};var Gi=($,_,x)=>_ in $?Qi($,_,{enumerable:!0,configurable:!0,writable:!0,value:x}):$[_]=x;var l=($,_,x)=>Gi($,typeof _!="symbol"?_+"":_,x),Mt=($,_,x)=>_.has($)||In("Cannot "+x);var g=($,_,x)=>(Mt($,_,"read from private field"),x?x.call($):_.get($)),K=($,_,x)=>_.has($)?In("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add($):_.set($,x),he=($,_,x,P)=>(Mt($,_,"write to private field"),P?P.call($,x):_.set($,x),x),X=($,_,x)=>(Mt($,_,"access private method"),x);var Ue,N,Oe,W,F,U,On,st,$n,kn,En,et,tt,nt,Ut,_n,it;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 P=[];for(let e=0;e<256;++e)P.push((e+256).toString(16).slice(1));function Cn(e,t=0){return(P[e[t+0]]+P[e[t+1]]+P[e[t+2]]+P[e[t+3]]+"-"+P[e[t+4]]+P[e[t+5]]+"-"+P[e[t+6]]+P[e[t+7]]+"-"+P[e[t+8]]+P[e[t+9]]+"-"+P[e[t+10]]+P[e[t+11]]+P[e[t+12]]+P[e[t+13]]+P[e[t+14]]+P[e[t+15]]).toLowerCase()}let rt;const xn=new Uint8Array(16);function Tn(){if(!rt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");rt=crypto.getRandomValues.bind(crypto)}return rt(xn)}const Dt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Rn(e,t,n){var s;if(Dt.randomUUID&&!e)return Dt.randomUUID();e=e||{};const i=e.random??((s=e.rng)==null?void 0:s.call(e))??Tn();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,Cn(i)}const j={Remove:"remove",Replace:"replace",Add:"add"},Nt=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),Qe=Symbol.iterator,Y={mutable:"mutable",immutable:"immutable"},ot={};function De(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Lt(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 Wt(e){return Object.getPrototypeOf(e)===Set.prototype}function Ft(e){return Object.getPrototypeOf(e)===Map.prototype}function H(e){var t;return(t=e.copy)!==null&&t!==void 0?t:e.original}function at(e){return!!E(e)}function E(e){return typeof e!="object"?null:e==null?void 0:e[Nt]}function ct(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,Y))===Y.immutable||typeof n=="function")}function zt(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||De(n,r)))return null;t.push(r)}if(e.parent)return zt(e.parent,t);t.reverse();try{Pn(e.copy,t)}catch{return null}return t}function Ne(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function pe(e,t){return Ne(e)===2?e.get(t):e[t]}function ut(e,t,n){Ne(e)===2?e.set(t,n):e[t]=n}function ft(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 Pn(e,t){for(let n=0;n<t.length-1;n+=1){const i=t[n];if(e=pe(Ne(e)===3?Array.from(e):e,i),typeof e!="object")throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}return e}function An(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 jn=Object.prototype.propertyIsEnumerable;function Mn(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!Wt(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(!Ft(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,Y),n!==void 0)&&n!==Y.mutable){if(n===Y.immutable)return An(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=>{jn.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=Mn(e.original,e.options))}function Le(e){if(!ge(e))return ct(e);if(Array.isArray(e))return e.map(Le);if(e instanceof Map){const n=Array.from(e.entries()).map(([i,s])=>[i,Le(s)]);if(!Ft(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(Le);if(!Wt(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]=Le(e[n]);return t}function Ge(e){return at(e)?Le(e):e}function ie(e){var t;e.assignedMap=(t=e.assignedMap)!==null&&t!==void 0?t:new Map,e.operated||(e.operated=!0,e.parent&&ie(e.parent))}function Un(e,t){const n=Ne(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 Vt(e,t,n){if(at(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),Un(e,(r,o)=>{var a;if(at(o)){const u=E(o);L(u);const c=!((a=u.assignedMap)===null||a===void 0)&&a.size||u.operated?u.copy:u.original;ut(i?s:e,r,c)}else Vt(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 Dn(e,t){const n=e.type===3?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&Vt(pe(n,t),e.finalities.handledSet,e.options)}function lt(e){e.type===3&&e.copy&&(e.copy.clear(),e.setMap.forEach(t=>{e.copy.add(ct(t))}))}function dt(e,t,n,i){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&i){const r=zt(e);r&&t(e,r,n,i)}e.finalized=!0}}function ht(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),lt(e),dt(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)),ut(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)&&Dn(e,t)})}function Nn(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 d=t.concat([c]),f=Se(d,s);n.push({op:j.Replace,path:f,value:Ge(u[c])}),i.push({op:j.Replace,path:f,value:Ge(r[c])})}for(let c=r.length;c<u.length;c+=1){const d=t.concat([c]),f=Se(d,s);n.push({op:j.Add,path:f,value:Ge(u[c])})}if(r.length<u.length){const{arrayLengthAssignment:c=!0}=a.enablePatches;if(c){const d=t.concat(["length"]),f=Se(d,s);i.push({op:j.Replace,path:f,value:r.length})}else for(let d=u.length;r.length<d;d-=1){const f=t.concat([d-1]),m=Se(f,s);i.push({op:j.Remove,path:m})}}}function Ln({original:e,copy:t,assignedMap:n},i,s,r,o){n.forEach((a,u)=>{const c=pe(e,u),d=Ge(pe(t,u)),f=a?De(e,u)?j.Replace:j.Add:j.Remove;if(we(c,d)&&f===j.Replace)return;const m=i.concat(u),y=Se(m,o);s.push(f===j.Remove?{op:f,path:y}:{op:f,path:y,value:d}),r.push(f===j.Add?{op:j.Remove,path:y}:f===j.Remove?{op:j.Add,path:y,value:c}:{op:j.Replace,path:y,value:c})})}function Wn({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:j.Remove,path:c,value:a}),s.unshift({op:j.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:j.Add,path:c,value:a}),s.unshift({op:j.Remove,path:c,value:a})}o+=1})}function We(e,t,n,i){const{pathAsArray:s=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return Ln(e,t,n,i,s);case 1:return Nn(e,t,n,i,s);case 3:return Wn(e,t,n,i,s)}}const He=(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.")},pt={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),ie(n),n.assignedMap.set(e,!0),n.copy.set(e,t),ht(n,e,t,We)),this},delete(e){if(!this.has(e))return!1;const t=E(this);return L(t),ie(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),ie(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,Y))===Y.mutable;if(i.options.strict&&He(s,i.options,r),r||i.finalized||!ge(s,i.options)||s!==i.original.get(e))return s;const o=ot.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{[Qe]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[Qe]:()=>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]}}}},[Qe](){return this.entries()}},Fn=Reflect.ownKeys(pt),Jt=(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,Y))===Y.mutable;if(e.options.strict&&He(o,e.options,c),!c&&!u&&ge(o,e.options)&&!e.finalized&&e.original.has(o)){const d=ot.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,d),a=d}else u&&(a=u.proxy);return{done:!1,value:n?a:[a,a]}},Be={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),ie(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),ht(t,e,e,We)),this},delete(e){if(!this.has(e))return!1;const t=E(this);L(t),ie(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),ie(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:Jt(e,t,{isValuesIterator:!0})}},entries(){const e=E(this);L(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:Jt(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[Qe](){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(Be,{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 zn=Reflect.ownKeys(Be),Qt=new WeakSet,Gt={get(e,t,n){var i,s;const r=(i=e.copy)===null||i===void 0?void 0:i[t];if(r&&Qt.has(r))return r;if(t===Nt)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,Y),o===Y.mutable)return e.options.strict&&He(c,e.options,!0),c}const a=H(e);if(a instanceof Map&&Fn.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(pt,"size").get.call(e.proxy);const c=pt[t];if(c)return c.bind(e.proxy)}if(a instanceof Set&&zn.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(Be,"size").get.call(e.proxy);const c=Be[t];if(c)return c.bind(e.proxy)}if(!De(a,t)){const c=Lt(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&&He(u,e.options),e.finalized||!ge(u,e.options))return u;if(u===ft(e.original,t)){if(L(e),e.copy[t]=Ht({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),ie(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=Lt(H(e),t);if(r!=null&&r.set)return r.set.call(e.proxy,n),!0;const o=ft(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||De(e.original,t))||(L(e),ie(e),De(e.original,t)&&we(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,ht(e,t,n,We)),!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?Gt.set.call(this,e,t,void 0,e.proxy):(ft(e.original,t)!==void 0||t in e.original?(L(e),ie(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 Ht(e){const{original:t,parentDraft:n,key:i,finalities:s,options:r}=e,o=Ne(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,Gt);if(s.revoke.push(c),Qt.add(u),a.proxy=u,n){const d=n;d.finalities.draft.push((f,m)=>{var y,I;const w=E(u);let h=d.type===3?d.setMap:d.copy;const O=pe(h,i),b=E(O);if(b){let k=b.original;b.operated&&(k=ct(O)),lt(b),dt(b,We,f,m),d.options.enableAutoFreeze&&(d.options.updatedValues=(y=d.options.updatedValues)!==null&&y!==void 0?y:new WeakMap,d.options.updatedValues.set(k,b.original)),ut(h,i,k)}(I=w.callbacks)===null||I===void 0||I.forEach(k=>{k(f,m)})})}else{const d=E(u);d.finalities.draft.push((f,m)=>{lt(d),dt(d,We,f,m)})}return u}ot.createDraft=Ht,Object.prototype.constructor.toString();function Ce(){return Rn()}function Vn(e,t){return e.localeCompare(t)}function Jn(){let e=Vn;if(typeof Intl=="object"&&Intl.hasOwnProperty("Collator"))try{e=Intl.Collator("en-US").compare}catch{}return e}Jn();function Qn(){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 Gn=Qn();function qe(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(Gn.has(r))return(o,a)=>qe(e,t,[...n,a?[r,e,t,o,a]:[r,e,t,o]])}})}function Hn(e,t){return`lookup__${e}__${JSON.stringify(t)}`}function Bt(e){return e.startsWith("lookup__")}function qt(e){const[t,n,...i]=e.split("__");return[n,JSON.parse(i.join("__"))]}function Bn(e){return new Proxy({__etype:e},{get(t,n){if(n==="lookup")return(s,r)=>qe(e,qt(Hn(s,r)),[]);if(n==="__etype")return e;const i=n;return Bt(i)?qe(e,qt(i),[]):qe(e,i,[])}})}function Kt(){return new Proxy({},{get(e,t){return Bn(t)}})}Kt();function qn(e){return e.__ops}class B extends Error{constructor(n,i,s){super(n);l(this,"hint");l(this,"traceId");this.hint=i,s&&(this.traceId=s);const r=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,r),Error.captureStackTrace&&Error.captureStackTrace(this,B),this.name="InstantError"}get[Symbol.toStringTag](){return"InstantError"}}class Ie extends B{constructor(n){var r;const i=((r=n.body)==null?void 0:r.message)||`API Error (${n.status})`;super(i,n.body.hint,n.body["trace-id"]);l(this,"body");l(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 xe="v0.22.168";class oe{constructor(t,n,i,s={indexed:!1,unique:!1}){l(this,"valueType");l(this,"required");l(this,"isIndexed");l(this,"config");l(this,"metadata",{});this.valueType=t,this.required=n,this.isIndexed=i,this.config=s}clientRequired(){return new oe(this.valueType,!1,this.isIndexed,this.config)}optional(){return new oe(this.valueType,!1,this.isIndexed,this.config)}unique(){return new oe(this.valueType,this.required,this.isIndexed,{...this.config,unique:!0})}indexed(){return new oe(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 Xt=["where","order","limit","last","first","offset","after","afterInclusive","before","beforeInclusive","fields","aggregate"],Kn=e=>e.valueType||"unknown",Yt=(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}},Xn=(e,t,n,i,s,r,o)=>{const a=r.valueType==="json",u=(c,d,f)=>{if(!Yt(f,d,a))throw new C(`Invalid value for operator '${c}' on attribute '${i}' in entity '${s}'. Expected ${d}, 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)}},Te=(e,t,n,i,s)=>{const r=Kn(n),o=n.valueType==="json";if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(o)return;const u=e;for(const[c,d]of Object.entries(u))Xn(c,d,r,t,i,n,`${s}.${c}`)}else if(!Yt(e,r,o))throw new C(`Invalid value for attribute '${t}' in entity '${i}'. Expected ${r}, but received: ${typeof e}`,s)},Yn=(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 d=0;d<r.length-1;d++){const f=r[d],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);Te(t,e,new oe("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);Te(t,e,new oe("string",!1,!0),n,s);return}if(!c){const d=Object.keys(u.attrs);throw new C(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${d.length>0?d.join(", ")+", id":"id"}`,s)}Te(t,e,c,n,s)},Zt=(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&&Zt(c,t,n,`${i}.${s}[${c}]`);continue}if(s==="id"){Te(r,"id",new oe("string",!1,!0),t,`${i}.id`);continue}if(s.includes(".")){Yn(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),d=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: ${d.length>0?d.join(", "):"none"}`,`${i}.${s}`)}if(a)Te(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 oe("string",!1,!0);Te(r,s,c,t,`${i}.${s}`)}}},Zn=(e,t,n,i,s=0)=>{for(const o of Object.keys(e))if(!Xt.includes(o))throw new C(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${Xt.join(", ")}. Found: ${o}`,i);const r=["offset","before","beforeInclusive","after","afterInclusive","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);Zt(e.where,t,n,i?`${i}.where`:"where")}},en=(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&&en(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}.$`);Zn(a,t,n,`${i}.$`,s)}},tn=(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)}en(n[i],i,t,i,0)}}},nn=e=>typeof e!="string"?!1:Bt(e)?!0:x(e);class q extends Error{constructor(t){super(t),this.name="TransactionValidationError"}}const sn=e=>e.length>0?e.join(", "):"none",ei=(e,t)=>new q(`Entity '${e}' does not exist in schema. Available entities: ${sn(t)}`),mt={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},ti=(e,t)=>{var n;return e==null?!0:((n=mt[t.valueType])==null?void 0:n.call(mt,e))??!1},rn=(e,t)=>{const n=t.entities[e];if(!n)throw ei(e,Object.keys(t.entities));return n},yt=(e,t,n)=>{const i=rn(e,n);if(typeof t!="object"||t===null)throw new q(`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&&!ti(r,o))throw new q(`Invalid value for attribute '${s}' in entity '${e}'. Expected ${o.valueType}, but received: ${typeof r}`)}},on=(e,t,n)=>{const i=rn(e,n);if(typeof t!="object"||t===null)throw new q(`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 q(`Link '${s}' does not exist on entity '${e}'. Available links: ${sn(a)}`)}if(r!=null){if(Array.isArray(r)){for(const a of r)if(!nn(a))throw new q(`Invalid entity ID in link '${s}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`)}else if(!nn(r))throw new q(`Invalid UUID in link '${s}' for entity '${e}'. Expected a UUID, but received: ${r}`)}}},ni={create:yt,update:yt,merge:yt,link:on,unlink:on,delete:()=>{}},ii=(e,t)=>{if(!t)return;const[n,i,s,r]=e;if(!Array.isArray(s)&&!x(s))throw new q(`Invalid id for entity '${i}'. Expected a UUID, but received: ${s}`);if(typeof i!="string")throw new q(`Entity name must be a string, but received: ${typeof i}`);const o=ni[n];o&&r!==void 0&&o(i,r,t)},si=(e,t)=>{const n=Array.isArray(e)?e:[e];for(const i of n){if(!i||typeof i!="object")throw new q(`Transaction chunk must be an object, but received: ${typeof i}`);if(!Array.isArray(i.__ops))throw new q(`Transaction chunk must have __ops array, but received: ${typeof i.__ops}`);for(const s of i.__ops){if(!Array.isArray(s))throw new q(`Transaction operation must be an array, but received: ${typeof s}`);ii(s,t)}}};let ri=0;class oi{constructor(t,n,i){l(this,"type","sse");l(this,"initParams",null);l(this,"sendQueue",[]);l(this,"sendPromise");l(this,"closeFired",!1);l(this,"sseInitTimeout");l(this,"ES");l(this,"messageUrl");l(this,"conn");l(this,"url");l(this,"id");l(this,"onopen");l(this,"onmessage");l(this,"onclose");l(this,"onerror");this.id=`${this.type}_${ri++}`,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 an;(function(e){e.InitialSyncBatch="InitialSyncBatch",e.InitialSyncComplete="InitialSyncComplete",e.LoadFromStorage="LoadFromStorage",e.SyncTransaction="SyncTransaction",e.Error="Error"})(an||(an={}));function ai({WStream:e,opts:t,startStream:n,appendStream:i,registerStream:s}){const r=t.clientId;let o=null,a=null,u=null;const c=Ce();let d=!1,f=!1;const m=[],y=[],I=[];let w=!1,h=0,O=0;const b=[],k=new TextEncoder;function ee(){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 ue(p){return y.push(p),o&&p(o),()=>{const v=y.indexOf(p);v!==-1&&y.splice(v,1)}}function re(p){o=p;for(const v of y)v(o)}function $e(){w=!0}function Pt(p){let v=h,V=0,G=0;for(const{byteLen:ne}of b){const de=v+ne;if(de>p)break;v=de,V++,G+=ne}V>0&&(h+=G,O-=G,b.splice(0,V))}function te(p,v){a=v,ee(),p.error(v),Q()}async function fe(){const p=await n({clientId:r,reconnectToken:c,ruleParams:t.ruleParams});switch(p.type){case"ok":{const{streamId:v,offset:V}=p;o=v,Pt(V),b.length&&i({streamId:v,chunks:b.map(G=>G.chunk),offset:h}),w=!1;break}case"disconnect":{$e();break}case"error":{u&&te(u,p.error);break}}}function le(){$e(),fe()}function ke({offset:p,done:v}){Pt(p),v&&(d=!0,Q())}function Ee(p){return d?(te(p,new B("Stream has been closed.")),null):o||(te(p,new B("Stream has not been initialized.")),null)}async function At(p){u=p;let v=!0,V=0;for(;v;){let G=Date.now()+Math.min(15e3,500*(V-1));v=!1;const ne=await n({clientId:t.clientId,reconnectToken:c,ruleParams:t.ruleParams});switch(ne.type){case"ok":{const{streamId:de,offset:jt}=ne;if(jt!==0){const _e=new B("Write stream is corrupted");te(p,_e);return}re(de),s(de,{onDisconnect:$e,onFlush:ke,onConnectionReconnect:fe,onAppendFailed:le}),w=!1;return}case"disconnect":{v=!0,$e(),V++,await new Promise(de=>{setTimeout(de,Math.max(0,G-Date.now()))});break}case"error":{te(p,ne.error);return}}}}class Ji extends e{constructor(v,V){super(v,V)}async streamId(){return o||new Promise((v,V)=>{const G=[],ne=()=>{for(const _e of G)_e()},de=_e=>{v(_e),ne()},jt=_e=>{V(_e||new B("Stream is closed.")),ne()};G.push(ue(de)),G.push(D(jt))})}}return{stream:new Ji({async start(p){try{await At(p)}catch(v){te(p,v)}},write(p,v){const V=Ee(v);if(V){const G=k.encode(p).length;b.push({chunk:p,byteLen:G});const ne=h+O;O+=G,w||i({streamId:V,chunks:[p],offset:ne})}},close(){o?i({streamId:o,chunks:[],offset:h+O,isDone:!0}):Q(),ee()},abort(p){o?i({streamId:o,chunks:[],offset:h+O,isDone:!0,abortReason:p}):Q(),ee()}}),addCompleteCb:z,closed(){return f}}}class ci{constructor(){l(this,"items",[]);l(this,"resolvers",[]);l(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 ui({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 d=[];function f(){c=!0;for(const b of d)b()}function m(b){return d.push(b),()=>{const k=d.indexOf(b);k!==-1&&d.splice(k,1)}}function y(b,k){b.error(k),f()}let I=0;async function w(b,k){u=Ce();const ee={...b||{},eventId:u};for await(const D of n(ee)){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 B("Stream is corrupted.")),r=!0;return}let z=s-D.offset;if(D.files&&D.files.length){const Q=new AbortController;let ue=fetch(D.files[0].url,{signal:Q.signal});for(let re=0;re<D.files.length;re++){const $e=D.files[re+1],te=await ue;if($e&&(ue=fetch($e.url,{signal:Q.signal})),!te.ok){if(I++,I>10){y(k,new B("Unable to process stream."));return}return{retry:!0}}if(te.body){const fe=te.body.getReader();try{for(;;){const{done:le,value:ke}=await fe.read();if(le)break;if(r){Q.abort();return}let Ee=ke;if(z>0&&(Ee=ke.subarray(z),z-=ke.length-Ee.length),!Ee.length)continue;s+=Ee.length;const At=o.decode(Ee);k.enqueue(At)}}finally{fe.releaseLock()}}else{const fe=await te.arrayBuffer();let le=fe;if(r){Q.abort();return}if(z>0&&(le=new Uint8Array(fe).subarray(z),z-=fe.byteLength-le.length),!le.byteLength)continue;s+=le.byteLength;const ke=o.decode(le);k.enqueue(ke)}}}if(I=0,D.content){let Q=D.content,ue=a.encode(D.content);if(z>0){const re=ue.subarray(z);if(z-=ue.length-re.length,!re.length)continue;ue=re,Q=o.decode(re)}s+=ue.length,k.enqueue(Q)}}}async function h(b){let k=!0,ee=0;for(;k;){k=!1;let D=Date.now()+Math.min(15e3,500*(ee-1));const z=await w({...t,offset:s},b);z!=null&&z.retry&&(k=!0,ee++,D<Date.now()-3e5&&(ee=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 fi{constructor({WStream:t,RStream:n,trySend:i,log:s}){l(this,"trySend");l(this,"WStream");l(this,"RStream");l(this,"writeStreams",{});l(this,"startWriteStreamCbs",{});l(this,"readStreamIterators",{});l(this,"log");l(this,"activeStreams",new Set);this.WStream=t,this.RStream=n,this.trySend=i,this.log=s}createWriteStream(t){const{stream:n,addCompleteCb:i}=ai({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}=ui({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=Ce();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(Ce(),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 ci;return this.readStreamIterators[t]=a,this.trySend(t,o),a}cancelReadStream({eventId:t}){const n={op:"unsubscribe-stream","subscribe-event-id":t};this.trySend(Ce(),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 B(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!==li.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 B(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 B(t.message||"Unknown error",t.hint)}),s.close(),delete this.readStreamIterators[i]);break}}}hasActiveStreams(){return this.activeStreams.size>0}}const li={AUTHENTICATED:"authenticated"};function di(){return globalThis.__instantDbSchemaHashStore=globalThis.__instantDbSchemaHashStore??new WeakMap,globalThis.__instantDbSchemaHashStore}function hi(){return globalThis.__instantDbStore=globalThis.__instantDbStore??{},globalThis.__instantDbStore}hi(),di();class cn 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 bt(e){}function pi(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=bt,onError:n=bt,onRetry:i=bt,onComment:s}=e;let r="",o=!0,a,u="",c="";function d(w){const h=o?w.replace(/^\xEF\xBB\xBF/,""):w,[O,b]=mi(`${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 In=$=>{throw TypeError($)};var Gi=($,_,x)=>_ in $?Qi($,_,{enumerable:!0,configurable:!0,writable:!0,value:x}):$[_]=x;var l=($,_,x)=>Gi($,typeof _!="symbol"?_+"":_,x),Mt=($,_,x)=>_.has($)||In("Cannot "+x);var g=($,_,x)=>(Mt($,_,"read from private field"),x?x.call($):_.get($)),K=($,_,x)=>_.has($)?In("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add($):_.set($,x),he=($,_,x,P)=>(Mt($,_,"write to private field"),P?P.call($,x):_.set($,x),x),X=($,_,x)=>(Mt($,_,"access private method"),x);var Ue,N,Oe,W,F,U,On,st,$n,kn,En,et,tt,nt,Ut,_n,it;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 P=[];for(let e=0;e<256;++e)P.push((e+256).toString(16).slice(1));function Cn(e,t=0){return(P[e[t+0]]+P[e[t+1]]+P[e[t+2]]+P[e[t+3]]+"-"+P[e[t+4]]+P[e[t+5]]+"-"+P[e[t+6]]+P[e[t+7]]+"-"+P[e[t+8]]+P[e[t+9]]+"-"+P[e[t+10]]+P[e[t+11]]+P[e[t+12]]+P[e[t+13]]+P[e[t+14]]+P[e[t+15]]).toLowerCase()}let rt;const xn=new Uint8Array(16);function Tn(){if(!rt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");rt=crypto.getRandomValues.bind(crypto)}return rt(xn)}const Dt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Rn(e,t,n){var s;if(Dt.randomUUID&&!e)return Dt.randomUUID();e=e||{};const i=e.random??((s=e.rng)==null?void 0:s.call(e))??Tn();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,Cn(i)}const j={Remove:"remove",Replace:"replace",Add:"add"},Nt=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),Qe=Symbol.iterator,Y={mutable:"mutable",immutable:"immutable"},ot={};function De(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Lt(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 Wt(e){return Object.getPrototypeOf(e)===Set.prototype}function Ft(e){return Object.getPrototypeOf(e)===Map.prototype}function H(e){var t;return(t=e.copy)!==null&&t!==void 0?t:e.original}function at(e){return!!E(e)}function E(e){return typeof e!="object"?null:e==null?void 0:e[Nt]}function ct(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,Y))===Y.immutable||typeof n=="function")}function zt(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||De(n,r)))return null;t.push(r)}if(e.parent)return zt(e.parent,t);t.reverse();try{Pn(e.copy,t)}catch{return null}return t}function Ne(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function pe(e,t){return Ne(e)===2?e.get(t):e[t]}function ut(e,t,n){Ne(e)===2?e.set(t,n):e[t]=n}function ft(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 Pn(e,t){for(let n=0;n<t.length-1;n+=1){const i=t[n];if(e=pe(Ne(e)===3?Array.from(e):e,i),typeof e!="object")throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}return e}function An(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 jn=Object.prototype.propertyIsEnumerable;function Mn(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!Wt(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(!Ft(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,Y),n!==void 0)&&n!==Y.mutable){if(n===Y.immutable)return An(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=>{jn.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=Mn(e.original,e.options))}function Le(e){if(!ge(e))return ct(e);if(Array.isArray(e))return e.map(Le);if(e instanceof Map){const n=Array.from(e.entries()).map(([i,s])=>[i,Le(s)]);if(!Ft(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(Le);if(!Wt(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]=Le(e[n]);return t}function Ge(e){return at(e)?Le(e):e}function ie(e){var t;e.assignedMap=(t=e.assignedMap)!==null&&t!==void 0?t:new Map,e.operated||(e.operated=!0,e.parent&&ie(e.parent))}function Un(e,t){const n=Ne(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 Vt(e,t,n){if(at(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),Un(e,(r,o)=>{var a;if(at(o)){const u=E(o);L(u);const c=!((a=u.assignedMap)===null||a===void 0)&&a.size||u.operated?u.copy:u.original;ut(i?s:e,r,c)}else Vt(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 Dn(e,t){const n=e.type===3?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&Vt(pe(n,t),e.finalities.handledSet,e.options)}function lt(e){e.type===3&&e.copy&&(e.copy.clear(),e.setMap.forEach(t=>{e.copy.add(ct(t))}))}function dt(e,t,n,i){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&i){const r=zt(e);r&&t(e,r,n,i)}e.finalized=!0}}function ht(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),lt(e),dt(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)),ut(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)&&Dn(e,t)})}function Nn(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 d=t.concat([c]),f=Se(d,s);n.push({op:j.Replace,path:f,value:Ge(u[c])}),i.push({op:j.Replace,path:f,value:Ge(r[c])})}for(let c=r.length;c<u.length;c+=1){const d=t.concat([c]),f=Se(d,s);n.push({op:j.Add,path:f,value:Ge(u[c])})}if(r.length<u.length){const{arrayLengthAssignment:c=!0}=a.enablePatches;if(c){const d=t.concat(["length"]),f=Se(d,s);i.push({op:j.Replace,path:f,value:r.length})}else for(let d=u.length;r.length<d;d-=1){const f=t.concat([d-1]),m=Se(f,s);i.push({op:j.Remove,path:m})}}}function Ln({original:e,copy:t,assignedMap:n},i,s,r,o){n.forEach((a,u)=>{const c=pe(e,u),d=Ge(pe(t,u)),f=a?De(e,u)?j.Replace:j.Add:j.Remove;if(we(c,d)&&f===j.Replace)return;const m=i.concat(u),y=Se(m,o);s.push(f===j.Remove?{op:f,path:y}:{op:f,path:y,value:d}),r.push(f===j.Add?{op:j.Remove,path:y}:f===j.Remove?{op:j.Add,path:y,value:c}:{op:j.Replace,path:y,value:c})})}function Wn({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:j.Remove,path:c,value:a}),s.unshift({op:j.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:j.Add,path:c,value:a}),s.unshift({op:j.Remove,path:c,value:a})}o+=1})}function We(e,t,n,i){const{pathAsArray:s=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return Ln(e,t,n,i,s);case 1:return Nn(e,t,n,i,s);case 3:return Wn(e,t,n,i,s)}}const He=(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.")},pt={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),ie(n),n.assignedMap.set(e,!0),n.copy.set(e,t),ht(n,e,t,We)),this},delete(e){if(!this.has(e))return!1;const t=E(this);return L(t),ie(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),ie(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,Y))===Y.mutable;if(i.options.strict&&He(s,i.options,r),r||i.finalized||!ge(s,i.options)||s!==i.original.get(e))return s;const o=ot.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{[Qe]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[Qe]:()=>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]}}}},[Qe](){return this.entries()}},Fn=Reflect.ownKeys(pt),Jt=(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,Y))===Y.mutable;if(e.options.strict&&He(o,e.options,c),!c&&!u&&ge(o,e.options)&&!e.finalized&&e.original.has(o)){const d=ot.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,d),a=d}else u&&(a=u.proxy);return{done:!1,value:n?a:[a,a]}},Be={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),ie(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),ht(t,e,e,We)),this},delete(e){if(!this.has(e))return!1;const t=E(this);L(t),ie(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),ie(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:Jt(e,t,{isValuesIterator:!0})}},entries(){const e=E(this);L(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:Jt(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[Qe](){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(Be,{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 zn=Reflect.ownKeys(Be),Qt=new WeakSet,Gt={get(e,t,n){var i,s;const r=(i=e.copy)===null||i===void 0?void 0:i[t];if(r&&Qt.has(r))return r;if(t===Nt)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,Y),o===Y.mutable)return e.options.strict&&He(c,e.options,!0),c}const a=H(e);if(a instanceof Map&&Fn.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(pt,"size").get.call(e.proxy);const c=pt[t];if(c)return c.bind(e.proxy)}if(a instanceof Set&&zn.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(Be,"size").get.call(e.proxy);const c=Be[t];if(c)return c.bind(e.proxy)}if(!De(a,t)){const c=Lt(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&&He(u,e.options),e.finalized||!ge(u,e.options))return u;if(u===ft(e.original,t)){if(L(e),e.copy[t]=Ht({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),ie(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=Lt(H(e),t);if(r!=null&&r.set)return r.set.call(e.proxy,n),!0;const o=ft(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||De(e.original,t))||(L(e),ie(e),De(e.original,t)&&we(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,ht(e,t,n,We)),!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?Gt.set.call(this,e,t,void 0,e.proxy):(ft(e.original,t)!==void 0||t in e.original?(L(e),ie(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 Ht(e){const{original:t,parentDraft:n,key:i,finalities:s,options:r}=e,o=Ne(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,Gt);if(s.revoke.push(c),Qt.add(u),a.proxy=u,n){const d=n;d.finalities.draft.push((f,m)=>{var y,I;const w=E(u);let h=d.type===3?d.setMap:d.copy;const O=pe(h,i),b=E(O);if(b){let k=b.original;b.operated&&(k=ct(O)),lt(b),dt(b,We,f,m),d.options.enableAutoFreeze&&(d.options.updatedValues=(y=d.options.updatedValues)!==null&&y!==void 0?y:new WeakMap,d.options.updatedValues.set(k,b.original)),ut(h,i,k)}(I=w.callbacks)===null||I===void 0||I.forEach(k=>{k(f,m)})})}else{const d=E(u);d.finalities.draft.push((f,m)=>{lt(d),dt(d,We,f,m)})}return u}ot.createDraft=Ht,Object.prototype.constructor.toString();function Ce(){return Rn()}function Vn(e,t){return e.localeCompare(t)}function Jn(){let e=Vn;if(typeof Intl=="object"&&Intl.hasOwnProperty("Collator"))try{e=Intl.Collator("en-US").compare}catch{}return e}Jn();function Qn(){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 Gn=Qn();function qe(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(Gn.has(r))return(o,a)=>qe(e,t,[...n,a?[r,e,t,o,a]:[r,e,t,o]])}})}function Hn(e,t){return`lookup__${e}__${JSON.stringify(t)}`}function Bt(e){return e.startsWith("lookup__")}function qt(e){const[t,n,...i]=e.split("__");return[n,JSON.parse(i.join("__"))]}function Bn(e){return new Proxy({__etype:e},{get(t,n){if(n==="lookup")return(s,r)=>qe(e,qt(Hn(s,r)),[]);if(n==="__etype")return e;const i=n;return Bt(i)?qe(e,qt(i),[]):qe(e,i,[])}})}function Kt(){return new Proxy({},{get(e,t){return Bn(t)}})}Kt();function qn(e){return e.__ops}class B extends Error{constructor(n,i,s){super(n);l(this,"hint");l(this,"traceId");this.hint=i,s&&(this.traceId=s);const r=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,r),Error.captureStackTrace&&Error.captureStackTrace(this,B),this.name="InstantError"}get[Symbol.toStringTag](){return"InstantError"}}class Ie extends B{constructor(n){var r;const i=((r=n.body)==null?void 0:r.message)||`API Error (${n.status})`;super(i,n.body.hint,n.body["trace-id"]);l(this,"body");l(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 xe="v0.22.169";class oe{constructor(t,n,i,s={indexed:!1,unique:!1}){l(this,"valueType");l(this,"required");l(this,"isIndexed");l(this,"config");l(this,"metadata",{});this.valueType=t,this.required=n,this.isIndexed=i,this.config=s}clientRequired(){return new oe(this.valueType,!1,this.isIndexed,this.config)}optional(){return new oe(this.valueType,!1,this.isIndexed,this.config)}unique(){return new oe(this.valueType,this.required,this.isIndexed,{...this.config,unique:!0})}indexed(){return new oe(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 Xt=["where","order","limit","last","first","offset","after","afterInclusive","before","beforeInclusive","fields","aggregate"],Kn=e=>e.valueType||"unknown",Yt=(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}},Xn=(e,t,n,i,s,r,o)=>{const a=r.valueType==="json",u=(c,d,f)=>{if(!Yt(f,d,a))throw new C(`Invalid value for operator '${c}' on attribute '${i}' in entity '${s}'. Expected ${d}, 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)}},Te=(e,t,n,i,s)=>{const r=Kn(n),o=n.valueType==="json";if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(o)return;const u=e;for(const[c,d]of Object.entries(u))Xn(c,d,r,t,i,n,`${s}.${c}`)}else if(!Yt(e,r,o))throw new C(`Invalid value for attribute '${t}' in entity '${i}'. Expected ${r}, but received: ${typeof e}`,s)},Yn=(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 d=0;d<r.length-1;d++){const f=r[d],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);Te(t,e,new oe("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);Te(t,e,new oe("string",!1,!0),n,s);return}if(!c){const d=Object.keys(u.attrs);throw new C(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${d.length>0?d.join(", ")+", id":"id"}`,s)}Te(t,e,c,n,s)},Zt=(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&&Zt(c,t,n,`${i}.${s}[${c}]`);continue}if(s==="id"){Te(r,"id",new oe("string",!1,!0),t,`${i}.id`);continue}if(s.includes(".")){Yn(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),d=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: ${d.length>0?d.join(", "):"none"}`,`${i}.${s}`)}if(a)Te(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 oe("string",!1,!0);Te(r,s,c,t,`${i}.${s}`)}}},Zn=(e,t,n,i,s=0)=>{for(const o of Object.keys(e))if(!Xt.includes(o))throw new C(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${Xt.join(", ")}. Found: ${o}`,i);const r=["offset","before","beforeInclusive","after","afterInclusive","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);Zt(e.where,t,n,i?`${i}.where`:"where")}},en=(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&&en(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}.$`);Zn(a,t,n,`${i}.$`,s)}},tn=(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)}en(n[i],i,t,i,0)}}},nn=e=>typeof e!="string"?!1:Bt(e)?!0:x(e);class q extends Error{constructor(t){super(t),this.name="TransactionValidationError"}}const sn=e=>e.length>0?e.join(", "):"none",ei=(e,t)=>new q(`Entity '${e}' does not exist in schema. Available entities: ${sn(t)}`),mt={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},ti=(e,t)=>{var n;return e==null?!0:((n=mt[t.valueType])==null?void 0:n.call(mt,e))??!1},rn=(e,t)=>{const n=t.entities[e];if(!n)throw ei(e,Object.keys(t.entities));return n},yt=(e,t,n)=>{const i=rn(e,n);if(typeof t!="object"||t===null)throw new q(`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&&!ti(r,o))throw new q(`Invalid value for attribute '${s}' in entity '${e}'. Expected ${o.valueType}, but received: ${typeof r}`)}},on=(e,t,n)=>{const i=rn(e,n);if(typeof t!="object"||t===null)throw new q(`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 q(`Link '${s}' does not exist on entity '${e}'. Available links: ${sn(a)}`)}if(r!=null){if(Array.isArray(r)){for(const a of r)if(!nn(a))throw new q(`Invalid entity ID in link '${s}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`)}else if(!nn(r))throw new q(`Invalid UUID in link '${s}' for entity '${e}'. Expected a UUID, but received: ${r}`)}}},ni={create:yt,update:yt,merge:yt,link:on,unlink:on,delete:()=>{}},ii=(e,t)=>{if(!t)return;const[n,i,s,r]=e;if(!Array.isArray(s)&&!x(s))throw new q(`Invalid id for entity '${i}'. Expected a UUID, but received: ${s}`);if(typeof i!="string")throw new q(`Entity name must be a string, but received: ${typeof i}`);const o=ni[n];o&&r!==void 0&&o(i,r,t)},si=(e,t)=>{const n=Array.isArray(e)?e:[e];for(const i of n){if(!i||typeof i!="object")throw new q(`Transaction chunk must be an object, but received: ${typeof i}`);if(!Array.isArray(i.__ops))throw new q(`Transaction chunk must have __ops array, but received: ${typeof i.__ops}`);for(const s of i.__ops){if(!Array.isArray(s))throw new q(`Transaction operation must be an array, but received: ${typeof s}`);ii(s,t)}}};let ri=0;class oi{constructor(t,n,i){l(this,"type","sse");l(this,"initParams",null);l(this,"sendQueue",[]);l(this,"sendPromise");l(this,"closeFired",!1);l(this,"sseInitTimeout");l(this,"ES");l(this,"messageUrl");l(this,"conn");l(this,"url");l(this,"id");l(this,"onopen");l(this,"onmessage");l(this,"onclose");l(this,"onerror");this.id=`${this.type}_${ri++}`,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 an;(function(e){e.InitialSyncBatch="InitialSyncBatch",e.InitialSyncComplete="InitialSyncComplete",e.LoadFromStorage="LoadFromStorage",e.SyncTransaction="SyncTransaction",e.Error="Error"})(an||(an={}));function ai({WStream:e,opts:t,startStream:n,appendStream:i,registerStream:s}){const r=t.clientId;let o=null,a=null,u=null;const c=Ce();let d=!1,f=!1;const m=[],y=[],I=[];let w=!1,h=0,O=0;const b=[],k=new TextEncoder;function ee(){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 ue(p){return y.push(p),o&&p(o),()=>{const v=y.indexOf(p);v!==-1&&y.splice(v,1)}}function re(p){o=p;for(const v of y)v(o)}function $e(){w=!0}function Pt(p){let v=h,V=0,G=0;for(const{byteLen:ne}of b){const de=v+ne;if(de>p)break;v=de,V++,G+=ne}V>0&&(h+=G,O-=G,b.splice(0,V))}function te(p,v){a=v,ee(),p.error(v),Q()}async function fe(){const p=await n({clientId:r,reconnectToken:c,ruleParams:t.ruleParams});switch(p.type){case"ok":{const{streamId:v,offset:V}=p;o=v,Pt(V),b.length&&i({streamId:v,chunks:b.map(G=>G.chunk),offset:h}),w=!1;break}case"disconnect":{$e();break}case"error":{u&&te(u,p.error);break}}}function le(){$e(),fe()}function ke({offset:p,done:v}){Pt(p),v&&(d=!0,Q())}function Ee(p){return d?(te(p,new B("Stream has been closed.")),null):o||(te(p,new B("Stream has not been initialized.")),null)}async function At(p){u=p;let v=!0,V=0;for(;v;){let G=Date.now()+Math.min(15e3,500*(V-1));v=!1;const ne=await n({clientId:t.clientId,reconnectToken:c,ruleParams:t.ruleParams});switch(ne.type){case"ok":{const{streamId:de,offset:jt}=ne;if(jt!==0){const _e=new B("Write stream is corrupted");te(p,_e);return}re(de),s(de,{onDisconnect:$e,onFlush:ke,onConnectionReconnect:fe,onAppendFailed:le}),w=!1;return}case"disconnect":{v=!0,$e(),V++,await new Promise(de=>{setTimeout(de,Math.max(0,G-Date.now()))});break}case"error":{te(p,ne.error);return}}}}class Ji extends e{constructor(v,V){super(v,V)}async streamId(){return o||new Promise((v,V)=>{const G=[],ne=()=>{for(const _e of G)_e()},de=_e=>{v(_e),ne()},jt=_e=>{V(_e||new B("Stream is closed.")),ne()};G.push(ue(de)),G.push(D(jt))})}}return{stream:new Ji({async start(p){try{await At(p)}catch(v){te(p,v)}},write(p,v){const V=Ee(v);if(V){const G=k.encode(p).length;b.push({chunk:p,byteLen:G});const ne=h+O;O+=G,w||i({streamId:V,chunks:[p],offset:ne})}},close(){o?i({streamId:o,chunks:[],offset:h+O,isDone:!0}):Q(),ee()},abort(p){o?i({streamId:o,chunks:[],offset:h+O,isDone:!0,abortReason:p}):Q(),ee()}}),addCompleteCb:z,closed(){return f}}}class ci{constructor(){l(this,"items",[]);l(this,"resolvers",[]);l(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 ui({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 d=[];function f(){c=!0;for(const b of d)b()}function m(b){return d.push(b),()=>{const k=d.indexOf(b);k!==-1&&d.splice(k,1)}}function y(b,k){b.error(k),f()}let I=0;async function w(b,k){u=Ce();const ee={...b||{},eventId:u};for await(const D of n(ee)){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 B("Stream is corrupted.")),r=!0;return}let z=s-D.offset;if(D.files&&D.files.length){const Q=new AbortController;let ue=fetch(D.files[0].url,{signal:Q.signal});for(let re=0;re<D.files.length;re++){const $e=D.files[re+1],te=await ue;if($e&&(ue=fetch($e.url,{signal:Q.signal})),!te.ok){if(I++,I>10){y(k,new B("Unable to process stream."));return}return{retry:!0}}if(te.body){const fe=te.body.getReader();try{for(;;){const{done:le,value:ke}=await fe.read();if(le)break;if(r){Q.abort();return}let Ee=ke;if(z>0&&(Ee=ke.subarray(z),z-=ke.length-Ee.length),!Ee.length)continue;s+=Ee.length;const At=o.decode(Ee);k.enqueue(At)}}finally{fe.releaseLock()}}else{const fe=await te.arrayBuffer();let le=fe;if(r){Q.abort();return}if(z>0&&(le=new Uint8Array(fe).subarray(z),z-=fe.byteLength-le.length),!le.byteLength)continue;s+=le.byteLength;const ke=o.decode(le);k.enqueue(ke)}}}if(I=0,D.content){let Q=D.content,ue=a.encode(D.content);if(z>0){const re=ue.subarray(z);if(z-=ue.length-re.length,!re.length)continue;ue=re,Q=o.decode(re)}s+=ue.length,k.enqueue(Q)}}}async function h(b){let k=!0,ee=0;for(;k;){k=!1;let D=Date.now()+Math.min(15e3,500*(ee-1));const z=await w({...t,offset:s},b);z!=null&&z.retry&&(k=!0,ee++,D<Date.now()-3e5&&(ee=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 fi{constructor({WStream:t,RStream:n,trySend:i,log:s}){l(this,"trySend");l(this,"WStream");l(this,"RStream");l(this,"writeStreams",{});l(this,"startWriteStreamCbs",{});l(this,"readStreamIterators",{});l(this,"log");l(this,"activeStreams",new Set);this.WStream=t,this.RStream=n,this.trySend=i,this.log=s}createWriteStream(t){const{stream:n,addCompleteCb:i}=ai({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}=ui({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=Ce();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(Ce(),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 ci;return this.readStreamIterators[t]=a,this.trySend(t,o),a}cancelReadStream({eventId:t}){const n={op:"unsubscribe-stream","subscribe-event-id":t};this.trySend(Ce(),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 B(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!==li.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 B(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 B(t.message||"Unknown error",t.hint)}),s.close(),delete this.readStreamIterators[i]);break}}}hasActiveStreams(){return this.activeStreams.size>0}}const li={AUTHENTICATED:"authenticated"};function di(){return globalThis.__instantDbSchemaHashStore=globalThis.__instantDbSchemaHashStore??new WeakMap,globalThis.__instantDbSchemaHashStore}function hi(){return globalThis.__instantDbStore=globalThis.__instantDbStore??{},globalThis.__instantDbStore}hi(),di();class cn 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 bt(e){}function pi(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=bt,onError:n=bt,onRetry:i=bt,onComment:s}=e;let r="",o=!0,a,u="",c="";function d(w){const h=o?w.replace(/^\xEF\xBB\xBF/,""):w,[O,b]=mi(`${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 cn(`Invalid \`retry\` value: "${h}"`,{type:"invalid-retry",value:h,line:O}));break;default:n(new cn(`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:d,reset:I}}function mi(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.169",
|
|
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.169"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"test": "vitest",
|