@instantdb/platform 0.22.140 → 0.22.141

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.
@@ -1,17 +1,17 @@
1
1
 
2
- > @instantdb/platform@0.22.140 build /home/runner/work/instant/instant/client/packages/platform
2
+ > @instantdb/platform@0.22.141 build /home/runner/work/instant/instant/client/packages/platform
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/platform@0.22.140 build:tshy
8
+ > @instantdb/platform@0.22.141 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/platform@0.22.140 build:standalone
14
+ > @instantdb/platform@0.22.141 build:standalone
15
15
  > vite build
16
16
 
17
17
  vite v5.4.14 building for production...
@@ -21,15 +21,15 @@ rendering chunks...
21
21
  computing gzip size...
22
22
  dist/standalone/index.umd.cjs 353.83 kB │ gzip: 96.24 kB
23
23
  dist/standalone/index.js 462.04 kB │ gzip: 108.59 kB
24
- ✓ built in 3.00s
24
+ ✓ built in 3.06s
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/platform@0.22.140 check-exports
28
+ > @instantdb/platform@0.22.141 check-exports
29
29
  > attw --pack .
30
30
 
31
31
 
32
- @instantdb/platform v0.22.140
32
+ @instantdb/platform v0.22.141
33
33
 
34
34
  Build tools:
35
35
  - @arethetypeswrong/cli@^0.17.4
@@ -838,7 +838,7 @@ class ze extends qt {
838
838
  }
839
839
  }
840
840
  typeof window < "u" && typeof window.localStorage < "u" && (window.localStorage.getItem("devBackend"), window.localStorage.getItem("__instantLogging"), window.localStorage.getItem("__devtoolLocalDash"));
