@sidekickdb/resumable-stream 2.0.0 → 2.0.1
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,15 +1,15 @@
|
|
|
1
1
|
|
|
2
|
-
> @sidekickdb/resumable-stream@2.0.
|
|
2
|
+
> @sidekickdb/resumable-stream@2.0.1 build /home/runner/work/sidekick/sidekick/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. See `npm help npmrc` for supported config options.
|
|
6
6
|
|
|
7
|
-
> @sidekickdb/resumable-stream@2.0.
|
|
7
|
+
> @sidekickdb/resumable-stream@2.0.1 build:tshy
|
|
8
8
|
> tshy
|
|
9
9
|
|
|
10
10
|
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
|
|
11
11
|
|
|
12
|
-
> @sidekickdb/resumable-stream@2.0.
|
|
12
|
+
> @sidekickdb/resumable-stream@2.0.1 build:standalone
|
|
13
13
|
> vite build
|
|
14
14
|
|
|
15
15
|
[36mvite v5.4.14 [32mbuilding for production...[36m[39m
|
|
@@ -19,14 +19,14 @@ rendering chunks...
|
|
|
19
19
|
computing gzip size...
|
|
20
20
|
[2mdist/standalone/[22m[36mindex.umd.cjs [39m[1m[2m78.37 kB[22m[1m[22m[2m │ gzip: 24.84 kB[22m
|
|
21
21
|
[2mdist/standalone/[22m[36mindex.js [39m[1m[2m135.27 kB[22m[1m[22m[2m │ gzip: 36.29 kB[22m
|
|
22
|
-
[32m✓ built in
|
|
22
|
+
[32m✓ built in 729ms[39m
|
|
23
23
|
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
|
|
24
24
|
|
|
25
|
-
> @sidekickdb/resumable-stream@2.0.
|
|
25
|
+
> @sidekickdb/resumable-stream@2.0.1 check-exports
|
|
26
26
|
> attw --pack .
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
@sidekickdb/resumable-stream v2.0.
|
|
29
|
+
@sidekickdb/resumable-stream v2.0.1
|
|
30
30
|
|
|
31
31
|
Build tools:
|
|
32
32
|
- @arethetypeswrong/cli@^0.18.5
|
package/dist/standalone/index.js
CHANGED
|
@@ -834,7 +834,7 @@ class ue extends x {
|
|
|
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 xe = "v2.0.
|
|
837
|
+
const xe = "v2.0.1";
|
|
838
838
|
class ce {
|
|
839
839
|
constructor(t, n, s, r = { indexed: !1, unique: !1 }) {
|
|
840
840
|
d(this, "valueType");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(E,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(E=typeof globalThis<"u"?globalThis:E||self,x(E.instant={}))})(this,function(E){"use strict";var Ir=Object.defineProperty;var Mn=E=>{throw TypeError(E)};var kr=(E,x,P)=>x in E?Ir(E,x,{enumerable:!0,configurable:!0,writable:!0,value:P}):E[x]=P;var d=(E,x,P)=>kr(E,typeof x!="symbol"?x+"":x,P),Kt=(E,x,P)=>x.has(E)||Mn("Cannot "+P);var f=(E,x,P)=>(Kt(E,x,"read from private field"),P?P.call(E):x.get(E)),k=(E,x,P)=>x.has(E)?Mn("Cannot add the same private member more than once"):x instanceof WeakSet?x.add(E):x.set(E,P),S=(E,x,P,D)=>(Kt(E,x,"write to private field"),D?D.call(E,P):x.set(E,P),P),O=(E,x,P)=>(Kt(E,x,"access private method"),P);var q,be,ve,qe,Be,Qe,Me,Oe,De,le,Ee,Ce,xe,Ne,B,Vt,ct,ut,Dn,ft,dt,Ze,Jt,lt,Q,Ge,Le,Fe,Xe,ee,ae,Ye,Te,ze,K,_e,G,X,F,Ln,gt,Fn,zn,Wn,ht,pt,yt,Ht,Kn,mt;const x=/^(?:[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 P(e){return typeof e=="string"&&x.test(e)}const D=[];for(let e=0;e<256;++e)D.push((e+256).toString(16).slice(1));function Vn(e,t=0){return(D[e[t+0]]+D[e[t+1]]+D[e[t+2]]+D[e[t+3]]+"-"+D[e[t+4]]+D[e[t+5]]+"-"+D[e[t+6]]+D[e[t+7]]+"-"+D[e[t+8]]+D[e[t+9]]+"-"+D[e[t+10]]+D[e[t+11]]+D[e[t+12]]+D[e[t+13]]+D[e[t+14]]+D[e[t+15]]).toLowerCase()}let wt;const Jn=new Uint8Array(16);function Hn(){if(!wt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");wt=crypto.getRandomValues.bind(crypto)}return wt(Jn)}const qt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qn(e,t,n){var r;if(qt.randomUUID&&!e)return qt.randomUUID();e=e||{};const s=e.random??((r=e.rng)==null?void 0:r.call(e))??Hn();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,Vn(s)}const L={Remove:"remove",Replace:"replace",Add:"add"},Bt=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),et=Symbol.iterator,se={mutable:"mutable",immutable:"immutable"},St={};function Ke(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Qt(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const s=Reflect.getOwnPropertyDescriptor(n,t);if(s)return s;n=Reflect.getPrototypeOf(n)}}}function Gt(e){return Object.getPrototypeOf(e)===Set.prototype}function Xt(e){return Object.getPrototypeOf(e)===Map.prototype}function Z(e){var t;return(t=e.copy)!==null&&t!==void 0?t:e.original}function It(e){return!!C(e)}function C(e){return typeof e!="object"?null:e==null?void 0:e[Bt]}function kt(e){var t;const n=C(e);return n?(t=n.copy)!==null&&t!==void 0?t:n.original:e}function Se(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,se))===se.immutable||typeof n=="function")}function Yt(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,s=C(pe(n,e.key));if(s!==null&&(s==null?void 0:s.original)!==e.original)return null;const r=e.parent.type===3,i=r?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(r&&n.size>i||Ke(n,i)))return null;t.push(i)}if(e.parent)return Yt(e.parent,t);t.reverse();try{Bn(e.copy,t)}catch{return null}return t}function Ve(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function pe(e,t){return Ve(e)===2?e.get(t):e[t]}function $t(e,t,n){Ve(e)===2?e.set(t,n):e[t]=n}function vt(e,t){const n=C(e);return(n?Z(n):e)[t]}function Ie(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function ke(e,t){return t?e:[""].concat(e).map(n=>{const s=`${n}`;return s.indexOf("/")===-1&&s.indexOf("~")===-1?s:s.replace(/~/g,"~0").replace(/\//g,"~1")}).join("/")}function Bn(e,t){for(let n=0;n<t.length-1;n+=1){const s=t[n];if(e=pe(Ve(e)===3?Array.from(e):e,s),typeof e!="object")throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}return e}function Qn(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach(n=>{let s=Reflect.getOwnPropertyDescriptor(e,n);if(s.enumerable&&s.configurable&&s.writable){t[n]=e[n];return}s.writable||(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(s={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[n]}),Reflect.defineProperty(t,n,s)}),t}const Gn=Object.prototype.propertyIsEnumerable;function Xn(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!Gt(e)){const s=Object.getPrototypeOf(e).constructor;return new s(e.values())}return Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values())}else if(e instanceof Map){if(!Xt(e)){const s=Object.getPrototypeOf(e).constructor;return new s(e)}return new Map(e)}else if(t!=null&&t.mark&&(n=t.mark(e,se),n!==void 0)&&n!==se.mutable){if(n===se.immutable)return Qn(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 s={};return Object.keys(e).forEach(r=>{s[r]=e[r]}),Object.getOwnPropertySymbols(e).forEach(r=>{Gn.call(e,r)&&(s[r]=e[r])}),s}else throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function H(e){e.copy||(e.copy=Xn(e.original,e.options))}function Je(e){if(!Se(e))return kt(e);if(Array.isArray(e))return e.map(Je);if(e instanceof Map){const n=Array.from(e.entries()).map(([s,r])=>[s,Je(r)]);if(!Xt(e)){const s=Object.getPrototypeOf(e).constructor;return new s(n)}return new Map(n)}if(e instanceof Set){const n=Array.from(e).map(Je);if(!Gt(e)){const s=Object.getPrototypeOf(e).constructor;return new s(n)}return new Set(n)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=Je(e[n]);return t}function tt(e){return It(e)?Je(e):e}function ce(e){var t;e.assignedMap=(t=e.assignedMap)!==null&&t!==void 0?t:new Map,e.operated||(e.operated=!0,e.parent&&ce(e.parent))}function Yn(e,t){const n=Ve(e);if(n===0)Reflect.ownKeys(e).forEach(s=>{t(s,e[s],e)});else if(n===1){let s=0;for(const r of e)t(s,r,e),s+=1}else e.forEach((s,r)=>t(r,s,e))}function Zt(e,t,n){if(It(e)||!Se(e,n)||t.has(e)||Object.isFrozen(e))return;const s=e instanceof Set,r=s?new Map:void 0;if(t.add(e),Yn(e,(i,o)=>{var a;if(It(o)){const c=C(o);H(c);const u=!((a=c.assignedMap)===null||a===void 0)&&a.size||c.operated?c.copy:c.original;$t(s?r:e,i,u)}else Zt(o,t,n)}),r){const i=e,o=Array.from(i);i.clear(),o.forEach(a=>{i.add(r.has(a)?r.get(a):a)})}}function Zn(e,t){const n=e.type===3?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&Zt(pe(n,t),e.finalities.handledSet,e.options)}function Ot(e){e.type===3&&e.copy&&(e.copy.clear(),e.setMap.forEach(t=>{e.copy.add(kt(t))}))}function Et(e,t,n,s){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&s){const i=Yt(e);i&&t(e,i,n,s)}e.finalized=!0}}function Ct(e,t,n,s){const r=C(n);r&&(r.callbacks||(r.callbacks=[]),r.callbacks.push((i,o)=>{var a;const c=e.type===3?e.setMap:e.copy;if(Ie(pe(c,t),n)){let u=r.original;r.copy&&(u=r.copy),Ot(e),Et(e,s,i,o),e.options.enableAutoFreeze&&(e.options.updatedValues=(a=e.options.updatedValues)!==null&&a!==void 0?a:new WeakMap,e.options.updatedValues.set(u,r.original)),$t(c,t,u)}}),e.options.enableAutoFreeze&&r.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),Se(n,e.options)&&e.finalities.draft.push(()=>{const i=e.type===3?e.setMap:e.copy;Ie(pe(i,t),n)&&Zn(e,t)})}function es(e,t,n,s,r){let{original:i,assignedMap:o,options:a}=e,c=e.copy;c.length<i.length&&([i,c]=[c,i],[n,s]=[s,n]);for(let u=0;u<i.length;u+=1)if(o.get(u.toString())&&c[u]!==i[u]){const h=t.concat([u]),l=ke(h,r);n.push({op:L.Replace,path:l,value:tt(c[u])}),s.push({op:L.Replace,path:l,value:tt(i[u])})}for(let u=i.length;u<c.length;u+=1){const h=t.concat([u]),l=ke(h,r);n.push({op:L.Add,path:l,value:tt(c[u])})}if(i.length<c.length){const{arrayLengthAssignment:u=!0}=a.enablePatches;if(u){const h=t.concat(["length"]),l=ke(h,r);s.push({op:L.Replace,path:l,value:i.length})}else for(let h=c.length;i.length<h;h-=1){const l=t.concat([h-1]),y=ke(l,r);s.push({op:L.Remove,path:y})}}}function ts({original:e,copy:t,assignedMap:n},s,r,i,o){n.forEach((a,c)=>{const u=pe(e,c),h=tt(pe(t,c)),l=a?Ke(e,c)?L.Replace:L.Add:L.Remove;if(Ie(u,h)&&l===L.Replace)return;const y=s.concat(c),m=ke(y,o);r.push(l===L.Remove?{op:l,path:m}:{op:l,path:m,value:h}),i.push(l===L.Add?{op:L.Remove,path:m}:l===L.Remove?{op:L.Add,path:m,value:u}:{op:L.Replace,path:m,value:u})})}function ns({original:e,copy:t},n,s,r,i){let o=0;e.forEach(a=>{if(!t.has(a)){const c=n.concat([o]),u=ke(c,i);s.push({op:L.Remove,path:u,value:a}),r.unshift({op:L.Add,path:u,value:a})}o+=1}),o=0,t.forEach(a=>{if(!e.has(a)){const c=n.concat([o]),u=ke(c,i);s.push({op:L.Add,path:u,value:a}),r.unshift({op:L.Remove,path:u,value:a})}o+=1})}function He(e,t,n,s){const{pathAsArray:r=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return ts(e,t,n,s,r);case 1:return es(e,t,n,s,r);case 3:return ns(e,t,n,s,r)}}const nt=(e,t,n=!1)=>{if(typeof e=="object"&&e!==null&&(!Se(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},xt={get size(){return Z(C(this)).size},has(e){return Z(C(this)).has(e)},set(e,t){const n=C(this),s=Z(n);return(!s.has(e)||!Ie(s.get(e),t))&&(H(n),ce(n),n.assignedMap.set(e,!0),n.copy.set(e,t),Ct(n,e,t,He)),this},delete(e){if(!this.has(e))return!1;const t=C(this);return H(t),ce(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=C(this);if(this.size){H(e),ce(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){const n=C(this);Z(n).forEach((s,r)=>{e.call(t,this.get(r),r,this)})},get(e){var t,n;const s=C(this),r=Z(s).get(e),i=((n=(t=s.options).mark)===null||n===void 0?void 0:n.call(t,r,se))===se.mutable;if(s.options.strict&&nt(r,s.options,i),i||s.finalized||!Se(r,s.options)||r!==s.original.get(e))return r;const o=St.createDraft({original:r,parentDraft:s,key:e,finalities:s.finalities,options:s.options});return H(s),s.copy.set(e,o),o},keys(){return Z(C(this)).keys()},values(){const e=this.keys();return{[et]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[et]:()=>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]}}}},[et](){return this.entries()}},ss=Reflect.ownKeys(xt),en=(e,t,{isValuesIterator:n})=>()=>{var s,r;const i=t.next();if(i.done)return i;const o=i.value;let a=e.setMap.get(o);const c=C(a),u=((r=(s=e.options).mark)===null||r===void 0?void 0:r.call(s,a,se))===se.mutable;if(e.options.strict&&nt(o,e.options,u),!u&&!c&&Se(o,e.options)&&!e.finalized&&e.original.has(o)){const h=St.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,h),a=h}else c&&(a=c.proxy);return{done:!1,value:n?a:[a,a]}},st={get size(){return C(this).setMap.size},has(e){const t=C(this);if(t.setMap.has(e))return!0;H(t);const n=C(e);return!!(n&&t.setMap.has(n.original))},add(e){const t=C(this);return this.has(e)||(H(t),ce(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),Ct(t,e,e,He)),this},delete(e){if(!this.has(e))return!1;const t=C(this);H(t),ce(t);const n=C(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=C(this);H(e),ce(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=C(this);H(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:en(e,t,{isValuesIterator:!0})}},entries(){const e=C(this);H(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:en(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[et](){return this.values()},forEach(e,t){const n=this.values();let s=n.next();for(;!s.done;)e.call(t,s.value,s.value,this),s=n.next()}};Set.prototype.difference&&Object.assign(st,{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 rs=Reflect.ownKeys(st),tn=new WeakSet,nn={get(e,t,n){var s,r;const i=(s=e.copy)===null||s===void 0?void 0:s[t];if(i&&tn.has(i))return i;if(t===Bt)return e;let o;if(e.options.mark){const u=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(u,se),o===se.mutable)return e.options.strict&&nt(u,e.options,!0),u}const a=Z(e);if(a instanceof Map&&ss.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(xt,"size").get.call(e.proxy);const u=xt[t];if(u)return u.bind(e.proxy)}if(a instanceof Set&&rs.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(st,"size").get.call(e.proxy);const u=st[t];if(u)return u.bind(e.proxy)}if(!Ke(a,t)){const u=Qt(a,t);return u?"value"in u?u.value:(r=u.get)===null||r===void 0?void 0:r.call(e.proxy):void 0}const c=a[t];if(e.options.strict&&nt(c,e.options),e.finalized||!Se(c,e.options))return c;if(c===vt(e.original,t)){if(H(e),e.copy[t]=sn({original:e.original[t],parentDraft:e,key:e.type===1?Number(t):t,finalities:e.finalities,options:e.options}),typeof o=="function"){const u=C(e.copy[t]);return H(u),ce(u),u.copy}return e.copy[t]}return c},set(e,t,n){var s;if(e.type===3||e.type===2)throw new Error("Map/Set draft does not support any property assignment.");let r;if(e.type===1&&t!=="length"&&!(Number.isInteger(r=Number(t))&&r>=0&&(t===0||r===0||String(r)===String(t))))throw new Error("Only supports setting array indices and the 'length' property.");const i=Qt(Z(e),t);if(i!=null&&i.set)return i.set.call(e.proxy,n),!0;const o=vt(Z(e),t),a=C(o);return a&&Ie(a.original,n)?(e.copy[t]=n,e.assignedMap=(s=e.assignedMap)!==null&&s!==void 0?s:new Map,e.assignedMap.set(t,!1),!0):(Ie(n,o)&&(n!==void 0||Ke(e.original,t))||(H(e),ce(e),Ke(e.original,t)&&Ie(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,Ct(e,t,n,He)),!0)},has(e,t){return t in Z(e)},ownKeys(e){return Reflect.ownKeys(Z(e))},getOwnPropertyDescriptor(e,t){const n=Z(e),s=Reflect.getOwnPropertyDescriptor(n,t);return s&&{writable:!0,configurable:e.type!==1||t!=="length",enumerable:s.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?nn.set.call(this,e,t,void 0,e.proxy):(vt(e.original,t)!==void 0||t in e.original?(H(e),ce(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 sn(e){const{original:t,parentDraft:n,key:s,finalities:r,options:i}=e,o=Ve(t),a={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:r,options:i,setMap:o===3?new Map(t.entries()):void 0};(s||"key"in e)&&(a.key=s);const{proxy:c,revoke:u}=Proxy.revocable(o===1?Object.assign([],a):a,nn);if(r.revoke.push(u),tn.add(c),a.proxy=c,n){const h=n;h.finalities.draft.push((l,y)=>{var m,g;const w=C(c);let p=h.type===3?h.setMap:h.copy;const $=pe(p,s),v=C($);if(v){let V=v.original;v.operated&&(V=kt($)),Ot(v),Et(v,He,l,y),h.options.enableAutoFreeze&&(h.options.updatedValues=(m=h.options.updatedValues)!==null&&m!==void 0?m:new WeakMap,h.options.updatedValues.set(V,v.original)),$t(p,s,V)}(g=w.callbacks)===null||g===void 0||g.forEach(V=>{V(l,y)})})}else{const h=C(c);h.finalities.draft.push((l,y)=>{Ot(h),Et(h,He,l,y)})}return c}St.createDraft=sn,Object.prototype.constructor.toString();function Pe(){return qn()}function is(e,t){return e.localeCompare(t)}function os(){let e=is;if(typeof Intl=="object"&&Intl.hasOwnProperty("Collator"))try{e=Intl.Collator("en-US").compare}catch{}return e}os();function as(){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 cs=as();function rt(e,t,n){const s={__etype:e,__ops:n};return new Proxy(s,{get:(r,i)=>{if(i==="__ops")return n;if(i==="__etype")return e;if(cs.has(i))return(o,a)=>rt(e,t,[...n,a?[i,e,t,o,a]:[i,e,t,o]])}})}function us(e,t){return`lookup__${e}__${JSON.stringify(t)}`}function rn(e){return e.startsWith("lookup__")}function on(e){const[t,n,...s]=e.split("__");return[n,JSON.parse(s.join("__"))]}function fs(e){return new Proxy({__etype:e},{get(t,n){if(n==="lookup")return(r,i)=>rt(e,on(us(r,i)),[]);if(n==="__etype")return e;const s=n;return rn(s)?rt(e,on(s),[]):rt(e,s,[])}})}function an(){return new Proxy({},{get(e,t){return fs(t)}})}an();function ds(e){return e.__ops}class _ extends Error{constructor(n,s,r){super(n);d(this,"hint");d(this,"traceId");this.hint=s,r&&(this.traceId=r);const i=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,i),Error.captureStackTrace&&Error.captureStackTrace(this,_),this.name="InstantError"}get[Symbol.toStringTag](){return"InstantError"}}class ue extends _{constructor(n){var i,o;const s=((i=n.body)==null?void 0:i.message)||`API Error (${n.status})`;super(s,n.body.hint,((o=n.body)==null?void 0:o.traceId)||n.body["trace-id"]);d(this,"body");d(this,"status");const r=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,r),Error.captureStackTrace&&Error.captureStackTrace(this,ue),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="v2.0.0";class fe{constructor(t,n,s,r={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=s,this.config=r}clientRequired(){return new fe(this.valueType,!1,this.isIndexed,this.config)}optional(){return new fe(this.valueType,!1,this.isIndexed,this.config)}unique(){return new fe(this.valueType,this.required,this.isIndexed,{...this.config,unique:!0})}indexed(){return new fe(this.valueType,this.required,!0,{...this.config,indexed:!0})}}class A extends Error{constructor(t,n){const s=n?`At path '${n}': ${t}`:t;super(s),this.name="QueryValidationError"}}const cn=["where","order","limit","last","first","offset","after","afterInclusive","before","beforeInclusive","fields","aggregate"],ls=e=>e.valueType||"unknown",un=(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}},hs=(e,t,n,s,r,i,o)=>{const a=i.valueType==="json",c=(u,h,l)=>{if(!un(l,h,a))throw new A(`Invalid value for operator '${u}' on attribute '${s}' in entity '${r}'. Expected ${h}, but received: ${typeof l}`,o)};switch(e){case"in":case"$in":if(!Array.isArray(t))throw new A(`Operator '${e}' for attribute '${s}' in entity '${r}' must be an array, but received: ${typeof t}`,o);for(const u of t)c(e,n,u);break;case"$not":case"$ne":case"$gt":case"$lt":case"$gte":case"$lte":c(e,n,t);break;case"$like":case"$ilike":if(c(e,"string",t),e==="$ilike"&&!i.isIndexed)throw new A(`Operator '${e}' can only be used with indexed attributes, but '${s}' in entity '${r}' is not indexed`,o);break;case"$isNull":c(e,"boolean",t);break;default:throw new A(`Unknown operator '${e}' for attribute '${s}' in entity '${r}'`,o)}},je=(e,t,n,s,r)=>{const i=ls(n),o=n.valueType==="json";if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(o)return;const c=e;for(const[u,h]of Object.entries(c))hs(u,h,i,t,s,n,`${r}.${u}`)}else if(!un(e,i,o))throw new A(`Invalid value for attribute '${t}' in entity '${s}'. Expected ${i}, but received: ${typeof e}`,r)},ps=(e,t,n,s,r)=>{const i=e.split(".");if(i.length<2)throw new A(`Invalid dot notation path '${e}'. Must contain at least one dot.`,r);let o=n;for(let h=0;h<i.length-1;h++){const l=i[h],y=s.entities[o];if(!y)throw new A(`Entity '${o}' does not exist in schema while traversing dot notation path '${e}'.`,r);const m=y.links[l];if(!m){const g=Object.keys(y.links);throw new A(`Link '${l}' does not exist on entity '${o}' in dot notation path '${e}'. Available links: ${g.length>0?g.join(", "):"none"}`,r)}o=m.entityName}const a=i[i.length-1],c=s.entities[o];if(!c)throw new A(`Target entity '${o}' does not exist in schema for dot notation path '${e}'.`,r);if(a==="id"){if(typeof t=="string"&&!P(t))throw new A(`Invalid value for id field in entity '${o}'. Expected a UUID, but received: ${t}`,r);je(t,e,new fe("string",!1,!0),n,r);return}const u=c.attrs[a];if(Object.keys(c.links).includes(a)){if(typeof t=="string"&&!P(t))throw new A(`Invalid value for link '${a}' in entity '${o}'. Expected a UUID, but received: ${t}`,r);je(t,e,new fe("string",!1,!0),n,r);return}if(!u){const h=Object.keys(c.attrs);throw new A(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${h.length>0?h.join(", ")+", id":"id"}`,r)}je(t,e,u,n,r)},fn=(e,t,n,s)=>{for(const[r,i]of Object.entries(e)){if(r==="or"||r==="and"){if(Array.isArray(i))for(const u of i)typeof u=="object"&&u!==null&&fn(u,t,n,`${s}.${r}[${u}]`);continue}if(r==="id"){je(i,"id",new fe("string",!1,!0),t,`${s}.id`);continue}if(r.includes(".")){ps(r,i,t,n,`${s}.${r}`);continue}const o=n.entities[t];if(!o)continue;const a=o.attrs[r],c=o.links[r];if(!a&&!c){const u=Object.keys(o.attrs),h=Object.keys(o.links);throw new A(`Attribute or link '${r}' does not exist on entity '${t}'. Available attributes: ${u.length>0?u.join(", "):"none"}. Available links: ${h.length>0?h.join(", "):"none"}`,`${s}.${r}`)}if(a)je(i,r,a,t,`${s}.${r}`);else if(c){if(typeof i=="string"&&!P(i))throw new A(`Invalid value for link '${r}' in entity '${t}'. Expected a UUID, but received: ${i}`,`${s}.${r}`);const u=new fe("string",!1,!0);je(i,r,u,t,`${s}.${r}`)}}},ys=(e,t,n,s,r=0)=>{for(const o of Object.keys(e))if(!cn.includes(o))throw new A(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${cn.join(", ")}. Found: ${o}`,s);const i=["offset","before","beforeInclusive","after","afterInclusive","first","last"];for(const o of i)if(e[o]!==void 0&&r>0)throw new A(`'${o}' can only be used on top-level namespaces. It cannot be used in nested queries.`,s);if(e.where&&n){if(typeof e.where!="object"||e.where===null)throw new A(`'where' clause must be an object in entity '${t}', but received: ${typeof e.where}`,s?`${s}.where`:void 0);fn(e.where,t,n,s?`${s}.where`:"where")}},dn=(e,t,n,s,r=0)=>{var i;if(!e||typeof e!="object")throw new A(`Query part for entity '${t}' must be an object, but received: ${typeof e}`,s);for(const o of Object.keys(e))if(o!=="$"){if(n&&!(o in n.entities[t].links)){const c=Object.keys(n.entities[t].links);throw new A(`Link '${o}' does not exist on entity '${t}'. Available links: ${c.length>0?c.join(", "):"none"}`,`${s}.${o}`)}const a=e[o];if(typeof a=="object"&&a!==null){const c=(i=n==null?void 0:n.entities[t].links[o])==null?void 0:i.entityName;c&&dn(a,c,n,`${s}.${o}`,r+1)}}else{const a=e[o];if(typeof a!="object"||a===null)throw new A(`Query parameter '$' must be an object in entity '${t}', but received: ${typeof a}`,`${s}.$`);ys(a,t,n,`${s}.$`,r)}},ln=(e,t)=>{if(typeof e!="object"||e===null)throw new A(`Query must be an object, but received: ${typeof e}${e===null?" (null)":""}`);if(Array.isArray(e))throw new A(`Query must be an object, but received: ${typeof e}`);const n=e;for(const s of Object.keys(n)){if(Array.isArray(e[s]))throw new A(`Query keys must be strings, but found key of type: ${typeof s}`,s);if(typeof s!="string")throw new A(`Query keys must be strings, but found key of type: ${typeof s}`,s);if(s!=="$$ruleParams"){if(t&&!t.entities[s]){const r=Object.keys(t.entities);throw new A(`Entity '${s}' does not exist in schema. Available entities: ${r.length>0?r.join(", "):"none"}`,s)}dn(n[s],s,t,s,0)}}},hn=e=>typeof e!="string"?!1:rn(e)?!0:P(e);class te extends Error{constructor(t){super(t),this.name="TransactionValidationError"}}const pn=e=>e.length>0?e.join(", "):"none",ms=(e,t)=>new te(`Entity '${e}' does not exist in schema. Available entities: ${pn(t)}`),Tt={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},bs=(e,t)=>{var n;return e==null?!0:((n=Tt[t.valueType])==null?void 0:n.call(Tt,e))??!1},yn=(e,t)=>{const n=t.entities[e];if(!n)throw ms(e,Object.keys(t.entities));return n},_t=(e,t,n)=>{const s=yn(e,n);if(typeof t!="object"||t===null)throw new te(`Arguments for data operation on entity '${e}' must be an object, but received: ${typeof t}`);for(const[r,i]of Object.entries(t)){if(r==="id")continue;const o=s.attrs[r];if(o&&!bs(i,o))throw new te(`Invalid value for attribute '${r}' in entity '${e}'. Expected ${o.valueType}, but received: ${typeof i}`)}},mn=(e,t,n)=>{const s=yn(e,n);if(typeof t!="object"||t===null)throw new te(`Arguments for link operation on entity '${e}' must be an object, but received: ${typeof t}`);for(const[r,i]of Object.entries(t)){if(!s.links[r]){const a=Object.keys(s.links);throw new te(`Link '${r}' does not exist on entity '${e}'. Available links: ${pn(a)}`)}if(i!=null){if(Array.isArray(i)){for(const a of i)if(!hn(a))throw new te(`Invalid entity ID in link '${r}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`)}else if(!hn(i))throw new te(`Invalid UUID in link '${r}' for entity '${e}'. Expected a UUID, but received: ${i}`)}}},gs={create:_t,update:_t,merge:_t,link:mn,unlink:mn,delete:()=>{}},ws=(e,t)=>{if(!t)return;const[n,s,r,i]=e;if(!Array.isArray(r)&&!P(r))throw new te(`Invalid id for entity '${s}'. Expected a UUID, but received: ${r}`);if(typeof s!="string")throw new te(`Entity name must be a string, but received: ${typeof s}`);const o=gs[n];o&&i!==void 0&&o(s,i,t)},Ss=(e,t)=>{const n=Array.isArray(e)?e:[e];for(const s of n){if(!s||typeof s!="object")throw new te(`Transaction chunk must be an object, but received: ${typeof s}`);if(!Array.isArray(s.__ops))throw new te(`Transaction chunk must have __ops array, but received: ${typeof s.__ops}`);for(const r of s.__ops){if(!Array.isArray(r))throw new te(`Transaction operation must be an array, but received: ${typeof r}`);ws(r,t)}}};let Is=0;class ks{constructor(t,n,s){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}_${Is++}`,this.url=n,this.messageUrl=s||this.url,this.ES=t,this.conn=new t(n),this.sseInitTimeout=setTimeout(()=>{this.initParams||this.handleError()},1e4),this.conn.onmessage=r=>{const i=JSON.parse(r.data);if(Array.isArray(i))for(const o of i)this.handleMessage(o);else this.handleMessage(i)},this.conn.onerror=r=>{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,s,r;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:(s=this.initParams)==null?void 0:s.sessionId,sse_token:(r=this.initParams)==null?void 0:r.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 bn;(function(e){e.InitialSyncBatch="InitialSyncBatch",e.InitialSyncComplete="InitialSyncComplete",e.LoadFromStorage="LoadFromStorage",e.SyncTransaction="SyncTransaction",e.Error="Error"})(bn||(bn={}));function $s({WStream:e,opts:t,startStream:n,appendStream:s,registerStream:r}){const i=t.clientId;let o=null,a=null,c=null;const u=Pe();let h=!1,l=!1;const y=[],m=[],g=[];let w=!1,p=0,$=0;const v=[],V=new TextEncoder;function Re(){l=!0;for(const b of y)b(a??void 0)}function zt(b){return y.push(b),l&&b(a??void 0),()=>{const I=y.indexOf(b);I!==-1&&y.splice(I,1)}}function jn(b){return g.push(b),()=>{const I=g.indexOf(b);I!==-1&&g.splice(I,1)}}t.waitUntil&&t.waitUntil(new Promise(b=>{g.push(b)}));function j(){for(const b of g)try{b()}catch{}}function T(b){return m.push(b),o&&b(o),()=>{const I=m.indexOf(b);I!==-1&&m.splice(I,1)}}function ie(b){o=b;for(const I of m)I(o)}function R(){w=!0}function z(b){let I=p,W=0,Y=0;for(const{byteLen:oe}of v){const he=I+oe;if(he>b)break;I=he,W++,Y+=oe}W>0&&(p+=Y,$-=Y,v.splice(0,W))}function N(b,I){a=I,Re(),b.error(I),j()}async function ne(){const b=await n({clientId:i,reconnectToken:u,ruleParams:t.ruleParams});switch(b.type){case"ok":{const{streamId:I,offset:W}=b;o=I,z(W),v.length&&s({streamId:I,chunks:v.map(Y=>Y.chunk),offset:p}),w=!1;break}case"disconnect":{R();break}case"error":{c&&N(c,b.error);break}}}function J(){R(),ne()}function bt({offset:b,done:I}){z(b),I&&(h=!0,j())}function Un(b){return h?(N(b,new _("Stream has been closed.")),null):o||(N(b,new _("Stream has not been initialized.")),null)}async function We(b){c=b;let I=!0,W=0;for(;I;){let Y=Date.now()+Math.min(15e3,500*(W-1));I=!1;const oe=await n({clientId:t.clientId,reconnectToken:u,ruleParams:t.ruleParams});switch(oe.type){case"ok":{const{streamId:he,offset:Wt}=oe;if(Wt!==0){const Ae=new _("Write stream is corrupted");N(b,Ae);return}ie(he),r(he,{onDisconnect:R,onFlush:bt,onConnectionReconnect:ne,onAppendFailed:J}),w=!1;return}case"disconnect":{I=!0,R(),W++,await new Promise(he=>{setTimeout(he,Math.max(0,Y-Date.now()))});break}case"error":{N(b,oe.error);return}}}}class ge extends e{constructor(I,W){super(I,W)}async streamId(){return o||new Promise((I,W)=>{const Y=[],oe=()=>{for(const Ae of Y)Ae()},he=Ae=>{I(Ae),oe()},Wt=Ae=>{W(Ae||new _("Stream is closed.")),oe()};Y.push(T(he)),Y.push(zt(Wt))})}}return{stream:new ge({async start(b){try{await We(b)}catch(I){N(b,I)}},write(b,I){const W=Un(I);if(W){const Y=V.encode(b).length;v.push({chunk:b,byteLen:Y});const oe=p+$;$+=Y,w||s({streamId:W,chunks:[b],offset:oe})}},close(){o?s({streamId:o,chunks:[],offset:p+$,isDone:!0}):j(),Re()},abort(b){o?s({streamId:o,chunks:[],offset:p+$,isDone:!0,abortReason:b}):j(),Re()}}),addCompleteCb:jn,closed(){return l}}}class vs{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(s=>{this.resolvers.push(s)});if(n||!t)return;yield t}}}}function Os({RStream:e,opts:t,startStream:n,cancelStream:s}){let r=t.byteOffset||0,i=!1;const o=new TextDecoder("utf-8"),a=new TextEncoder;let c,u=!1;const h=[],l=[];let y=null,m=null;function g(j){u=!0;for(const T of h)T(j)}function w(j){return h.push(j),()=>{const T=h.indexOf(j);T!==-1&&h.splice(T,1)}}function p(j){return l.push(j),y&&j(y),()=>{const T=l.indexOf(j);T!==-1&&l.splice(T,1)}}function $(j,T){m=T,j.error(T),g(T)}let v=0;async function V(j,T){c=Pe();const ie={...j||{},eventId:c};for await(const R of n(ie)){if(i)return;if(R.type==="reconnect")return{retry:!0};if(R.type==="error"){$(T,R.error);return}if(R.offset>r){$(T,new _("Stream is corrupted.")),i=!0;return}y=R.streamId;for(const N of l)N(y);let z=r-R.offset;if(R.files&&R.files.length){const N=new AbortController;let ne=fetch(R.files[0].url,{signal:N.signal});for(let J=0;J<R.files.length;J++){const bt=R.files[J+1],We=await ne;if(bt&&(ne=fetch(bt.url,{signal:N.signal})),!We.ok){if(v++,v>10){$(T,new _("Unable to process stream."));return}return{retry:!0}}if(We.body){const ge=We.body.getReader();try{for(;;){const{done:we,value:b}=await ge.read();if(we)break;if(i){N.abort();return}let I=b;if(z>0&&(I=b.subarray(z),z-=b.length-I.length),!I.length)continue;r+=I.length;const W=o.decode(I);T.enqueue(W)}}finally{ge.releaseLock()}}else{const ge=await We.arrayBuffer();let we=ge;if(i){N.abort();return}if(z>0&&(we=new Uint8Array(ge).subarray(z),z-=ge.byteLength-we.length),!we.byteLength)continue;r+=we.byteLength;const b=o.decode(we);T.enqueue(b)}}}if(v=0,R.content){let N=R.content,ne=a.encode(R.content);if(z>0){const J=ne.subarray(z);if(z-=ne.length-J.length,!J.length)continue;ne=J,N=o.decode(J)}r+=ne.length,T.enqueue(N)}}}async function Re(j){let T=!0,ie=0;for(;T;){T=!1;let R=Date.now()+Math.min(15e3,500*(ie-1));const z=await V({...t,offset:r},j);z!=null&&z.retry&&(T=!0,ie++,R<Date.now()-3e5&&(ie=0),await new Promise(N=>{setTimeout(N,Math.max(0,R-Date.now()))}))}!i&&!u&&(j.close(),g())}class zt extends e{constructor(T,ie){super(T,ie)}async streamId(){if(y)return y;if(m)throw m;return new Promise((T,ie)=>{const R=[],z=()=>{for(const J of R)J()},N=J=>{T(J),z()},ne=J=>{ie(J||new _("Stream is closed.")),z()};R.push(p(N)),R.push(w(ne))})}}return{stream:new zt({start(j){Re(j)},cancel(j){i=!0,c&&s({eventId:c}),g()}}),addCloseCb:w,closed(){return u}}}class Es{constructor({WStream:t,RStream:n,trySend:s,log:r}){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=s,this.log=r}createWriteStream(t){const{stream:n,addCompleteCb:s}=$s({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),s(()=>{this.activeStreams.delete(n)}),n}createReadStream(t){const{stream:n,addCloseCb:s}=Os({RStream:this.RStream,opts:t,startStream:this.startReadStream.bind(this),cancelStream:this.cancelReadStream.bind(this)});return this.activeStreams.add(n),s(()=>{this.activeStreams.delete(n)}),n}startWriteStream(t){const n=Pe();let s=null;const r=new Promise(o=>{s=o});this.startWriteStreamCbs[n]=s;const i={op:"start-stream","client-id":t.clientId,"reconnect-token":t.reconnectToken};return t.ruleParams&&(i["rule-params"]=t.ruleParams),this.trySend(n,i),r}registerWriteStream(t,n){this.writeStreams[t]=n}appendStream({streamId:t,chunks:n,isDone:s,offset:r,abortReason:i}){const o={op:"append-stream","stream-id":t,chunks:n,offset:r,done:!!s};i&&(o["abort-reason"]=i),this.trySend(Pe(),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"],s=this.writeStreams[n];if(!s){this.log.info("No stream cbs for stream-flushed",t);return}s.onFlush({offset:t.offset,done:t.done}),t.done&&delete this.writeStreams[n]}startReadStream({eventId:t,clientId:n,streamId:s,offset:r,ruleParams:i}){const o={op:"subscribe-stream"};if(!s&&!n)throw new Error("Must provide one of streamId or clientId to subscribe to the stream.");s&&(o["stream-id"]=s),n&&(o["client-id"]=n),r&&(o.offset=r),i&&(o["rule-params"]=i);const a=new vs;return this.readStreamIterators[t]=a,this.trySend(t,o),a}cancelReadStream({eventId:t}){const n={op:"unsubscribe-stream","subscribe-event-id":t};this.trySend(Pe(),n),delete this.readStreamIterators[t]}onStreamAppend(t){const n=t["client-event-id"],s=this.readStreamIterators[n];if(!s){this.log.info("No iterator for read stream",t);return}if(t.error){t.retry?s.push({type:"reconnect"}):s.push({type:"error",error:new _(t.error)}),s.close(),delete this.readStreamIterators[n];return}s.push({type:"append",offset:t.offset,files:t.files,content:t.content,streamId:t["stream-id"]}),t.done&&(s.close(),delete this.readStreamIterators[n])}onConnectionStatusChange(t){for(const n of Object.values(this.startWriteStreamCbs))n({type:"disconnect"});if(this.startWriteStreamCbs={},t!==Cs.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 s=n["stream-id"],r=this.writeStreams[s];r==null||r.onAppendFailed();break}case"start-stream":{const s=t["client-event-id"],r=this.startWriteStreamCbs[s];r&&(r({type:"error",error:new _(t.message||"Unknown error",t.hint)}),delete this.startWriteStreamCbs[s]);break}case"subscribe-stream":{const s=t["client-event-id"],r=this.readStreamIterators[s];r&&(r.push({type:"error",error:new _(t.message||"Unknown error",t.hint)}),r.close(),delete this.readStreamIterators[s]);break}}}hasActiveStreams(){return this.activeStreams.size>0}}const Cs={AUTHENTICATED:"authenticated"};class xs extends _{constructor(t){super(t),this.name="MissingApiURIError"}get[Symbol.toStringTag](){return"MissingApiURIError"}}function Ts({target:e,option:t="apiURI",envVar:n}){return`No SidekickDB server URL configured. ${n?`Pass \`${t}\` to ${e} or set the ${n} environment variable`:`Pass \`${t}\` to ${e}`}, for example ${t}: 'https://sidekick.example.com'. SidekickDB has no default server.`}function Rt(e,t){if(typeof e=="string"&&e.trim()!=="")return e;throw new xs(Ts(t))}function _s(){return globalThis.__instantDbSchemaHashStore=globalThis.__instantDbSchemaHashStore??new WeakMap,globalThis.__instantDbSchemaHashStore}function Rs(){return globalThis.__instantDbStore=globalThis.__instantDbStore??{},globalThis.__instantDbStore}Rs(),_s();class gn extends Event{constructor(n,s){super(n);d(this,"code");d(this,"message");this.code=(s==null?void 0:s.code)??void 0,this.message=(s==null?void 0:s.message)??void 0}[Symbol.for("nodejs.util.inspect.custom")](n,s,r){return r(wn(this),s)}[Symbol.for("Deno.customInspect")](n,s){return n(wn(this),s)}}function As(e){const t=globalThis.DOMException;return typeof t=="function"?new t(e,"SyntaxError"):new SyntaxError(e)}function At(e){return e instanceof Error?"errors"in e&&Array.isArray(e.errors)?e.errors.map(At).join(", "):"cause"in e&&e.cause instanceof Error?`${e}: ${At(e.cause)}`:e.message:`${e}`}function wn(e){return{type:e.type,message:e.message,code:e.code,defaultPrevented:e.defaultPrevented,cancelable:e.cancelable,timeStamp:e.timeStamp}}class Sn 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 Pt(e){}function Ps(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=Pt,onError:n=Pt,onRetry:s=Pt,onComment:r}=e;let i="",o=!0,a,c="",u="";function h(w){const p=o?w.replace(/^\xEF\xBB\xBF/,""):w,[$,v]=js(`${i}${p}`);for(const V of $)l(V);i=v,o=!1}function l(w){if(w===""){m();return}if(w.startsWith(":")){r&&r(w.slice(w.startsWith(": ")?2:1));return}const p=w.indexOf(":");if(p!==-1){const $=w.slice(0,p),v=w[p+1]===" "?2:1,V=w.slice(p+v);y($,V,w);return}y(w,"",w)}function y(w,p,$){switch(w){case"event":u=p;break;case"data":c=`${c}${p}
|
|
1
|
+
(function(E,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(E=typeof globalThis<"u"?globalThis:E||self,x(E.instant={}))})(this,function(E){"use strict";var Ir=Object.defineProperty;var Mn=E=>{throw TypeError(E)};var kr=(E,x,P)=>x in E?Ir(E,x,{enumerable:!0,configurable:!0,writable:!0,value:P}):E[x]=P;var d=(E,x,P)=>kr(E,typeof x!="symbol"?x+"":x,P),Kt=(E,x,P)=>x.has(E)||Mn("Cannot "+P);var f=(E,x,P)=>(Kt(E,x,"read from private field"),P?P.call(E):x.get(E)),k=(E,x,P)=>x.has(E)?Mn("Cannot add the same private member more than once"):x instanceof WeakSet?x.add(E):x.set(E,P),S=(E,x,P,D)=>(Kt(E,x,"write to private field"),D?D.call(E,P):x.set(E,P),P),O=(E,x,P)=>(Kt(E,x,"access private method"),P);var q,be,ve,qe,Be,Qe,Me,Oe,De,le,Ee,Ce,xe,Ne,B,Vt,ct,ut,Dn,ft,dt,Ze,Jt,lt,Q,Ge,Le,Fe,Xe,ee,ae,Ye,Te,ze,K,_e,G,X,F,Ln,gt,Fn,zn,Wn,ht,pt,yt,Ht,Kn,mt;const x=/^(?:[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 P(e){return typeof e=="string"&&x.test(e)}const D=[];for(let e=0;e<256;++e)D.push((e+256).toString(16).slice(1));function Vn(e,t=0){return(D[e[t+0]]+D[e[t+1]]+D[e[t+2]]+D[e[t+3]]+"-"+D[e[t+4]]+D[e[t+5]]+"-"+D[e[t+6]]+D[e[t+7]]+"-"+D[e[t+8]]+D[e[t+9]]+"-"+D[e[t+10]]+D[e[t+11]]+D[e[t+12]]+D[e[t+13]]+D[e[t+14]]+D[e[t+15]]).toLowerCase()}let wt;const Jn=new Uint8Array(16);function Hn(){if(!wt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");wt=crypto.getRandomValues.bind(crypto)}return wt(Jn)}const qt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qn(e,t,n){var r;if(qt.randomUUID&&!e)return qt.randomUUID();e=e||{};const s=e.random??((r=e.rng)==null?void 0:r.call(e))??Hn();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,Vn(s)}const L={Remove:"remove",Replace:"replace",Add:"add"},Bt=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),et=Symbol.iterator,se={mutable:"mutable",immutable:"immutable"},St={};function Ke(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Qt(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const s=Reflect.getOwnPropertyDescriptor(n,t);if(s)return s;n=Reflect.getPrototypeOf(n)}}}function Gt(e){return Object.getPrototypeOf(e)===Set.prototype}function Xt(e){return Object.getPrototypeOf(e)===Map.prototype}function Z(e){var t;return(t=e.copy)!==null&&t!==void 0?t:e.original}function It(e){return!!C(e)}function C(e){return typeof e!="object"?null:e==null?void 0:e[Bt]}function kt(e){var t;const n=C(e);return n?(t=n.copy)!==null&&t!==void 0?t:n.original:e}function Se(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,se))===se.immutable||typeof n=="function")}function Yt(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,s=C(pe(n,e.key));if(s!==null&&(s==null?void 0:s.original)!==e.original)return null;const r=e.parent.type===3,i=r?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(r&&n.size>i||Ke(n,i)))return null;t.push(i)}if(e.parent)return Yt(e.parent,t);t.reverse();try{Bn(e.copy,t)}catch{return null}return t}function Ve(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function pe(e,t){return Ve(e)===2?e.get(t):e[t]}function $t(e,t,n){Ve(e)===2?e.set(t,n):e[t]=n}function vt(e,t){const n=C(e);return(n?Z(n):e)[t]}function Ie(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function ke(e,t){return t?e:[""].concat(e).map(n=>{const s=`${n}`;return s.indexOf("/")===-1&&s.indexOf("~")===-1?s:s.replace(/~/g,"~0").replace(/\//g,"~1")}).join("/")}function Bn(e,t){for(let n=0;n<t.length-1;n+=1){const s=t[n];if(e=pe(Ve(e)===3?Array.from(e):e,s),typeof e!="object")throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}return e}function Qn(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach(n=>{let s=Reflect.getOwnPropertyDescriptor(e,n);if(s.enumerable&&s.configurable&&s.writable){t[n]=e[n];return}s.writable||(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(s={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[n]}),Reflect.defineProperty(t,n,s)}),t}const Gn=Object.prototype.propertyIsEnumerable;function Xn(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!Gt(e)){const s=Object.getPrototypeOf(e).constructor;return new s(e.values())}return Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values())}else if(e instanceof Map){if(!Xt(e)){const s=Object.getPrototypeOf(e).constructor;return new s(e)}return new Map(e)}else if(t!=null&&t.mark&&(n=t.mark(e,se),n!==void 0)&&n!==se.mutable){if(n===se.immutable)return Qn(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 s={};return Object.keys(e).forEach(r=>{s[r]=e[r]}),Object.getOwnPropertySymbols(e).forEach(r=>{Gn.call(e,r)&&(s[r]=e[r])}),s}else throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function H(e){e.copy||(e.copy=Xn(e.original,e.options))}function Je(e){if(!Se(e))return kt(e);if(Array.isArray(e))return e.map(Je);if(e instanceof Map){const n=Array.from(e.entries()).map(([s,r])=>[s,Je(r)]);if(!Xt(e)){const s=Object.getPrototypeOf(e).constructor;return new s(n)}return new Map(n)}if(e instanceof Set){const n=Array.from(e).map(Je);if(!Gt(e)){const s=Object.getPrototypeOf(e).constructor;return new s(n)}return new Set(n)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=Je(e[n]);return t}function tt(e){return It(e)?Je(e):e}function ce(e){var t;e.assignedMap=(t=e.assignedMap)!==null&&t!==void 0?t:new Map,e.operated||(e.operated=!0,e.parent&&ce(e.parent))}function Yn(e,t){const n=Ve(e);if(n===0)Reflect.ownKeys(e).forEach(s=>{t(s,e[s],e)});else if(n===1){let s=0;for(const r of e)t(s,r,e),s+=1}else e.forEach((s,r)=>t(r,s,e))}function Zt(e,t,n){if(It(e)||!Se(e,n)||t.has(e)||Object.isFrozen(e))return;const s=e instanceof Set,r=s?new Map:void 0;if(t.add(e),Yn(e,(i,o)=>{var a;if(It(o)){const c=C(o);H(c);const u=!((a=c.assignedMap)===null||a===void 0)&&a.size||c.operated?c.copy:c.original;$t(s?r:e,i,u)}else Zt(o,t,n)}),r){const i=e,o=Array.from(i);i.clear(),o.forEach(a=>{i.add(r.has(a)?r.get(a):a)})}}function Zn(e,t){const n=e.type===3?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&Zt(pe(n,t),e.finalities.handledSet,e.options)}function Ot(e){e.type===3&&e.copy&&(e.copy.clear(),e.setMap.forEach(t=>{e.copy.add(kt(t))}))}function Et(e,t,n,s){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&s){const i=Yt(e);i&&t(e,i,n,s)}e.finalized=!0}}function Ct(e,t,n,s){const r=C(n);r&&(r.callbacks||(r.callbacks=[]),r.callbacks.push((i,o)=>{var a;const c=e.type===3?e.setMap:e.copy;if(Ie(pe(c,t),n)){let u=r.original;r.copy&&(u=r.copy),Ot(e),Et(e,s,i,o),e.options.enableAutoFreeze&&(e.options.updatedValues=(a=e.options.updatedValues)!==null&&a!==void 0?a:new WeakMap,e.options.updatedValues.set(u,r.original)),$t(c,t,u)}}),e.options.enableAutoFreeze&&r.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),Se(n,e.options)&&e.finalities.draft.push(()=>{const i=e.type===3?e.setMap:e.copy;Ie(pe(i,t),n)&&Zn(e,t)})}function es(e,t,n,s,r){let{original:i,assignedMap:o,options:a}=e,c=e.copy;c.length<i.length&&([i,c]=[c,i],[n,s]=[s,n]);for(let u=0;u<i.length;u+=1)if(o.get(u.toString())&&c[u]!==i[u]){const h=t.concat([u]),l=ke(h,r);n.push({op:L.Replace,path:l,value:tt(c[u])}),s.push({op:L.Replace,path:l,value:tt(i[u])})}for(let u=i.length;u<c.length;u+=1){const h=t.concat([u]),l=ke(h,r);n.push({op:L.Add,path:l,value:tt(c[u])})}if(i.length<c.length){const{arrayLengthAssignment:u=!0}=a.enablePatches;if(u){const h=t.concat(["length"]),l=ke(h,r);s.push({op:L.Replace,path:l,value:i.length})}else for(let h=c.length;i.length<h;h-=1){const l=t.concat([h-1]),y=ke(l,r);s.push({op:L.Remove,path:y})}}}function ts({original:e,copy:t,assignedMap:n},s,r,i,o){n.forEach((a,c)=>{const u=pe(e,c),h=tt(pe(t,c)),l=a?Ke(e,c)?L.Replace:L.Add:L.Remove;if(Ie(u,h)&&l===L.Replace)return;const y=s.concat(c),m=ke(y,o);r.push(l===L.Remove?{op:l,path:m}:{op:l,path:m,value:h}),i.push(l===L.Add?{op:L.Remove,path:m}:l===L.Remove?{op:L.Add,path:m,value:u}:{op:L.Replace,path:m,value:u})})}function ns({original:e,copy:t},n,s,r,i){let o=0;e.forEach(a=>{if(!t.has(a)){const c=n.concat([o]),u=ke(c,i);s.push({op:L.Remove,path:u,value:a}),r.unshift({op:L.Add,path:u,value:a})}o+=1}),o=0,t.forEach(a=>{if(!e.has(a)){const c=n.concat([o]),u=ke(c,i);s.push({op:L.Add,path:u,value:a}),r.unshift({op:L.Remove,path:u,value:a})}o+=1})}function He(e,t,n,s){const{pathAsArray:r=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return ts(e,t,n,s,r);case 1:return es(e,t,n,s,r);case 3:return ns(e,t,n,s,r)}}const nt=(e,t,n=!1)=>{if(typeof e=="object"&&e!==null&&(!Se(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},xt={get size(){return Z(C(this)).size},has(e){return Z(C(this)).has(e)},set(e,t){const n=C(this),s=Z(n);return(!s.has(e)||!Ie(s.get(e),t))&&(H(n),ce(n),n.assignedMap.set(e,!0),n.copy.set(e,t),Ct(n,e,t,He)),this},delete(e){if(!this.has(e))return!1;const t=C(this);return H(t),ce(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=C(this);if(this.size){H(e),ce(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){const n=C(this);Z(n).forEach((s,r)=>{e.call(t,this.get(r),r,this)})},get(e){var t,n;const s=C(this),r=Z(s).get(e),i=((n=(t=s.options).mark)===null||n===void 0?void 0:n.call(t,r,se))===se.mutable;if(s.options.strict&&nt(r,s.options,i),i||s.finalized||!Se(r,s.options)||r!==s.original.get(e))return r;const o=St.createDraft({original:r,parentDraft:s,key:e,finalities:s.finalities,options:s.options});return H(s),s.copy.set(e,o),o},keys(){return Z(C(this)).keys()},values(){const e=this.keys();return{[et]:()=>this.values(),next:()=>{const t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[et]:()=>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]}}}},[et](){return this.entries()}},ss=Reflect.ownKeys(xt),en=(e,t,{isValuesIterator:n})=>()=>{var s,r;const i=t.next();if(i.done)return i;const o=i.value;let a=e.setMap.get(o);const c=C(a),u=((r=(s=e.options).mark)===null||r===void 0?void 0:r.call(s,a,se))===se.mutable;if(e.options.strict&&nt(o,e.options,u),!u&&!c&&Se(o,e.options)&&!e.finalized&&e.original.has(o)){const h=St.createDraft({original:o,parentDraft:e,key:o,finalities:e.finalities,options:e.options});e.setMap.set(o,h),a=h}else c&&(a=c.proxy);return{done:!1,value:n?a:[a,a]}},st={get size(){return C(this).setMap.size},has(e){const t=C(this);if(t.setMap.has(e))return!0;H(t);const n=C(e);return!!(n&&t.setMap.has(n.original))},add(e){const t=C(this);return this.has(e)||(H(t),ce(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),Ct(t,e,e,He)),this},delete(e){if(!this.has(e))return!1;const t=C(this);H(t),ce(t);const n=C(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=C(this);H(e),ce(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=C(this);H(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:en(e,t,{isValuesIterator:!0})}},entries(){const e=C(this);H(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:en(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[et](){return this.values()},forEach(e,t){const n=this.values();let s=n.next();for(;!s.done;)e.call(t,s.value,s.value,this),s=n.next()}};Set.prototype.difference&&Object.assign(st,{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 rs=Reflect.ownKeys(st),tn=new WeakSet,nn={get(e,t,n){var s,r;const i=(s=e.copy)===null||s===void 0?void 0:s[t];if(i&&tn.has(i))return i;if(t===Bt)return e;let o;if(e.options.mark){const u=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(u,se),o===se.mutable)return e.options.strict&&nt(u,e.options,!0),u}const a=Z(e);if(a instanceof Map&&ss.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(xt,"size").get.call(e.proxy);const u=xt[t];if(u)return u.bind(e.proxy)}if(a instanceof Set&&rs.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(st,"size").get.call(e.proxy);const u=st[t];if(u)return u.bind(e.proxy)}if(!Ke(a,t)){const u=Qt(a,t);return u?"value"in u?u.value:(r=u.get)===null||r===void 0?void 0:r.call(e.proxy):void 0}const c=a[t];if(e.options.strict&&nt(c,e.options),e.finalized||!Se(c,e.options))return c;if(c===vt(e.original,t)){if(H(e),e.copy[t]=sn({original:e.original[t],parentDraft:e,key:e.type===1?Number(t):t,finalities:e.finalities,options:e.options}),typeof o=="function"){const u=C(e.copy[t]);return H(u),ce(u),u.copy}return e.copy[t]}return c},set(e,t,n){var s;if(e.type===3||e.type===2)throw new Error("Map/Set draft does not support any property assignment.");let r;if(e.type===1&&t!=="length"&&!(Number.isInteger(r=Number(t))&&r>=0&&(t===0||r===0||String(r)===String(t))))throw new Error("Only supports setting array indices and the 'length' property.");const i=Qt(Z(e),t);if(i!=null&&i.set)return i.set.call(e.proxy,n),!0;const o=vt(Z(e),t),a=C(o);return a&&Ie(a.original,n)?(e.copy[t]=n,e.assignedMap=(s=e.assignedMap)!==null&&s!==void 0?s:new Map,e.assignedMap.set(t,!1),!0):(Ie(n,o)&&(n!==void 0||Ke(e.original,t))||(H(e),ce(e),Ke(e.original,t)&&Ie(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,Ct(e,t,n,He)),!0)},has(e,t){return t in Z(e)},ownKeys(e){return Reflect.ownKeys(Z(e))},getOwnPropertyDescriptor(e,t){const n=Z(e),s=Reflect.getOwnPropertyDescriptor(n,t);return s&&{writable:!0,configurable:e.type!==1||t!=="length",enumerable:s.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?nn.set.call(this,e,t,void 0,e.proxy):(vt(e.original,t)!==void 0||t in e.original?(H(e),ce(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 sn(e){const{original:t,parentDraft:n,key:s,finalities:r,options:i}=e,o=Ve(t),a={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:r,options:i,setMap:o===3?new Map(t.entries()):void 0};(s||"key"in e)&&(a.key=s);const{proxy:c,revoke:u}=Proxy.revocable(o===1?Object.assign([],a):a,nn);if(r.revoke.push(u),tn.add(c),a.proxy=c,n){const h=n;h.finalities.draft.push((l,y)=>{var m,g;const w=C(c);let p=h.type===3?h.setMap:h.copy;const $=pe(p,s),v=C($);if(v){let V=v.original;v.operated&&(V=kt($)),Ot(v),Et(v,He,l,y),h.options.enableAutoFreeze&&(h.options.updatedValues=(m=h.options.updatedValues)!==null&&m!==void 0?m:new WeakMap,h.options.updatedValues.set(V,v.original)),$t(p,s,V)}(g=w.callbacks)===null||g===void 0||g.forEach(V=>{V(l,y)})})}else{const h=C(c);h.finalities.draft.push((l,y)=>{Ot(h),Et(h,He,l,y)})}return c}St.createDraft=sn,Object.prototype.constructor.toString();function Pe(){return qn()}function is(e,t){return e.localeCompare(t)}function os(){let e=is;if(typeof Intl=="object"&&Intl.hasOwnProperty("Collator"))try{e=Intl.Collator("en-US").compare}catch{}return e}os();function as(){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 cs=as();function rt(e,t,n){const s={__etype:e,__ops:n};return new Proxy(s,{get:(r,i)=>{if(i==="__ops")return n;if(i==="__etype")return e;if(cs.has(i))return(o,a)=>rt(e,t,[...n,a?[i,e,t,o,a]:[i,e,t,o]])}})}function us(e,t){return`lookup__${e}__${JSON.stringify(t)}`}function rn(e){return e.startsWith("lookup__")}function on(e){const[t,n,...s]=e.split("__");return[n,JSON.parse(s.join("__"))]}function fs(e){return new Proxy({__etype:e},{get(t,n){if(n==="lookup")return(r,i)=>rt(e,on(us(r,i)),[]);if(n==="__etype")return e;const s=n;return rn(s)?rt(e,on(s),[]):rt(e,s,[])}})}function an(){return new Proxy({},{get(e,t){return fs(t)}})}an();function ds(e){return e.__ops}class _ extends Error{constructor(n,s,r){super(n);d(this,"hint");d(this,"traceId");this.hint=s,r&&(this.traceId=r);const i=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,i),Error.captureStackTrace&&Error.captureStackTrace(this,_),this.name="InstantError"}get[Symbol.toStringTag](){return"InstantError"}}class ue extends _{constructor(n){var i,o;const s=((i=n.body)==null?void 0:i.message)||`API Error (${n.status})`;super(s,n.body.hint,((o=n.body)==null?void 0:o.traceId)||n.body["trace-id"]);d(this,"body");d(this,"status");const r=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,r),Error.captureStackTrace&&Error.captureStackTrace(this,ue),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="v2.0.1";class fe{constructor(t,n,s,r={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=s,this.config=r}clientRequired(){return new fe(this.valueType,!1,this.isIndexed,this.config)}optional(){return new fe(this.valueType,!1,this.isIndexed,this.config)}unique(){return new fe(this.valueType,this.required,this.isIndexed,{...this.config,unique:!0})}indexed(){return new fe(this.valueType,this.required,!0,{...this.config,indexed:!0})}}class A extends Error{constructor(t,n){const s=n?`At path '${n}': ${t}`:t;super(s),this.name="QueryValidationError"}}const cn=["where","order","limit","last","first","offset","after","afterInclusive","before","beforeInclusive","fields","aggregate"],ls=e=>e.valueType||"unknown",un=(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}},hs=(e,t,n,s,r,i,o)=>{const a=i.valueType==="json",c=(u,h,l)=>{if(!un(l,h,a))throw new A(`Invalid value for operator '${u}' on attribute '${s}' in entity '${r}'. Expected ${h}, but received: ${typeof l}`,o)};switch(e){case"in":case"$in":if(!Array.isArray(t))throw new A(`Operator '${e}' for attribute '${s}' in entity '${r}' must be an array, but received: ${typeof t}`,o);for(const u of t)c(e,n,u);break;case"$not":case"$ne":case"$gt":case"$lt":case"$gte":case"$lte":c(e,n,t);break;case"$like":case"$ilike":if(c(e,"string",t),e==="$ilike"&&!i.isIndexed)throw new A(`Operator '${e}' can only be used with indexed attributes, but '${s}' in entity '${r}' is not indexed`,o);break;case"$isNull":c(e,"boolean",t);break;default:throw new A(`Unknown operator '${e}' for attribute '${s}' in entity '${r}'`,o)}},je=(e,t,n,s,r)=>{const i=ls(n),o=n.valueType==="json";if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(o)return;const c=e;for(const[u,h]of Object.entries(c))hs(u,h,i,t,s,n,`${r}.${u}`)}else if(!un(e,i,o))throw new A(`Invalid value for attribute '${t}' in entity '${s}'. Expected ${i}, but received: ${typeof e}`,r)},ps=(e,t,n,s,r)=>{const i=e.split(".");if(i.length<2)throw new A(`Invalid dot notation path '${e}'. Must contain at least one dot.`,r);let o=n;for(let h=0;h<i.length-1;h++){const l=i[h],y=s.entities[o];if(!y)throw new A(`Entity '${o}' does not exist in schema while traversing dot notation path '${e}'.`,r);const m=y.links[l];if(!m){const g=Object.keys(y.links);throw new A(`Link '${l}' does not exist on entity '${o}' in dot notation path '${e}'. Available links: ${g.length>0?g.join(", "):"none"}`,r)}o=m.entityName}const a=i[i.length-1],c=s.entities[o];if(!c)throw new A(`Target entity '${o}' does not exist in schema for dot notation path '${e}'.`,r);if(a==="id"){if(typeof t=="string"&&!P(t))throw new A(`Invalid value for id field in entity '${o}'. Expected a UUID, but received: ${t}`,r);je(t,e,new fe("string",!1,!0),n,r);return}const u=c.attrs[a];if(Object.keys(c.links).includes(a)){if(typeof t=="string"&&!P(t))throw new A(`Invalid value for link '${a}' in entity '${o}'. Expected a UUID, but received: ${t}`,r);je(t,e,new fe("string",!1,!0),n,r);return}if(!u){const h=Object.keys(c.attrs);throw new A(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${h.length>0?h.join(", ")+", id":"id"}`,r)}je(t,e,u,n,r)},fn=(e,t,n,s)=>{for(const[r,i]of Object.entries(e)){if(r==="or"||r==="and"){if(Array.isArray(i))for(const u of i)typeof u=="object"&&u!==null&&fn(u,t,n,`${s}.${r}[${u}]`);continue}if(r==="id"){je(i,"id",new fe("string",!1,!0),t,`${s}.id`);continue}if(r.includes(".")){ps(r,i,t,n,`${s}.${r}`);continue}const o=n.entities[t];if(!o)continue;const a=o.attrs[r],c=o.links[r];if(!a&&!c){const u=Object.keys(o.attrs),h=Object.keys(o.links);throw new A(`Attribute or link '${r}' does not exist on entity '${t}'. Available attributes: ${u.length>0?u.join(", "):"none"}. Available links: ${h.length>0?h.join(", "):"none"}`,`${s}.${r}`)}if(a)je(i,r,a,t,`${s}.${r}`);else if(c){if(typeof i=="string"&&!P(i))throw new A(`Invalid value for link '${r}' in entity '${t}'. Expected a UUID, but received: ${i}`,`${s}.${r}`);const u=new fe("string",!1,!0);je(i,r,u,t,`${s}.${r}`)}}},ys=(e,t,n,s,r=0)=>{for(const o of Object.keys(e))if(!cn.includes(o))throw new A(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${cn.join(", ")}. Found: ${o}`,s);const i=["offset","before","beforeInclusive","after","afterInclusive","first","last"];for(const o of i)if(e[o]!==void 0&&r>0)throw new A(`'${o}' can only be used on top-level namespaces. It cannot be used in nested queries.`,s);if(e.where&&n){if(typeof e.where!="object"||e.where===null)throw new A(`'where' clause must be an object in entity '${t}', but received: ${typeof e.where}`,s?`${s}.where`:void 0);fn(e.where,t,n,s?`${s}.where`:"where")}},dn=(e,t,n,s,r=0)=>{var i;if(!e||typeof e!="object")throw new A(`Query part for entity '${t}' must be an object, but received: ${typeof e}`,s);for(const o of Object.keys(e))if(o!=="$"){if(n&&!(o in n.entities[t].links)){const c=Object.keys(n.entities[t].links);throw new A(`Link '${o}' does not exist on entity '${t}'. Available links: ${c.length>0?c.join(", "):"none"}`,`${s}.${o}`)}const a=e[o];if(typeof a=="object"&&a!==null){const c=(i=n==null?void 0:n.entities[t].links[o])==null?void 0:i.entityName;c&&dn(a,c,n,`${s}.${o}`,r+1)}}else{const a=e[o];if(typeof a!="object"||a===null)throw new A(`Query parameter '$' must be an object in entity '${t}', but received: ${typeof a}`,`${s}.$`);ys(a,t,n,`${s}.$`,r)}},ln=(e,t)=>{if(typeof e!="object"||e===null)throw new A(`Query must be an object, but received: ${typeof e}${e===null?" (null)":""}`);if(Array.isArray(e))throw new A(`Query must be an object, but received: ${typeof e}`);const n=e;for(const s of Object.keys(n)){if(Array.isArray(e[s]))throw new A(`Query keys must be strings, but found key of type: ${typeof s}`,s);if(typeof s!="string")throw new A(`Query keys must be strings, but found key of type: ${typeof s}`,s);if(s!=="$$ruleParams"){if(t&&!t.entities[s]){const r=Object.keys(t.entities);throw new A(`Entity '${s}' does not exist in schema. Available entities: ${r.length>0?r.join(", "):"none"}`,s)}dn(n[s],s,t,s,0)}}},hn=e=>typeof e!="string"?!1:rn(e)?!0:P(e);class te extends Error{constructor(t){super(t),this.name="TransactionValidationError"}}const pn=e=>e.length>0?e.join(", "):"none",ms=(e,t)=>new te(`Entity '${e}' does not exist in schema. Available entities: ${pn(t)}`),Tt={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},bs=(e,t)=>{var n;return e==null?!0:((n=Tt[t.valueType])==null?void 0:n.call(Tt,e))??!1},yn=(e,t)=>{const n=t.entities[e];if(!n)throw ms(e,Object.keys(t.entities));return n},_t=(e,t,n)=>{const s=yn(e,n);if(typeof t!="object"||t===null)throw new te(`Arguments for data operation on entity '${e}' must be an object, but received: ${typeof t}`);for(const[r,i]of Object.entries(t)){if(r==="id")continue;const o=s.attrs[r];if(o&&!bs(i,o))throw new te(`Invalid value for attribute '${r}' in entity '${e}'. Expected ${o.valueType}, but received: ${typeof i}`)}},mn=(e,t,n)=>{const s=yn(e,n);if(typeof t!="object"||t===null)throw new te(`Arguments for link operation on entity '${e}' must be an object, but received: ${typeof t}`);for(const[r,i]of Object.entries(t)){if(!s.links[r]){const a=Object.keys(s.links);throw new te(`Link '${r}' does not exist on entity '${e}'. Available links: ${pn(a)}`)}if(i!=null){if(Array.isArray(i)){for(const a of i)if(!hn(a))throw new te(`Invalid entity ID in link '${r}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`)}else if(!hn(i))throw new te(`Invalid UUID in link '${r}' for entity '${e}'. Expected a UUID, but received: ${i}`)}}},gs={create:_t,update:_t,merge:_t,link:mn,unlink:mn,delete:()=>{}},ws=(e,t)=>{if(!t)return;const[n,s,r,i]=e;if(!Array.isArray(r)&&!P(r))throw new te(`Invalid id for entity '${s}'. Expected a UUID, but received: ${r}`);if(typeof s!="string")throw new te(`Entity name must be a string, but received: ${typeof s}`);const o=gs[n];o&&i!==void 0&&o(s,i,t)},Ss=(e,t)=>{const n=Array.isArray(e)?e:[e];for(const s of n){if(!s||typeof s!="object")throw new te(`Transaction chunk must be an object, but received: ${typeof s}`);if(!Array.isArray(s.__ops))throw new te(`Transaction chunk must have __ops array, but received: ${typeof s.__ops}`);for(const r of s.__ops){if(!Array.isArray(r))throw new te(`Transaction operation must be an array, but received: ${typeof r}`);ws(r,t)}}};let Is=0;class ks{constructor(t,n,s){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}_${Is++}`,this.url=n,this.messageUrl=s||this.url,this.ES=t,this.conn=new t(n),this.sseInitTimeout=setTimeout(()=>{this.initParams||this.handleError()},1e4),this.conn.onmessage=r=>{const i=JSON.parse(r.data);if(Array.isArray(i))for(const o of i)this.handleMessage(o);else this.handleMessage(i)},this.conn.onerror=r=>{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,s,r;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:(s=this.initParams)==null?void 0:s.sessionId,sse_token:(r=this.initParams)==null?void 0:r.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 bn;(function(e){e.InitialSyncBatch="InitialSyncBatch",e.InitialSyncComplete="InitialSyncComplete",e.LoadFromStorage="LoadFromStorage",e.SyncTransaction="SyncTransaction",e.Error="Error"})(bn||(bn={}));function $s({WStream:e,opts:t,startStream:n,appendStream:s,registerStream:r}){const i=t.clientId;let o=null,a=null,c=null;const u=Pe();let h=!1,l=!1;const y=[],m=[],g=[];let w=!1,p=0,$=0;const v=[],V=new TextEncoder;function Re(){l=!0;for(const b of y)b(a??void 0)}function zt(b){return y.push(b),l&&b(a??void 0),()=>{const I=y.indexOf(b);I!==-1&&y.splice(I,1)}}function jn(b){return g.push(b),()=>{const I=g.indexOf(b);I!==-1&&g.splice(I,1)}}t.waitUntil&&t.waitUntil(new Promise(b=>{g.push(b)}));function j(){for(const b of g)try{b()}catch{}}function T(b){return m.push(b),o&&b(o),()=>{const I=m.indexOf(b);I!==-1&&m.splice(I,1)}}function ie(b){o=b;for(const I of m)I(o)}function R(){w=!0}function z(b){let I=p,W=0,Y=0;for(const{byteLen:oe}of v){const he=I+oe;if(he>b)break;I=he,W++,Y+=oe}W>0&&(p+=Y,$-=Y,v.splice(0,W))}function N(b,I){a=I,Re(),b.error(I),j()}async function ne(){const b=await n({clientId:i,reconnectToken:u,ruleParams:t.ruleParams});switch(b.type){case"ok":{const{streamId:I,offset:W}=b;o=I,z(W),v.length&&s({streamId:I,chunks:v.map(Y=>Y.chunk),offset:p}),w=!1;break}case"disconnect":{R();break}case"error":{c&&N(c,b.error);break}}}function J(){R(),ne()}function bt({offset:b,done:I}){z(b),I&&(h=!0,j())}function Un(b){return h?(N(b,new _("Stream has been closed.")),null):o||(N(b,new _("Stream has not been initialized.")),null)}async function We(b){c=b;let I=!0,W=0;for(;I;){let Y=Date.now()+Math.min(15e3,500*(W-1));I=!1;const oe=await n({clientId:t.clientId,reconnectToken:u,ruleParams:t.ruleParams});switch(oe.type){case"ok":{const{streamId:he,offset:Wt}=oe;if(Wt!==0){const Ae=new _("Write stream is corrupted");N(b,Ae);return}ie(he),r(he,{onDisconnect:R,onFlush:bt,onConnectionReconnect:ne,onAppendFailed:J}),w=!1;return}case"disconnect":{I=!0,R(),W++,await new Promise(he=>{setTimeout(he,Math.max(0,Y-Date.now()))});break}case"error":{N(b,oe.error);return}}}}class ge extends e{constructor(I,W){super(I,W)}async streamId(){return o||new Promise((I,W)=>{const Y=[],oe=()=>{for(const Ae of Y)Ae()},he=Ae=>{I(Ae),oe()},Wt=Ae=>{W(Ae||new _("Stream is closed.")),oe()};Y.push(T(he)),Y.push(zt(Wt))})}}return{stream:new ge({async start(b){try{await We(b)}catch(I){N(b,I)}},write(b,I){const W=Un(I);if(W){const Y=V.encode(b).length;v.push({chunk:b,byteLen:Y});const oe=p+$;$+=Y,w||s({streamId:W,chunks:[b],offset:oe})}},close(){o?s({streamId:o,chunks:[],offset:p+$,isDone:!0}):j(),Re()},abort(b){o?s({streamId:o,chunks:[],offset:p+$,isDone:!0,abortReason:b}):j(),Re()}}),addCompleteCb:jn,closed(){return l}}}class vs{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(s=>{this.resolvers.push(s)});if(n||!t)return;yield t}}}}function Os({RStream:e,opts:t,startStream:n,cancelStream:s}){let r=t.byteOffset||0,i=!1;const o=new TextDecoder("utf-8"),a=new TextEncoder;let c,u=!1;const h=[],l=[];let y=null,m=null;function g(j){u=!0;for(const T of h)T(j)}function w(j){return h.push(j),()=>{const T=h.indexOf(j);T!==-1&&h.splice(T,1)}}function p(j){return l.push(j),y&&j(y),()=>{const T=l.indexOf(j);T!==-1&&l.splice(T,1)}}function $(j,T){m=T,j.error(T),g(T)}let v=0;async function V(j,T){c=Pe();const ie={...j||{},eventId:c};for await(const R of n(ie)){if(i)return;if(R.type==="reconnect")return{retry:!0};if(R.type==="error"){$(T,R.error);return}if(R.offset>r){$(T,new _("Stream is corrupted.")),i=!0;return}y=R.streamId;for(const N of l)N(y);let z=r-R.offset;if(R.files&&R.files.length){const N=new AbortController;let ne=fetch(R.files[0].url,{signal:N.signal});for(let J=0;J<R.files.length;J++){const bt=R.files[J+1],We=await ne;if(bt&&(ne=fetch(bt.url,{signal:N.signal})),!We.ok){if(v++,v>10){$(T,new _("Unable to process stream."));return}return{retry:!0}}if(We.body){const ge=We.body.getReader();try{for(;;){const{done:we,value:b}=await ge.read();if(we)break;if(i){N.abort();return}let I=b;if(z>0&&(I=b.subarray(z),z-=b.length-I.length),!I.length)continue;r+=I.length;const W=o.decode(I);T.enqueue(W)}}finally{ge.releaseLock()}}else{const ge=await We.arrayBuffer();let we=ge;if(i){N.abort();return}if(z>0&&(we=new Uint8Array(ge).subarray(z),z-=ge.byteLength-we.length),!we.byteLength)continue;r+=we.byteLength;const b=o.decode(we);T.enqueue(b)}}}if(v=0,R.content){let N=R.content,ne=a.encode(R.content);if(z>0){const J=ne.subarray(z);if(z-=ne.length-J.length,!J.length)continue;ne=J,N=o.decode(J)}r+=ne.length,T.enqueue(N)}}}async function Re(j){let T=!0,ie=0;for(;T;){T=!1;let R=Date.now()+Math.min(15e3,500*(ie-1));const z=await V({...t,offset:r},j);z!=null&&z.retry&&(T=!0,ie++,R<Date.now()-3e5&&(ie=0),await new Promise(N=>{setTimeout(N,Math.max(0,R-Date.now()))}))}!i&&!u&&(j.close(),g())}class zt extends e{constructor(T,ie){super(T,ie)}async streamId(){if(y)return y;if(m)throw m;return new Promise((T,ie)=>{const R=[],z=()=>{for(const J of R)J()},N=J=>{T(J),z()},ne=J=>{ie(J||new _("Stream is closed.")),z()};R.push(p(N)),R.push(w(ne))})}}return{stream:new zt({start(j){Re(j)},cancel(j){i=!0,c&&s({eventId:c}),g()}}),addCloseCb:w,closed(){return u}}}class Es{constructor({WStream:t,RStream:n,trySend:s,log:r}){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=s,this.log=r}createWriteStream(t){const{stream:n,addCompleteCb:s}=$s({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),s(()=>{this.activeStreams.delete(n)}),n}createReadStream(t){const{stream:n,addCloseCb:s}=Os({RStream:this.RStream,opts:t,startStream:this.startReadStream.bind(this),cancelStream:this.cancelReadStream.bind(this)});return this.activeStreams.add(n),s(()=>{this.activeStreams.delete(n)}),n}startWriteStream(t){const n=Pe();let s=null;const r=new Promise(o=>{s=o});this.startWriteStreamCbs[n]=s;const i={op:"start-stream","client-id":t.clientId,"reconnect-token":t.reconnectToken};return t.ruleParams&&(i["rule-params"]=t.ruleParams),this.trySend(n,i),r}registerWriteStream(t,n){this.writeStreams[t]=n}appendStream({streamId:t,chunks:n,isDone:s,offset:r,abortReason:i}){const o={op:"append-stream","stream-id":t,chunks:n,offset:r,done:!!s};i&&(o["abort-reason"]=i),this.trySend(Pe(),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"],s=this.writeStreams[n];if(!s){this.log.info("No stream cbs for stream-flushed",t);return}s.onFlush({offset:t.offset,done:t.done}),t.done&&delete this.writeStreams[n]}startReadStream({eventId:t,clientId:n,streamId:s,offset:r,ruleParams:i}){const o={op:"subscribe-stream"};if(!s&&!n)throw new Error("Must provide one of streamId or clientId to subscribe to the stream.");s&&(o["stream-id"]=s),n&&(o["client-id"]=n),r&&(o.offset=r),i&&(o["rule-params"]=i);const a=new vs;return this.readStreamIterators[t]=a,this.trySend(t,o),a}cancelReadStream({eventId:t}){const n={op:"unsubscribe-stream","subscribe-event-id":t};this.trySend(Pe(),n),delete this.readStreamIterators[t]}onStreamAppend(t){const n=t["client-event-id"],s=this.readStreamIterators[n];if(!s){this.log.info("No iterator for read stream",t);return}if(t.error){t.retry?s.push({type:"reconnect"}):s.push({type:"error",error:new _(t.error)}),s.close(),delete this.readStreamIterators[n];return}s.push({type:"append",offset:t.offset,files:t.files,content:t.content,streamId:t["stream-id"]}),t.done&&(s.close(),delete this.readStreamIterators[n])}onConnectionStatusChange(t){for(const n of Object.values(this.startWriteStreamCbs))n({type:"disconnect"});if(this.startWriteStreamCbs={},t!==Cs.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 s=n["stream-id"],r=this.writeStreams[s];r==null||r.onAppendFailed();break}case"start-stream":{const s=t["client-event-id"],r=this.startWriteStreamCbs[s];r&&(r({type:"error",error:new _(t.message||"Unknown error",t.hint)}),delete this.startWriteStreamCbs[s]);break}case"subscribe-stream":{const s=t["client-event-id"],r=this.readStreamIterators[s];r&&(r.push({type:"error",error:new _(t.message||"Unknown error",t.hint)}),r.close(),delete this.readStreamIterators[s]);break}}}hasActiveStreams(){return this.activeStreams.size>0}}const Cs={AUTHENTICATED:"authenticated"};class xs extends _{constructor(t){super(t),this.name="MissingApiURIError"}get[Symbol.toStringTag](){return"MissingApiURIError"}}function Ts({target:e,option:t="apiURI",envVar:n}){return`No SidekickDB server URL configured. ${n?`Pass \`${t}\` to ${e} or set the ${n} environment variable`:`Pass \`${t}\` to ${e}`}, for example ${t}: 'https://sidekick.example.com'. SidekickDB has no default server.`}function Rt(e,t){if(typeof e=="string"&&e.trim()!=="")return e;throw new xs(Ts(t))}function _s(){return globalThis.__instantDbSchemaHashStore=globalThis.__instantDbSchemaHashStore??new WeakMap,globalThis.__instantDbSchemaHashStore}function Rs(){return globalThis.__instantDbStore=globalThis.__instantDbStore??{},globalThis.__instantDbStore}Rs(),_s();class gn extends Event{constructor(n,s){super(n);d(this,"code");d(this,"message");this.code=(s==null?void 0:s.code)??void 0,this.message=(s==null?void 0:s.message)??void 0}[Symbol.for("nodejs.util.inspect.custom")](n,s,r){return r(wn(this),s)}[Symbol.for("Deno.customInspect")](n,s){return n(wn(this),s)}}function As(e){const t=globalThis.DOMException;return typeof t=="function"?new t(e,"SyntaxError"):new SyntaxError(e)}function At(e){return e instanceof Error?"errors"in e&&Array.isArray(e.errors)?e.errors.map(At).join(", "):"cause"in e&&e.cause instanceof Error?`${e}: ${At(e.cause)}`:e.message:`${e}`}function wn(e){return{type:e.type,message:e.message,code:e.code,defaultPrevented:e.defaultPrevented,cancelable:e.cancelable,timeStamp:e.timeStamp}}class Sn 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 Pt(e){}function Ps(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=Pt,onError:n=Pt,onRetry:s=Pt,onComment:r}=e;let i="",o=!0,a,c="",u="";function h(w){const p=o?w.replace(/^\xEF\xBB\xBF/,""):w,[$,v]=js(`${i}${p}`);for(const V of $)l(V);i=v,o=!1}function l(w){if(w===""){m();return}if(w.startsWith(":")){r&&r(w.slice(w.startsWith(": ")?2:1));return}const p=w.indexOf(":");if(p!==-1){const $=w.slice(0,p),v=w[p+1]===" "?2:1,V=w.slice(p+v);y($,V,w);return}y(w,"",w)}function y(w,p,$){switch(w){case"event":u=p;break;case"data":c=`${c}${p}
|
|
2
2
|
`;break;case"id":a=p.includes("\0")?void 0:p;break;case"retry":/^\d+$/.test(p)?s(parseInt(p,10)):n(new Sn(`Invalid \`retry\` value: "${p}"`,{type:"invalid-retry",value:p,line:$}));break;default:n(new Sn(`Unknown field "${w.length>20?`${w.slice(0,20)}…`:w}"`,{type:"unknown-field",field:w,value:p,line:$}));break}}function m(){c.length>0&&t({id:a,event:u||void 0,data:c.endsWith(`
|
|
3
3
|
`)?c.slice(0,-1):c}),a=void 0,c="",u=""}function g(w={}){i&&w.consume&&l(i),o=!0,a=void 0,c="",u="",i=""}return{feed:h,reset:g}}function js(e){const t=[];let n="",s=0;for(;s<e.length;){const r=e.indexOf("\r",s),i=e.indexOf(`
|
|
4
4
|
`,s);let o=-1;if(r!==-1&&i!==-1?o=Math.min(r,i):r!==-1?r===e.length-1?o=-1:o=r:i!==-1&&(o=i),o===-1){n=e.slice(s);break}else{const a=e.slice(s,o);t.push(a),s=o+1,e[s-1]==="\r"&&e[s]===`
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sidekickdb/resumable-stream",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "SidekickDB's drop-in replacement for Vercel's resumable-stream package.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://sidekickdb.co/docs/streams",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/SidekickDB/sidekick.git",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"vitest": "^1.6.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@sidekickdb/admin": "2.0.
|
|
57
|
+
"@sidekickdb/admin": "2.0.1"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest",
|