841
- const Ue = "v0.22.140";
841
+ const Ue = "v0.22.141";
842
842
  class Q {
843
843
  constructor(t, s, e, i = { indexed: !1, unique: !1 }) {
844
844
  m(this, "valueType");
@@ -1,4 +1,4 @@
1
- (function(A,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(A=typeof globalThis<"u"?globalThis:A||self,v(A.instant={}))})(this,function(A){"use strict";var Jn=Object.defineProperty;var Ni=A=>{throw TypeError(A)};var Wn=(A,v,N)=>v in A?Jn(A,v,{enumerable:!0,configurable:!0,writable:!0,value:N}):A[v]=N;var m=(A,v,N)=>Wn(A,typeof v!="symbol"?v+"":v,N),ki=(A,v,N)=>v.has(A)||Ni("Cannot "+N);var T=(A,v,N)=>(ki(A,v,"read from private field"),N?N.call(A):v.get(A)),xe=(A,v,N)=>v.has(A)?Ni("Cannot add the same private member more than once"):v instanceof WeakSet?v.add(A):v.set(A,N),Pe=(A,v,N,Be)=>(ki(A,v,"write to private field"),Be?Be.call(A,N):v.set(A,N),N);var se,Y,Pt,gt,bt,F,j;class v extends Error{constructor(s){super(s.message);m(this,"error");m(this,"errorDescription");const e=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,e),Error.captureStackTrace&&Error.captureStackTrace(this,v),this.name="InstantOAuthError",this.error=s.error,this.errorDescription=s.errorDescription}get[Symbol.toStringTag](){return"InstantAPIError"}}const N={Remove:"remove",Replace:"replace",Add:"add"},Be=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),Xe=Symbol.iterator,Z={mutable:"mutable",immutable:"immutable"},Tt={};function Re(r,t){return r instanceof Map?r.has(t):Object.prototype.hasOwnProperty.call(r,t)}function cs(r,t){if(t in r){let s=Reflect.getPrototypeOf(r);for(;s;){const e=Reflect.getOwnPropertyDescriptor(s,t);if(e)return e;s=Reflect.getPrototypeOf(s)}}}function hs(r){return Object.getPrototypeOf(r)===Set.prototype}function ls(r){return Object.getPrototypeOf(r)===Map.prototype}function G(r){var t;return(t=r.copy)!==null&&t!==void 0?t:r.original}function At(r){return!!L(r)}function L(r){return typeof r!="object"?null:r==null?void 0:r[Be]}function St(r){var t;const s=L(r);return s?(t=s.copy)!==null&&t!==void 0?t:s.original:r}function ge(r,t){if(!r||typeof r!="object")return!1;let s;return Object.getPrototypeOf(r)===Object.prototype||Array.isArray(r)||r instanceof Map||r instanceof Set||!!(t!=null&&t.mark)&&((s=t.mark(r,Z))===Z.immutable||typeof s=="function")}function us(r,t=[]){if(Object.hasOwnProperty.call(r,"key")){const s=r.parent.copy,e=L(le(s,r.key));if(e!==null&&(e==null?void 0:e.original)!==r.original)return null;const i=r.parent.type===3,a=i?Array.from(r.parent.setMap.keys()).indexOf(r.key):r.key;if(!(i&&s.size>a||Re(s,a)))return null;t.push(a)}if(r.parent)return us(r.parent,t);t.reverse();try{vi(r.copy,t)}catch{return null}return t}function je(r){return Array.isArray(r)?1:r instanceof Map?2:r instanceof Set?3:0}function le(r,t){return je(r)===2?r.get(t):r[t]}function Et(r,t,s){je(r)===2?r.set(t,s):r[t]=s}function It(r,t){const s=L(r);return(s?G(s):r)[t]}function be(r,t){return r===t?r!==0||1/r===1/t:r!==r&&t!==t}function we(r,t){return t?r:[""].concat(r).map(s=>{const e=`${s}`;return e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}).join("/")}function vi(r,t){for(let s=0;s<t.length-1;s+=1){const e=t[s];if(r=le(je(r)===3?Array.from(r):r,e),typeof r!="object")throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}return r}function Oi(r){const t=Object.create(Object.getPrototypeOf(r));return Reflect.ownKeys(r).forEach(s=>{let e=Reflect.getOwnPropertyDescriptor(r,s);if(e.enumerable&&e.configurable&&e.writable){t[s]=r[s];return}e.writable||(e.writable=!0,e.configurable=!0),(e.get||e.set)&&(e={configurable:!0,writable:!0,enumerable:e.enumerable,value:r[s]}),Reflect.defineProperty(t,s,e)}),t}const Di=Object.prototype.propertyIsEnumerable;function Li(r,t){let s;if(Array.isArray(r))return Array.prototype.concat.call(r);if(r instanceof Set){if(!hs(r)){const e=Object.getPrototypeOf(r).constructor;return new e(r.values())}return Set.prototype.difference?Set.prototype.difference.call(r,new Set):new Set(r.values())}else if(r instanceof Map){if(!ls(r)){const e=Object.getPrototypeOf(r).constructor;return new e(r)}return new Map(r)}else if(t!=null&&t.mark&&(s=t.mark(r,Z),s!==void 0)&&s!==Z.mutable){if(s===Z.immutable)return Oi(r);if(typeof s=="function"){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return s()}throw new Error(`Unsupported mark result: ${s}`)}else if(typeof r=="object"&&Object.getPrototypeOf(r)===Object.prototype){const e={};return Object.keys(r).forEach(i=>{e[i]=r[i]}),Object.getOwnPropertySymbols(r).forEach(i=>{Di.call(r,i)&&(e[i]=r[i])}),e}else throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function K(r){r.copy||(r.copy=Li(r.original,r.options))}function _e(r){if(!ge(r))return St(r);if(Array.isArray(r))return r.map(_e);if(r instanceof Map){const s=Array.from(r.entries()).map(([e,i])=>[e,_e(i)]);if(!ls(r)){const e=Object.getPrototypeOf(r).constructor;return new e(s)}return new Map(s)}if(r instanceof Set){const s=Array.from(r).map(_e);if(!hs(r)){const e=Object.getPrototypeOf(r).constructor;return new e(s)}return new Set(s)}const t=Object.create(Object.getPrototypeOf(r));for(const s in r)t[s]=_e(r[s]);return t}function Ge(r){return At(r)?_e(r):r}function ie(r){var t;r.assignedMap=(t=r.assignedMap)!==null&&t!==void 0?t:new Map,r.operated||(r.operated=!0,r.parent&&ie(r.parent))}function Mi(r,t){const s=je(r);if(s===0)Reflect.ownKeys(r).forEach(e=>{t(e,r[e],r)});else if(s===1){let e=0;for(const i of r)t(e,i,r),e+=1}else r.forEach((e,i)=>t(i,e,r))}function ps(r,t,s){if(At(r)||!ge(r,s)||t.has(r)||Object.isFrozen(r))return;const e=r instanceof Set,i=e?new Map:void 0;if(t.add(r),Mi(r,(a,n)=>{var o;if(At(n)){const c=L(n);K(c);const h=!((o=c.assignedMap)===null||o===void 0)&&o.size||c.operated?c.copy:c.original;Et(e?i:r,a,h)}else ps(n,t,s)}),i){const a=r,n=Array.from(a);a.clear(),n.forEach(o=>{a.add(i.has(o)?i.get(o):o)})}}function Fi(r,t){const s=r.type===3?r.setMap:r.copy;r.finalities.revoke.length>1&&r.assignedMap.get(t)&&s&&ps(le(s,t),r.finalities.handledSet,r.options)}function Ct(r){r.type===3&&r.copy&&(r.copy.clear(),r.setMap.forEach(t=>{r.copy.add(St(t))}))}function Nt(r,t,s,e){if(r.operated&&r.assignedMap&&r.assignedMap.size>0&&!r.finalized){if(s&&e){const a=us(r);a&&t(r,a,s,e)}r.finalized=!0}}function kt(r,t,s,e){const i=L(s);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push((a,n)=>{var o;const c=r.type===3?r.setMap:r.copy;if(be(le(c,t),s)){let h=i.original;i.copy&&(h=i.copy),Ct(r),Nt(r,e,a,n),r.options.enableAutoFreeze&&(r.options.updatedValues=(o=r.options.updatedValues)!==null&&o!==void 0?o:new WeakMap,r.options.updatedValues.set(h,i.original)),Et(c,t,h)}}),r.options.enableAutoFreeze&&i.finalities!==r.finalities&&(r.options.enableAutoFreeze=!1)),ge(s,r.options)&&r.finalities.draft.push(()=>{const a=r.type===3?r.setMap:r.copy;be(le(a,t),s)&&Fi(r,t)})}function Bi(r,t,s,e,i){let{original:a,assignedMap:n,options:o}=r,c=r.copy;c.length<a.length&&([a,c]=[c,a],[s,e]=[e,s]);for(let h=0;h<a.length;h+=1)if(n.get(h.toString())&&c[h]!==a[h]){const l=t.concat([h]),u=we(l,i);s.push({op:N.Replace,path:u,value:Ge(c[h])}),e.push({op:N.Replace,path:u,value:Ge(a[h])})}for(let h=a.length;h<c.length;h+=1){const l=t.concat([h]),u=we(l,i);s.push({op:N.Add,path:u,value:Ge(c[h])})}if(a.length<c.length){const{arrayLengthAssignment:h=!0}=o.enablePatches;if(h){const l=t.concat(["length"]),u=we(l,i);e.push({op:N.Replace,path:u,value:a.length})}else for(let l=c.length;a.length<l;l-=1){const u=t.concat([l-1]),d=we(u,i);e.push({op:N.Remove,path:d})}}}function Ri({original:r,copy:t,assignedMap:s},e,i,a,n){s.forEach((o,c)=>{const h=le(r,c),l=Ge(le(t,c)),u=o?Re(r,c)?N.Replace:N.Add:N.Remove;if(be(h,l)&&u===N.Replace)return;const d=e.concat(c),f=we(d,n);i.push(u===N.Remove?{op:u,path:f}:{op:u,path:f,value:l}),a.push(u===N.Add?{op:N.Remove,path:f}:u===N.Remove?{op:N.Add,path:f,value:h}:{op:N.Replace,path:f,value:h})})}function ji({original:r,copy:t},s,e,i,a){let n=0;r.forEach(o=>{if(!t.has(o)){const c=s.concat([n]),h=we(c,a);e.push({op:N.Remove,path:h,value:o}),i.unshift({op:N.Add,path:h,value:o})}n+=1}),n=0,t.forEach(o=>{if(!r.has(o)){const c=s.concat([n]),h=we(c,a);e.push({op:N.Add,path:h,value:o}),i.unshift({op:N.Remove,path:h,value:o})}n+=1})}function Ue(r,t,s,e){const{pathAsArray:i=!0}=r.options.enablePatches;switch(r.type){case 0:case 2:return Ri(r,t,s,e,i);case 1:return Bi(r,t,s,e,i);case 3:return ji(r,t,s,e,i)}}const Ye=(r,t,s=!1)=>{if(typeof r=="object"&&r!==null&&(!ge(r,t)||s))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},vt={get size(){return G(L(this)).size},has(r){return G(L(this)).has(r)},set(r,t){const s=L(this),e=G(s);return(!e.has(r)||!be(e.get(r),t))&&(K(s),ie(s),s.assignedMap.set(r,!0),s.copy.set(r,t),kt(s,r,t,Ue)),this},delete(r){if(!this.has(r))return!1;const t=L(this);return K(t),ie(t),t.original.has(r)?t.assignedMap.set(r,!1):t.assignedMap.delete(r),t.copy.delete(r),!0},clear(){const r=L(this);if(this.size){K(r),ie(r),r.assignedMap=new Map;for(const[t]of r.original)r.assignedMap.set(t,!1);r.copy.clear()}},forEach(r,t){const s=L(this);G(s).forEach((e,i)=>{r.call(t,this.get(i),i,this)})},get(r){var t,s;const e=L(this),i=G(e).get(r),a=((s=(t=e.options).mark)===null||s===void 0?void 0:s.call(t,i,Z))===Z.mutable;if(e.options.strict&&Ye(i,e.options,a),a||e.finalized||!ge(i,e.options)||i!==e.original.get(r))return i;const n=Tt.createDraft({original:i,parentDraft:e,key:r,finalities:e.finalities,options:e.options});return K(e),e.copy.set(r,n),n},keys(){return G(L(this)).keys()},values(){const r=this.keys();return{[Xe]:()=>this.values(),next:()=>{const t=r.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const r=this.keys();return{[Xe]:()=>this.entries(),next:()=>{const t=r.next();if(t.done)return t;const s=this.get(t.value);return{done:!1,value:[t.value,s]}}}},[Xe](){return this.entries()}},_i=Reflect.ownKeys(vt),fs=(r,t,{isValuesIterator:s})=>()=>{var e,i;const a=t.next();if(a.done)return a;const n=a.value;let o=r.setMap.get(n);const c=L(o),h=((i=(e=r.options).mark)===null||i===void 0?void 0:i.call(e,o,Z))===Z.mutable;if(r.options.strict&&Ye(n,r.options,h),!h&&!c&&ge(n,r.options)&&!r.finalized&&r.original.has(n)){const l=Tt.createDraft({original:n,parentDraft:r,key:n,finalities:r.finalities,options:r.options});r.setMap.set(n,l),o=l}else c&&(o=c.proxy);return{done:!1,value:s?o:[o,o]}},Qe={get size(){return L(this).setMap.size},has(r){const t=L(this);if(t.setMap.has(r))return!0;K(t);const s=L(r);return!!(s&&t.setMap.has(s.original))},add(r){const t=L(this);return this.has(r)||(K(t),ie(t),t.assignedMap.set(r,!0),t.setMap.set(r,r),kt(t,r,r,Ue)),this},delete(r){if(!this.has(r))return!1;const t=L(this);K(t),ie(t);const s=L(r);return s&&t.setMap.has(s.original)?(t.assignedMap.set(s.original,!1),t.setMap.delete(s.original)):(!s&&t.setMap.has(r)?t.assignedMap.set(r,!1):t.assignedMap.delete(r),t.setMap.delete(r))},clear(){if(!this.size)return;const r=L(this);K(r),ie(r);for(const t of r.original)r.assignedMap.set(t,!1);r.setMap.clear()},values(){const r=L(this);K(r);const t=r.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:fs(r,t,{isValuesIterator:!0})}},entries(){const r=L(this);K(r);const t=r.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:fs(r,t,{isValuesIterator:!1})}},keys(){return this.values()},[Xe](){return this.values()},forEach(r,t){const s=this.values();let e=s.next();for(;!e.done;)r.call(t,e.value,e.value,this),e=s.next()}};Set.prototype.difference&&Object.assign(Qe,{intersection(r){return Set.prototype.intersection.call(new Set(this.values()),r)},union(r){return Set.prototype.union.call(new Set(this.values()),r)},difference(r){return Set.prototype.difference.call(new Set(this.values()),r)},symmetricDifference(r){return Set.prototype.symmetricDifference.call(new Set(this.values()),r)},isSubsetOf(r){return Set.prototype.isSubsetOf.call(new Set(this.values()),r)},isSupersetOf(r){return Set.prototype.isSupersetOf.call(new Set(this.values()),r)},isDisjointFrom(r){return Set.prototype.isDisjointFrom.call(new Set(this.values()),r)}});const Ui=Reflect.ownKeys(Qe),ds=new WeakSet,ms={get(r,t,s){var e,i;const a=(e=r.copy)===null||e===void 0?void 0:e[t];if(a&&ds.has(a))return a;if(t===Be)return r;let n;if(r.options.mark){const h=t==="size"&&(r.original instanceof Map||r.original instanceof Set)?Reflect.get(r.original,t):Reflect.get(r.original,t,s);if(n=r.options.mark(h,Z),n===Z.mutable)return r.options.strict&&Ye(h,r.options,!0),h}const o=G(r);if(o instanceof Map&&_i.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(vt,"size").get.call(r.proxy);const h=vt[t];if(h)return h.bind(r.proxy)}if(o instanceof Set&&Ui.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(Qe,"size").get.call(r.proxy);const h=Qe[t];if(h)return h.bind(r.proxy)}if(!Re(o,t)){const h=cs(o,t);return h?"value"in h?h.value:(i=h.get)===null||i===void 0?void 0:i.call(r.proxy):void 0}const c=o[t];if(r.options.strict&&Ye(c,r.options),r.finalized||!ge(c,r.options))return c;if(c===It(r.original,t)){if(K(r),r.copy[t]=ys({original:r.original[t],parentDraft:r,key:r.type===1?Number(t):t,finalities:r.finalities,options:r.options}),typeof n=="function"){const h=L(r.copy[t]);return K(h),ie(h),h.copy}return r.copy[t]}return c},set(r,t,s){var e;if(r.type===3||r.type===2)throw new Error("Map/Set draft does not support any property assignment.");let i;if(r.type===1&&t!=="length"&&!(Number.isInteger(i=Number(t))&&i>=0&&(t===0||i===0||String(i)===String(t))))throw new Error("Only supports setting array indices and the 'length' property.");const a=cs(G(r),t);if(a!=null&&a.set)return a.set.call(r.proxy,s),!0;const n=It(G(r),t),o=L(n);return o&&be(o.original,s)?(r.copy[t]=s,r.assignedMap=(e=r.assignedMap)!==null&&e!==void 0?e:new Map,r.assignedMap.set(t,!1),!0):(be(s,n)&&(s!==void 0||Re(r.original,t))||(K(r),ie(r),Re(r.original,t)&&be(s,r.original[t])?r.assignedMap.delete(t):r.assignedMap.set(t,!0),r.copy[t]=s,kt(r,t,s,Ue)),!0)},has(r,t){return t in G(r)},ownKeys(r){return Reflect.ownKeys(G(r))},getOwnPropertyDescriptor(r,t){const s=G(r),e=Reflect.getOwnPropertyDescriptor(s,t);return e&&{writable:!0,configurable:r.type!==1||t!=="length",enumerable:e.enumerable,value:s[t]}},getPrototypeOf(r){return Reflect.getPrototypeOf(r.original)},setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(r,t){var s;return r.type===1?ms.set.call(this,r,t,void 0,r.proxy):(It(r.original,t)!==void 0||t in r.original?(K(r),ie(r),r.assignedMap.set(t,!1)):(r.assignedMap=(s=r.assignedMap)!==null&&s!==void 0?s:new Map,r.assignedMap.delete(t)),r.copy&&delete r.copy[t],!0)}};function ys(r){const{original:t,parentDraft:s,key:e,finalities:i,options:a}=r,n=je(t),o={type:n,finalized:!1,parent:s,original:t,copy:null,proxy:null,finalities:i,options:a,setMap:n===3?new Map(t.entries()):void 0};(e||"key"in r)&&(o.key=e);const{proxy:c,revoke:h}=Proxy.revocable(n===1?Object.assign([],o):o,ms);if(i.revoke.push(h),ds.add(c),o.proxy=c,s){const l=s;l.finalities.draft.push((u,d)=>{var f,x;const S=L(c);let _=l.type===3?l.setMap:l.copy;const C=le(_,e),D=L(C);if(D){let U=D.original;D.operated&&(U=St(C)),Ct(D),Nt(D,Ue,u,d),l.options.enableAutoFreeze&&(l.options.updatedValues=(f=l.options.updatedValues)!==null&&f!==void 0?f:new WeakMap,l.options.updatedValues.set(U,D.original)),Et(_,e,U)}(x=S.callbacks)===null||x===void 0||x.forEach(U=>{U(u,d)})})}else{const l=L(c);l.finalities.draft.push((u,d)=>{Ct(l),Nt(l,Ue,u,d)})}return c}Tt.createDraft=ys,Object.prototype.constructor.toString();const z=[];for(let r=0;r<256;++r)z.push((r+256).toString(16).slice(1));function $i(r,t=0){return(z[r[t+0]]+z[r[t+1]]+z[r[t+2]]+z[r[t+3]]+"-"+z[r[t+4]]+z[r[t+5]]+"-"+z[r[t+6]]+z[r[t+7]]+"-"+z[r[t+8]]+z[r[t+9]]+"-"+z[r[t+10]]+z[r[t+11]]+z[r[t+12]]+z[r[t+13]]+z[r[t+14]]+z[r[t+15]]).toLowerCase()}let Ot;const qi=new Uint8Array(16);function zi(){if(!Ot){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ot=crypto.getRandomValues.bind(crypto)}return Ot(qi)}const xs={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Vi(r,t,s){var i;if(xs.randomUUID&&!r)return xs.randomUUID();r=r||{};const e=r.random??((i=r.rng)==null?void 0:i.call(r))??zi();if(e.length<16)throw new Error("Random bytes length must be >= 16");return e[6]=e[6]&15|64,e[8]=e[8]&63|128,$i(e)}function Ps(){return Vi()}function Hi(r,t){return r.localeCompare(t)}function Ki(){let r=Hi;if(typeof Intl=="object"&&Intl.hasOwnProperty("Collator"))try{r=Intl.Collator("en-US").compare}catch{}return r}Ki();function Ji(){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 Wi=Ji();function Ze(r,t,s){const e={__etype:r,__ops:s};return new Proxy(e,{get:(i,a)=>{if(a==="__ops")return s;if(a==="__etype")return r;if(Wi.has(a))return(n,o)=>Ze(r,t,[...s,o?[a,r,t,n,o]:[a,r,t,n]])}})}function Xi(r,t){return`lookup__${r}__${JSON.stringify(t)}`}function Gi(r){return r.startsWith("lookup__")}function gs(r){const[t,s,...e]=r.split("__");return[s,JSON.parse(e.join("__"))]}function Yi(r){return new Proxy({__etype:r},{get(t,s){if(s==="lookup")return(i,a)=>Ze(r,gs(Xi(i,a)),[]);if(s==="__etype")return r;const e=s;return Gi(e)?Ze(r,gs(e),[]):Ze(r,e,[])}})}function Qi(){return new Proxy({},{get(r,t){return Yi(t)}})}Qi();class Dt extends Error{constructor(s,e){super(s);m(this,"hint");this.hint=e;const i=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,i),Error.captureStackTrace&&Error.captureStackTrace(this,Dt),this.name="InstantError"}get[Symbol.toStringTag](){return"InstantError"}}class $e extends Dt{constructor(s){var a;const e=((a=s.body)==null?void 0:a.message)||`API Error (${s.status})`;super(e,s.body.hint);m(this,"body");m(this,"status");const i=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,i),Error.captureStackTrace&&Error.captureStackTrace(this,$e),this.name="InstantAPIError",this.status=s.status,this.body=s.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 Ce="v0.22.140";class ee{constructor(t,s,e,i={indexed:!1,unique:!1}){m(this,"valueType");m(this,"required");m(this,"isIndexed");m(this,"config");m(this,"metadata",{});this.valueType=t,this.required=s,this.isIndexed=e,this.config=i}clientRequired(){return new ee(this.valueType,!1,this.isIndexed,this.config)}optional(){return new ee(this.valueType,!1,this.isIndexed,this.config)}unique(){return new ee(this.valueType,this.required,this.isIndexed,{...this.config,unique:!0})}indexed(){return new ee(this.valueType,this.required,!0,{...this.config,indexed:!0})}}class et{constructor(t,s){m(this,"attrs");m(this,"links");this.attrs=t,this.links=s}asType(){return new et(this.attrs,this.links)}}class tt{constructor(t,s,e){m(this,"entities");m(this,"links");m(this,"rooms");this.entities=t,this.links=s,this.rooms=e}withRoomSchema(){return new tt(this.entities,this.links,{})}}var bs;(function(r){r.InitialSyncBatch="InitialSyncBatch",r.InitialSyncComplete="InitialSyncComplete",r.LoadFromStorage="LoadFromStorage",r.SyncTransaction="SyncTransaction",r.Error="Error"})(bs||(bs={}));function Zi(r,t){return new tt(ws(r,t),t,void 0)}function er(r){return new et(r,{})}function tr(){return new ee("string",!0,!1)}function sr(){return new ee("number",!0,!1)}function ir(){return new ee("boolean",!0,!1)}function rr(){return new ee("date",!0,!1)}function ar(){return new ee("json",!0,!1)}function nr(){return new ee("json",!0,!1)}function ws(r,t){var i,a,n,o;const s={fwd:{},rev:{}};for(const c of Object.values(t))(i=s.fwd)[a=c.forward.on]||(i[a]={}),(n=s.rev)[o=c.reverse.on]||(n[o]={}),s.fwd[c.forward.on][c.forward.label]={entityName:c.reverse.on,cardinality:c.forward.has},s.rev[c.reverse.on][c.reverse.label]={entityName:c.forward.on,cardinality:c.reverse.has};return Object.fromEntries(Object.entries(r).map(([c,h])=>[c,new et(h.attrs,{...s.fwd[c],...s.rev[c]})]))}function or({entities:r,links:t,rooms:s}){const e=t??{},i=s??{};return new tt(ws(r,e),e,i)}const V={graph:Zi,schema:or,entity:er,string:tr,number:sr,boolean:ir,date:rr,json:ar,any:nr};function cr(){return globalThis.__instantDbSchemaHashStore=globalThis.__instantDbSchemaHashStore??new WeakMap,globalThis.__instantDbSchemaHashStore}function hr(){return globalThis.__instantDbStore=globalThis.__instantDbStore??{},globalThis.__instantDbStore}hr(),cr();function lr(){const r="0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-._~";let t="";for(const s of crypto.getRandomValues(new Uint8Array(64)))t=t+r[s%r.length];return t}function ur(r){return crypto.subtle.digest({name:"SHA-256"},new TextEncoder().encode(r))}function pr(r){return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function fr(r){return ur(r).then(t=>pr(btoa(String.fromCharCode(...Array.from(new Uint8Array(t))))))}function dr(){const r=Math.min(800,Math.floor(window.outerWidth*.8)),t=Math.min(630,Math.floor(window.outerHeight*.5)),s={width:r,height:t,left:Math.round(window.screenX+(window.outerWidth-r)/2),top:Math.round(window.screenY+(window.outerHeight-t)/8)},e={width:s.width,height:s.height,left:s.left,top:s.top,toolbar:0,scrollbars:1,status:1,resizable:1,menuBar:0,rel:"opener"};return Object.keys(e).map(i=>`${i}=${e[i]}`).join(",")}let Ts=null;function mr({clientId:r,state:t,codeChallenge:s,apiURI:e,redirectUri:i,scopes:a}){const n=new URL(`${e}/platform/oauth/start`);return n.searchParams.set("client_id",r),n.searchParams.set("redirect_uri",i),n.searchParams.set("scope",a.join(" ")),n.searchParams.set("state",t),n.searchParams.set("response_type","code"),n.searchParams.set("code_challenge",s),n.searchParams.set("code_challenge_method","S256"),n.toString()}async function yr({code:r,clientId:t,verifier:s,apiURI:e,redirectUri:i}){const a=await fetch(`${e}/platform/oauth/token`,{method:"POST",headers:{"Content-type":"application/json","Instant-Platform-Version":Ce,"Instant-Core-Version":Ce},body:JSON.stringify({grant_type:"authorization_code",code:r,redirect_uri:i,client_id:t,code_verifier:s})});if(!a.ok){const o=await a.text();let c;try{const h=JSON.parse(o);c={error:h.error,errorDescription:h.error_description,message:`OAuth error: ${h.error||"server_error"}`}}catch{c={error:"server_error",message:"OAuth error: server_error"}}throw new v(c)}const n=await a.json();return{token:n.access_token,expiresAt:new Date(Date.now()+(n.expires_in-30)*1e3)}}function xr(){if(typeof window>"u")throw new Error("This function may only be used in a browser context.");const r=new URL(window.location.href).searchParams,t=r.get("state"),s=r.get("error"),e=r.get("error_description"),i=r.get("code");if(!t)throw new Error("Invalid redirect. The state param is missing.");const a=new BroadcastChannel(t);return a.addEventListener("message",n=>{n.data.type==="oauth-redirect-window-done"&&window.close()}),a.postMessage({type:"oauth-redirect",state:t,error:s,errorDescription:e,code:i}),()=>{a.close()}}function Pr({clientId:r,apiURI:t,redirectUri:s,scopes:e}){if(typeof window>"u")throw new Error("OAuth flow can only be started on the client.");const i=Ts;i&&i.close();const a=crypto.randomUUID(),n=lr(),o=new BroadcastChannel(a),c=new Promise((l,u)=>{o.addEventListener("message",async d=>{if(d.data.type!=="oauth-redirect")return;const{state:f,error:x,code:S,errorDescription:_}=d.data;if(!(!f||f!==a)){if(S)try{const C=await yr({clientId:r,code:S,verifier:n,apiURI:t,redirectUri:s});l(C)}catch(C){C instanceof v&&u(C),u(new v({error:"server_error",message:"OAuth error exchanging code for token"}))}else u(typeof x=="string"?new v({error:x,errorDescription:_,message:`OAuth error: ${x}`}):new v({error:"server_error",message:"OAuth error: server_error"}));o.postMessage({type:"oauth-redirect-window-done"})}})}),h=window.open("",`instantdb_oauth_${Math.random()}`.replace(".",""),dr());return h?(Ts=h,fr(n).then(l=>{const u=mr({clientId:r,state:a,codeChallenge:l,apiURI:t,redirectUri:s,scopes:e});h.location.href=u}),c.finally(()=>o.close())):Promise.reject({error:"Could not open Auth window"})}class gr{constructor(t){m(this,"redirectUri");m(this,"clientId");m(this,"apiURI");this.redirectUri=t.redirectUri,this.apiURI=t.apiURI??"https://api.instantdb.com",this.clientId=t.clientId}startClientOnlyFlow(t){return Pr({clientId:this.clientId,apiURI:this.apiURI,redirectUri:this.redirectUri,scopes:t})}handleClientRedirect(){return xr()}}function br(r,t){const s=r&&Object.keys(r).length?JSON.stringify(r,null,2):`{
1
+ (function(A,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(A=typeof globalThis<"u"?globalThis:A||self,v(A.instant={}))})(this,function(A){"use strict";var Jn=Object.defineProperty;var Ni=A=>{throw TypeError(A)};var Wn=(A,v,N)=>v in A?Jn(A,v,{enumerable:!0,configurable:!0,writable:!0,value:N}):A[v]=N;var m=(A,v,N)=>Wn(A,typeof v!="symbol"?v+"":v,N),ki=(A,v,N)=>v.has(A)||Ni("Cannot "+N);var T=(A,v,N)=>(ki(A,v,"read from private field"),N?N.call(A):v.get(A)),xe=(A,v,N)=>v.has(A)?Ni("Cannot add the same private member more than once"):v instanceof WeakSet?v.add(A):v.set(A,N),Pe=(A,v,N,Be)=>(ki(A,v,"write to private field"),Be?Be.call(A,N):v.set(A,N),N);var se,Y,Pt,gt,bt,F,j;class v extends Error{constructor(s){super(s.message);m(this,"error");m(this,"errorDescription");const e=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,e),Error.captureStackTrace&&Error.captureStackTrace(this,v),this.name="InstantOAuthError",this.error=s.error,this.errorDescription=s.errorDescription}get[Symbol.toStringTag](){return"InstantAPIError"}}const N={Remove:"remove",Replace:"replace",Add:"add"},Be=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),Xe=Symbol.iterator,Z={mutable:"mutable",immutable:"immutable"},Tt={};function Re(r,t){return r instanceof Map?r.has(t):Object.prototype.hasOwnProperty.call(r,t)}function cs(r,t){if(t in r){let s=Reflect.getPrototypeOf(r);for(;s;){const e=Reflect.getOwnPropertyDescriptor(s,t);if(e)return e;s=Reflect.getPrototypeOf(s)}}}function hs(r){return Object.getPrototypeOf(r)===Set.prototype}function ls(r){return Object.getPrototypeOf(r)===Map.prototype}function G(r){var t;return(t=r.copy)!==null&&t!==void 0?t:r.original}function At(r){return!!L(r)}function L(r){return typeof r!="object"?null:r==null?void 0:r[Be]}function St(r){var t;const s=L(r);return s?(t=s.copy)!==null&&t!==void 0?t:s.original:r}function ge(r,t){if(!r||typeof r!="object")return!1;let s;return Object.getPrototypeOf(r)===Object.prototype||Array.isArray(r)||r instanceof Map||r instanceof Set||!!(t!=null&&t.mark)&&((s=t.mark(r,Z))===Z.immutable||typeof s=="function")}function us(r,t=[]){if(Object.hasOwnProperty.call(r,"key")){const s=r.parent.copy,e=L(le(s,r.key));if(e!==null&&(e==null?void 0:e.original)!==r.original)return null;const i=r.parent.type===3,a=i?Array.from(r.parent.setMap.keys()).indexOf(r.key):r.key;if(!(i&&s.size>a||Re(s,a)))return null;t.push(a)}if(r.parent)return us(r.parent,t);t.reverse();try{vi(r.copy,t)}catch{return null}return t}function je(r){return Array.isArray(r)?1:r instanceof Map?2:r instanceof Set?3:0}function le(r,t){return je(r)===2?r.get(t):r[t]}function Et(r,t,s){je(r)===2?r.set(t,s):r[t]=s}function It(r,t){const s=L(r);return(s?G(s):r)[t]}function be(r,t){return r===t?r!==0||1/r===1/t:r!==r&&t!==t}function we(r,t){return t?r:[""].concat(r).map(s=>{const e=`${s}`;return e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}).join("/")}function vi(r,t){for(let s=0;s<t.length-1;s+=1){const e=t[s];if(r=le(je(r)===3?Array.from(r):r,e),typeof r!="object")throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}return r}function Oi(r){const t=Object.create(Object.getPrototypeOf(r));return Reflect.ownKeys(r).forEach(s=>{let e=Reflect.getOwnPropertyDescriptor(r,s);if(e.enumerable&&e.configurable&&e.writable){t[s]=r[s];return}e.writable||(e.writable=!0,e.configurable=!0),(e.get||e.set)&&(e={configurable:!0,writable:!0,enumerable:e.enumerable,value:r[s]}),Reflect.defineProperty(t,s,e)}),t}const Di=Object.prototype.propertyIsEnumerable;function Li(r,t){let s;if(Array.isArray(r))return Array.prototype.concat.call(r);if(r instanceof Set){if(!hs(r)){const e=Object.getPrototypeOf(r).constructor;return new e(r.values())}return Set.prototype.difference?Set.prototype.difference.call(r,new Set):new Set(r.values())}else if(r instanceof Map){if(!ls(r)){const e=Object.getPrototypeOf(r).constructor;return new e(r)}return new Map(r)}else if(t!=null&&t.mark&&(s=t.mark(r,Z),s!==void 0)&&s!==Z.mutable){if(s===Z.immutable)return Oi(r);if(typeof s=="function"){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return s()}throw new Error(`Unsupported mark result: ${s}`)}else if(typeof r=="object"&&Object.getPrototypeOf(r)===Object.prototype){const e={};return Object.keys(r).forEach(i=>{e[i]=r[i]}),Object.getOwnPropertySymbols(r).forEach(i=>{Di.call(r,i)&&(e[i]=r[i])}),e}else throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function K(r){r.copy||(r.copy=Li(r.original,r.options))}function _e(r){if(!ge(r))return St(r);if(Array.isArray(r))return r.map(_e);if(r instanceof Map){const s=Array.from(r.entries()).map(([e,i])=>[e,_e(i)]);if(!ls(r)){const e=Object.getPrototypeOf(r).constructor;return new e(s)}return new Map(s)}if(r instanceof Set){const s=Array.from(r).map(_e);if(!hs(r)){const e=Object.getPrototypeOf(r).constructor;return new e(s)}return new Set(s)}const t=Object.create(Object.getPrototypeOf(r));for(const s in r)t[s]=_e(r[s]);return t}function Ge(r){return At(r)?_e(r):r}function ie(r){var t;r.assignedMap=(t=r.assignedMap)!==null&&t!==void 0?t:new Map,r.operated||(r.operated=!0,r.parent&&ie(r.parent))}function Mi(r,t){const s=je(r);if(s===0)Reflect.ownKeys(r).forEach(e=>{t(e,r[e],r)});else if(s===1){let e=0;for(const i of r)t(e,i,r),e+=1}else r.forEach((e,i)=>t(i,e,r))}function ps(r,t,s){if(At(r)||!ge(r,s)||t.has(r)||Object.isFrozen(r))return;const e=r instanceof Set,i=e?new Map:void 0;if(t.add(r),Mi(r,(a,n)=>{var o;if(At(n)){const c=L(n);K(c);const h=!((o=c.assignedMap)===null||o===void 0)&&o.size||c.operated?c.copy:c.original;Et(e?i:r,a,h)}else ps(n,t,s)}),i){const a=r,n=Array.from(a);a.clear(),n.forEach(o=>{a.add(i.has(o)?i.get(o):o)})}}function Fi(r,t){const s=r.type===3?r.setMap:r.copy;r.finalities.revoke.length>1&&r.assignedMap.get(t)&&s&&ps(le(s,t),r.finalities.handledSet,r.options)}function Ct(r){r.type===3&&r.copy&&(r.copy.clear(),r.setMap.forEach(t=>{r.copy.add(St(t))}))}function Nt(r,t,s,e){if(r.operated&&r.assignedMap&&r.assignedMap.size>0&&!r.finalized){if(s&&e){const a=us(r);a&&t(r,a,s,e)}r.finalized=!0}}function kt(r,t,s,e){const i=L(s);i&&(i.callbacks||(i.callbacks=[]),i.callbacks.push((a,n)=>{var o;const c=r.type===3?r.setMap:r.copy;if(be(le(c,t),s)){let h=i.original;i.copy&&(h=i.copy),Ct(r),Nt(r,e,a,n),r.options.enableAutoFreeze&&(r.options.updatedValues=(o=r.options.updatedValues)!==null&&o!==void 0?o:new WeakMap,r.options.updatedValues.set(h,i.original)),Et(c,t,h)}}),r.options.enableAutoFreeze&&i.finalities!==r.finalities&&(r.options.enableAutoFreeze=!1)),ge(s,r.options)&&r.finalities.draft.push(()=>{const a=r.type===3?r.setMap:r.copy;be(le(a,t),s)&&Fi(r,t)})}function Bi(r,t,s,e,i){let{original:a,assignedMap:n,options:o}=r,c=r.copy;c.length<a.length&&([a,c]=[c,a],[s,e]=[e,s]);for(let h=0;h<a.length;h+=1)if(n.get(h.toString())&&c[h]!==a[h]){const l=t.concat([h]),u=we(l,i);s.push({op:N.Replace,path:u,value:Ge(c[h])}),e.push({op:N.Replace,path:u,value:Ge(a[h])})}for(let h=a.length;h<c.length;h+=1){const l=t.concat([h]),u=we(l,i);s.push({op:N.Add,path:u,value:Ge(c[h])})}if(a.length<c.length){const{arrayLengthAssignment:h=!0}=o.enablePatches;if(h){const l=t.concat(["length"]),u=we(l,i);e.push({op:N.Replace,path:u,value:a.length})}else for(let l=c.length;a.length<l;l-=1){const u=t.concat([l-1]),d=we(u,i);e.push({op:N.Remove,path:d})}}}function Ri({original:r,copy:t,assignedMap:s},e,i,a,n){s.forEach((o,c)=>{const h=le(r,c),l=Ge(le(t,c)),u=o?Re(r,c)?N.Replace:N.Add:N.Remove;if(be(h,l)&&u===N.Replace)return;const d=e.concat(c),f=we(d,n);i.push(u===N.Remove?{op:u,path:f}:{op:u,path:f,value:l}),a.push(u===N.Add?{op:N.Remove,path:f}:u===N.Remove?{op:N.Add,path:f,value:h}:{op:N.Replace,path:f,value:h})})}function ji({original:r,copy:t},s,e,i,a){let n=0;r.forEach(o=>{if(!t.has(o)){const c=s.concat([n]),h=we(c,a);e.push({op:N.Remove,path:h,value:o}),i.unshift({op:N.Add,path:h,value:o})}n+=1}),n=0,t.forEach(o=>{if(!r.has(o)){const c=s.concat([n]),h=we(c,a);e.push({op:N.Add,path:h,value:o}),i.unshift({op:N.Remove,path:h,value:o})}n+=1})}function Ue(r,t,s,e){const{pathAsArray:i=!0}=r.options.enablePatches;switch(r.type){case 0:case 2:return Ri(r,t,s,e,i);case 1:return Bi(r,t,s,e,i);case 3:return ji(r,t,s,e,i)}}const Ye=(r,t,s=!1)=>{if(typeof r=="object"&&r!==null&&(!ge(r,t)||s))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},vt={get size(){return G(L(this)).size},has(r){return G(L(this)).has(r)},set(r,t){const s=L(this),e=G(s);return(!e.has(r)||!be(e.get(r),t))&&(K(s),ie(s),s.assignedMap.set(r,!0),s.copy.set(r,t),kt(s,r,t,Ue)),this},delete(r){if(!this.has(r))return!1;const t=L(this);return K(t),ie(t),t.original.has(r)?t.assignedMap.set(r,!1):t.assignedMap.delete(r),t.copy.delete(r),!0},clear(){const r=L(this);if(this.size){K(r),ie(r),r.assignedMap=new Map;for(const[t]of r.original)r.assignedMap.set(t,!1);r.copy.clear()}},forEach(r,t){const s=L(this);G(s).forEach((e,i)=>{r.call(t,this.get(i),i,this)})},get(r){var t,s;const e=L(this),i=G(e).get(r),a=((s=(t=e.options).mark)===null||s===void 0?void 0:s.call(t,i,Z))===Z.mutable;if(e.options.strict&&Ye(i,e.options,a),a||e.finalized||!ge(i,e.options)||i!==e.original.get(r))return i;const n=Tt.createDraft({original:i,parentDraft:e,key:r,finalities:e.finalities,options:e.options});return K(e),e.copy.set(r,n),n},keys(){return G(L(this)).keys()},values(){const r=this.keys();return{[Xe]:()=>this.values(),next:()=>{const t=r.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){const r=this.keys();return{[Xe]:()=>this.entries(),next:()=>{const t=r.next();if(t.done)return t;const s=this.get(t.value);return{done:!1,value:[t.value,s]}}}},[Xe](){return this.entries()}},_i=Reflect.ownKeys(vt),fs=(r,t,{isValuesIterator:s})=>()=>{var e,i;const a=t.next();if(a.done)return a;const n=a.value;let o=r.setMap.get(n);const c=L(o),h=((i=(e=r.options).mark)===null||i===void 0?void 0:i.call(e,o,Z))===Z.mutable;if(r.options.strict&&Ye(n,r.options,h),!h&&!c&&ge(n,r.options)&&!r.finalized&&r.original.has(n)){const l=Tt.createDraft({original:n,parentDraft:r,key:n,finalities:r.finalities,options:r.options});r.setMap.set(n,l),o=l}else c&&(o=c.proxy);return{done:!1,value:s?o:[o,o]}},Qe={get size(){return L(this).setMap.size},has(r){const t=L(this);if(t.setMap.has(r))return!0;K(t);const s=L(r);return!!(s&&t.setMap.has(s.original))},add(r){const t=L(this);return this.has(r)||(K(t),ie(t),t.assignedMap.set(r,!0),t.setMap.set(r,r),kt(t,r,r,Ue)),this},delete(r){if(!this.has(r))return!1;const t=L(this);K(t),ie(t);const s=L(r);return s&&t.setMap.has(s.original)?(t.assignedMap.set(s.original,!1),t.setMap.delete(s.original)):(!s&&t.setMap.has(r)?t.assignedMap.set(r,!1):t.assignedMap.delete(r),t.setMap.delete(r))},clear(){if(!this.size)return;const r=L(this);K(r),ie(r);for(const t of r.original)r.assignedMap.set(t,!1);r.setMap.clear()},values(){const r=L(this);K(r);const t=r.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:fs(r,t,{isValuesIterator:!0})}},entries(){const r=L(this);K(r);const t=r.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:fs(r,t,{isValuesIterator:!1})}},keys(){return this.values()},[Xe](){return this.values()},forEach(r,t){const s=this.values();let e=s.next();for(;!e.done;)r.call(t,e.value,e.value,this),e=s.next()}};Set.prototype.difference&&Object.assign(Qe,{intersection(r){return Set.prototype.intersection.call(new Set(this.values()),r)},union(r){return Set.prototype.union.call(new Set(this.values()),r)},difference(r){return Set.prototype.difference.call(new Set(this.values()),r)},symmetricDifference(r){return Set.prototype.symmetricDifference.call(new Set(this.values()),r)},isSubsetOf(r){return Set.prototype.isSubsetOf.call(new Set(this.values()),r)},isSupersetOf(r){return Set.prototype.isSupersetOf.call(new Set(this.values()),r)},isDisjointFrom(r){return Set.prototype.isDisjointFrom.call(new Set(this.values()),r)}});const Ui=Reflect.ownKeys(Qe),ds=new WeakSet,ms={get(r,t,s){var e,i;const a=(e=r.copy)===null||e===void 0?void 0:e[t];if(a&&ds.has(a))return a;if(t===Be)return r;let n;if(r.options.mark){const h=t==="size"&&(r.original instanceof Map||r.original instanceof Set)?Reflect.get(r.original,t):Reflect.get(r.original,t,s);if(n=r.options.mark(h,Z),n===Z.mutable)return r.options.strict&&Ye(h,r.options,!0),h}const o=G(r);if(o instanceof Map&&_i.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(vt,"size").get.call(r.proxy);const h=vt[t];if(h)return h.bind(r.proxy)}if(o instanceof Set&&Ui.includes(t)){if(t==="size")return Object.getOwnPropertyDescriptor(Qe,"size").get.call(r.proxy);const h=Qe[t];if(h)return h.bind(r.proxy)}if(!Re(o,t)){const h=cs(o,t);return h?"value"in h?h.value:(i=h.get)===null||i===void 0?void 0:i.call(r.proxy):void 0}const c=o[t];if(r.options.strict&&Ye(c,r.options),r.finalized||!ge(c,r.options))return c;if(c===It(r.original,t)){if(K(r),r.copy[t]=ys({original:r.original[t],parentDraft:r,key:r.type===1?Number(t):t,finalities:r.finalities,options:r.options}),typeof n=="function"){const h=L(r.copy[t]);return K(h),ie(h),h.copy}return r.copy[t]}return c},set(r,t,s){var e;if(r.type===3||r.type===2)throw new Error("Map/Set draft does not support any property assignment.");let i;if(r.type===1&&t!=="length"&&!(Number.isInteger(i=Number(t))&&i>=0&&(t===0||i===0||String(i)===String(t))))throw new Error("Only supports setting array indices and the 'length' property.");const a=cs(G(r),t);if(a!=null&&a.set)return a.set.call(r.proxy,s),!0;const n=It(G(r),t),o=L(n);return o&&be(o.original,s)?(r.copy[t]=s,r.assignedMap=(e=r.assignedMap)!==null&&e!==void 0?e:new Map,r.assignedMap.set(t,!1),!0):(be(s,n)&&(s!==void 0||Re(r.original,t))||(K(r),ie(r),Re(r.original,t)&&be(s,r.original[t])?r.assignedMap.delete(t):r.assignedMap.set(t,!0),r.copy[t]=s,kt(r,t,s,Ue)),!0)},has(r,t){return t in G(r)},ownKeys(r){return Reflect.ownKeys(G(r))},getOwnPropertyDescriptor(r,t){const s=G(r),e=Reflect.getOwnPropertyDescriptor(s,t);return e&&{writable:!0,configurable:r.type!==1||t!=="length",enumerable:e.enumerable,value:s[t]}},getPrototypeOf(r){return Reflect.getPrototypeOf(r.original)},setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(r,t){var s;return r.type===1?ms.set.call(this,r,t,void 0,r.proxy):(It(r.original,t)!==void 0||t in r.original?(K(r),ie(r),r.assignedMap.set(t,!1)):(r.assignedMap=(s=r.assignedMap)!==null&&s!==void 0?s:new Map,r.assignedMap.delete(t)),r.copy&&delete r.copy[t],!0)}};function ys(r){const{original:t,parentDraft:s,key:e,finalities:i,options:a}=r,n=je(t),o={type:n,finalized:!1,parent:s,original:t,copy:null,proxy:null,finalities:i,options:a,setMap:n===3?new Map(t.entries()):void 0};(e||"key"in r)&&(o.key=e);const{proxy:c,revoke:h}=Proxy.revocable(n===1?Object.assign([],o):o,ms);if(i.revoke.push(h),ds.add(c),o.proxy=c,s){const l=s;l.finalities.draft.push((u,d)=>{var f,x;const S=L(c);let _=l.type===3?l.setMap:l.copy;const C=le(_,e),D=L(C);if(D){let U=D.original;D.operated&&(U=St(C)),Ct(D),Nt(D,Ue,u,d),l.options.enableAutoFreeze&&(l.options.updatedValues=(f=l.options.updatedValues)!==null&&f!==void 0?f:new WeakMap,l.options.updatedValues.set(U,D.original)),Et(_,e,U)}(x=S.callbacks)===null||x===void 0||x.forEach(U=>{U(u,d)})})}else{const l=L(c);l.finalities.draft.push((u,d)=>{Ct(l),Nt(l,Ue,u,d)})}return c}Tt.createDraft=ys,Object.prototype.constructor.toString();const z=[];for(let r=0;r<256;++r)z.push((r+256).toString(16).slice(1));function $i(r,t=0){return(z[r[t+0]]+z[r[t+1]]+z[r[t+2]]+z[r[t+3]]+"-"+z[r[t+4]]+z[r[t+5]]+"-"+z[r[t+6]]+z[r[t+7]]+"-"+z[r[t+8]]+z[r[t+9]]+"-"+z[r[t+10]]+z[r[t+11]]+z[r[t+12]]+z[r[t+13]]+z[r[t+14]]+z[r[t+15]]).toLowerCase()}let Ot;const qi=new Uint8Array(16);function zi(){if(!Ot){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ot=crypto.getRandomValues.bind(crypto)}return Ot(qi)}const xs={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Vi(r,t,s){var i;if(xs.randomUUID&&!r)return xs.randomUUID();r=r||{};const e=r.random??((i=r.rng)==null?void 0:i.call(r))??zi();if(e.length<16)throw new Error("Random bytes length must be >= 16");return e[6]=e[6]&15|64,e[8]=e[8]&63|128,$i(e)}function Ps(){return Vi()}function Hi(r,t){return r.localeCompare(t)}function Ki(){let r=Hi;if(typeof Intl=="object"&&Intl.hasOwnProperty("Collator"))try{r=Intl.Collator("en-US").compare}catch{}return r}Ki();function Ji(){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 Wi=Ji();function Ze(r,t,s){const e={__etype:r,__ops:s};return new Proxy(e,{get:(i,a)=>{if(a==="__ops")return s;if(a==="__etype")return r;if(Wi.has(a))return(n,o)=>Ze(r,t,[...s,o?[a,r,t,n,o]:[a,r,t,n]])}})}function Xi(r,t){return`lookup__${r}__${JSON.stringify(t)}`}function Gi(r){return r.startsWith("lookup__")}function gs(r){const[t,s,...e]=r.split("__");return[s,JSON.parse(e.join("__"))]}function Yi(r){return new Proxy({__etype:r},{get(t,s){if(s==="lookup")return(i,a)=>Ze(r,gs(Xi(i,a)),[]);if(s==="__etype")return r;const e=s;return Gi(e)?Ze(r,gs(e),[]):Ze(r,e,[])}})}function Qi(){return new Proxy({},{get(r,t){return Yi(t)}})}Qi();class Dt extends Error{constructor(s,e){super(s);m(this,"hint");this.hint=e;const i=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,i),Error.captureStackTrace&&Error.captureStackTrace(this,Dt),this.name="InstantError"}get[Symbol.toStringTag](){return"InstantError"}}class $e extends Dt{constructor(s){var a;const e=((a=s.body)==null?void 0:a.message)||`API Error (${s.status})`;super(e,s.body.hint);m(this,"body");m(this,"status");const i=new.target.prototype;Object.setPrototypeOf&&Object.setPrototypeOf(this,i),Error.captureStackTrace&&Error.captureStackTrace(this,$e),this.name="InstantAPIError",this.status=s.status,this.body=s.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 Ce="v0.22.141";class ee{constructor(t,s,e,i={indexed:!1,unique:!1}){m(this,"valueType");m(this,"required");m(this,"isIndexed");m(this,"config");m(this,"metadata",{});this.valueType=t,this.required=s,this.isIndexed=e,this.config=i}clientRequired(){return new ee(this.valueType,!1,this.isIndexed,this.config)}optional(){return new ee(this.valueType,!1,this.isIndexed,this.config)}unique(){return new ee(this.valueType,this.required,this.isIndexed,{...this.config,unique:!0})}indexed(){return new ee(this.valueType,this.required,!0,{...this.config,indexed:!0})}}class et{constructor(t,s){m(this,"attrs");m(this,"links");this.attrs=t,this.links=s}asType(){return new et(this.attrs,this.links)}}class tt{constructor(t,s,e){m(this,"entities");m(this,"links");m(this,"rooms");this.entities=t,this.links=s,this.rooms=e}withRoomSchema(){return new tt(this.entities,this.links,{})}}var bs;(function(r){r.InitialSyncBatch="InitialSyncBatch",r.InitialSyncComplete="InitialSyncComplete",r.LoadFromStorage="LoadFromStorage",r.SyncTransaction="SyncTransaction",r.Error="Error"})(bs||(bs={}));function Zi(r,t){return new tt(ws(r,t),t,void 0)}function er(r){return new et(r,{})}function tr(){return new ee("string",!0,!1)}function sr(){return new ee("number",!0,!1)}function ir(){return new ee("boolean",!0,!1)}function rr(){return new ee("date",!0,!1)}function ar(){return new ee("json",!0,!1)}function nr(){return new ee("json",!0,!1)}function ws(r,t){var i,a,n,o;const s={fwd:{},rev:{}};for(const c of Object.values(t))(i=s.fwd)[a=c.forward.on]||(i[a]={}),(n=s.rev)[o=c.reverse.on]||(n[o]={}),s.fwd[c.forward.on][c.forward.label]={entityName:c.reverse.on,cardinality:c.forward.has},s.rev[c.reverse.on][c.reverse.label]={entityName:c.forward.on,cardinality:c.reverse.has};return Object.fromEntries(Object.entries(r).map(([c,h])=>[c,new et(h.attrs,{...s.fwd[c],...s.rev[c]})]))}function or({entities:r,links:t,rooms:s}){const e=t??{},i=s??{};return new tt(ws(r,e),e,i)}const V={graph:Zi,schema:or,entity:er,string:tr,number:sr,boolean:ir,date:rr,json:ar,any:nr};function cr(){return globalThis.__instantDbSchemaHashStore=globalThis.__instantDbSchemaHashStore??new WeakMap,globalThis.__instantDbSchemaHashStore}function hr(){return globalThis.__instantDbStore=globalThis.__instantDbStore??{},globalThis.__instantDbStore}hr(),cr();function lr(){const r="0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-._~";let t="";for(const s of crypto.getRandomValues(new Uint8Array(64)))t=t+r[s%r.length];return t}function ur(r){return crypto.subtle.digest({name:"SHA-256"},new TextEncoder().encode(r))}function pr(r){return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function fr(r){return ur(r).then(t=>pr(btoa(String.fromCharCode(...Array.from(new Uint8Array(t))))))}function dr(){const r=Math.min(800,Math.floor(window.outerWidth*.8)),t=Math.min(630,Math.floor(window.outerHeight*.5)),s={width:r,height:t,left:Math.round(window.screenX+(window.outerWidth-r)/2),top:Math.round(window.screenY+(window.outerHeight-t)/8)},e={width:s.width,height:s.height,left:s.left,top:s.top,toolbar:0,scrollbars:1,status:1,resizable:1,menuBar:0,rel:"opener"};return Object.keys(e).map(i=>`${i}=${e[i]}`).join(",")}let Ts=null;function mr({clientId:r,state:t,codeChallenge:s,apiURI:e,redirectUri:i,scopes:a}){const n=new URL(`${e}/platform/oauth/start`);return n.searchParams.set("client_id",r),n.searchParams.set("redirect_uri",i),n.searchParams.set("scope",a.join(" ")),n.searchParams.set("state",t),n.searchParams.set("response_type","code"),n.searchParams.set("code_challenge",s),n.searchParams.set("code_challenge_method","S256"),n.toString()}async function yr({code:r,clientId:t,verifier:s,apiURI:e,redirectUri:i}){const a=await fetch(`${e}/platform/oauth/token`,{method:"POST",headers:{"Content-type":"application/json","Instant-Platform-Version":Ce,"Instant-Core-Version":Ce},body:JSON.stringify({grant_type:"authorization_code",code:r,redirect_uri:i,client_id:t,code_verifier:s})});if(!a.ok){const o=await a.text();let c;try{const h=JSON.parse(o);c={error:h.error,errorDescription:h.error_description,message:`OAuth error: ${h.error||"server_error"}`}}catch{c={error:"server_error",message:"OAuth error: server_error"}}throw new v(c)}const n=await a.json();return{token:n.access_token,expiresAt:new Date(Date.now()+(n.expires_in-30)*1e3)}}function xr(){if(typeof window>"u")throw new Error("This function may only be used in a browser context.");const r=new URL(window.location.href).searchParams,t=r.get("state"),s=r.get("error"),e=r.get("error_description"),i=r.get("code");if(!t)throw new Error("Invalid redirect. The state param is missing.");const a=new BroadcastChannel(t);return a.addEventListener("message",n=>{n.data.type==="oauth-redirect-window-done"&&window.close()}),a.postMessage({type:"oauth-redirect",state:t,error:s,errorDescription:e,code:i}),()=>{a.close()}}function Pr({clientId:r,apiURI:t,redirectUri:s,scopes:e}){if(typeof window>"u")throw new Error("OAuth flow can only be started on the client.");const i=Ts;i&&i.close();const a=crypto.randomUUID(),n=lr(),o=new BroadcastChannel(a),c=new Promise((l,u)=>{o.addEventListener("message",async d=>{if(d.data.type!=="oauth-redirect")return;const{state:f,error:x,code:S,errorDescription:_}=d.data;if(!(!f||f!==a)){if(S)try{const C=await yr({clientId:r,code:S,verifier:n,apiURI:t,redirectUri:s});l(C)}catch(C){C instanceof v&&u(C),u(new v({error:"server_error",message:"OAuth error exchanging code for token"}))}else u(typeof x=="string"?new v({error:x,errorDescription:_,message:`OAuth error: ${x}`}):new v({error:"server_error",message:"OAuth error: server_error"}));o.postMessage({type:"oauth-redirect-window-done"})}})}),h=window.open("",`instantdb_oauth_${Math.random()}`.replace(".",""),dr());return h?(Ts=h,fr(n).then(l=>{const u=mr({clientId:r,state:a,codeChallenge:l,apiURI:t,redirectUri:s,scopes:e});h.location.href=u}),c.finally(()=>o.close())):Promise.reject({error:"Could not open Auth window"})}class gr{constructor(t){m(this,"redirectUri");m(this,"clientId");m(this,"apiURI");this.redirectUri=t.redirectUri,this.apiURI=t.apiURI??"https://api.instantdb.com",this.clientId=t.clientId}startClientOnlyFlow(t){return Pr({clientId:this.clientId,apiURI:this.apiURI,redirectUri:this.redirectUri,scopes:t})}handleClientRedirect(){return xr()}}function br(r,t){const s=r&&Object.keys(r).length?JSON.stringify(r,null,2):`{
2
2
  /**
3
3
  * Welcome to Instant's permission system!
4
4
  * Right now your rules are empty. To start filling them in, check out the docs:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instantdb/platform",
3
- "version": "0.22.140",
3
+ "version": "0.22.141",
4
4
  "description": "Instant's platform package for managing Instant apps.",
5
5
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/platform",
6
6
  "repository": {
@@ -54,8 +54,8 @@
54
54
  "dependencies": {
55
55
  "@babel/parser": "^8.0.0-beta.0",
56
56
  "@babel/types": "^8.0.0-beta.0",
57
- "@instantdb/core": "0.22.140",
58
- "@instantdb/version": "0.22.140"
57
+ "@instantdb/core": "0.22.141",
58
+ "@instantdb/version": "0.22.141"
59
59
  },
60
60
  "scripts": {
61
61
  "test": "vitest",