iterate.com / ui

git clone https://git.iterate.com/repos/ui

Release of @iterate-com/ui from c35a49357c06026b8cf833dd25635a336a615ab6

Workspace: b57e184844d40fd1df428c55d9da4291f110dc1b
Modules: 189, imports named by export: 529
Via: apps/ui/build-release.mjs of /repos/config

ui release builder, 2026-11-26 23:29 UTC · 8f2e890b3164ff7b9373b349285674d8735ff4a0 · parent 87fc8a8

3 files changed

M dist/chunks/context-catalog-live.mjs
@@ -1,1 +1,1 @@
-import{r as e}from"./rolldown-runtime.mjs";import{a as t}from"./vendor-react";import{itxSessionOf as n}from"../lib/itx-session";import{a as r,d as i,f as a,h as o,i as s,l as c,r as l,s as u,u as d,v as f}from"./vendor-zod";import{Pt as p,St as m,b as h,gn as g,s as _}from"./vendor-db";import{C as v,n as y}from"./context-catalog-rows.mjs";import{r as b}from"./context-catalog-list.mjs";var x=/* @__PURE__ */ e(t(),1);const S=y.omit({awake:!0,activities:!0}).extend({activeMs:i(),createdMs:i(),rev:i()}),C=d({path:o(),since:i(),activities:l(v).optional()}),w=u(a({gen:o(),rev:i(),more:c(!0).optional()}),r(`type`,[a({type:c(`reset`),q:o(),full:s(),rows:l(f())}),a({type:c(`resume`),q:o(),full:s(),ids:l(o()),rows:l(f())}),a({type:c(`change`),from:i(),del:l(o()),rows:l(f())})]));function T(e,t){if(e===t)return 0;let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e.charCodeAt(r),i=t.charCodeAt(r);if(n===i)continue;let a=n>=55296&&n<=57343;return a===(i>=55296&&i<=57343)?n<i?-1:1:a?1:-1}return e.length<t.length?-1:1}function E(e,t){return t===`path`?[0,e.path]:[(t===`created`?e.createdMs:e.activeMs)??0,e.path]}function D(e,t,n=`active`){if(n===`path`)return T(e.path,t.path);let[r]=E(e,n),[i]=E(t,n);return r===i?-T(e.path,t.path):i-r}const O=a({code:o()}),k=e=>e.keys?`keys`:e.awake?`awake`:`window`;function A(e){let t=n(e),r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set,o=`asking`,s=()=>Math.max(t.get().epoch,1),c=1,l=e=>{if(o!==e){o=e;for(let e of a)e()}};function u(e){if(!e.gen||!e.q)return;let t=k(e.query);if(t===`awake`)return;let n={gen:e.gen,rev:e.rev,q:e.q};if(t===`keys`)return{...n,have:[...e.rows.keys()]};let r=e.query.order||`active`,i=[...e.rows.values()].toSorted((e,t)=>D(e,t,r)).at(-1);return{...n,bound:i?E(i,r):null}}function d(e,t){e.error=t,f(e),e.rejectReady(Error(t)),e.onChange({del:[],put:[],error:t})}function f(e){let t=e.handle;e.start=void 0,e.handle=void 0,Promise.resolve(t).then(e=>e?.[Symbol.dispose](),()=>{})}function p(n){f(n);let r={};n.start=r;let i=s(),a=u(n),o;try{o=e.contexts.watch(n.query,e=>{h(n,r,e)},a?{cursor:a}:void 0)}catch(e){o=Promise.reject(e)}n.handle=o,Promise.resolve(o).then(void 0,e=>{n.start===r&&s()===i&&t.get().state===`open`&&(O.safeParse(e).data?.code!==`INVALID_INPUT`&&l(`none`),d(n,e instanceof Error?e.message:String(e)))}),Promise.resolve(o).then(e=>e.ended?e.ended():new Promise(()=>{})).then(()=>{n.start===r&&t.get().state===`open`&&m(n,`the catalog ended the watch three times in half a minute`)},()=>{})}function m(e,t){let n=Date.now();if(n-e.restartedAt>3e4&&(e.restarts=0,e.restartedAt=n),e.restarts>=2){l(`none`),d(e,t);return}e.restarts+=1,p(e)}function h(e,t,n){let r=w.safeParse(n);if(e.start===t&&(r.success?g(e,r.data):(l(`none`),d(e,`the catalog sent a frame that this page cannot read`))),!r.success||!r.data.more)for(let e of i)e()}function g(e,t){o===`asking`&&l(`live`);let n=t.rows.flatMap(t=>{let n=e.row.safeParse(t);return n.success?[n.data]:[]});if(t.type===`change`){if(e.gen!==t.gen||e.rev!==t.from){m(e,`the catalog's changes came with a gap three times in half a minute`);return}for(let n of t.del)e.rows.delete(n);for(let t of n)e.rows.set(t.path,t);e.rev=t.rev,e.frames+=1,e.onChange({del:t.del,put:n});return}let r=new Set(t.type===`reset`?n.map(e=>e.path):t.ids),i=[...e.rows.keys()].filter(e=>!r.has(e));for(let t of i)e.rows.delete(t);for(let t of n)e.rows.set(t.path,t);e.gen=t.gen,e.rev=t.rev,e.q=t.q,e.full=t.full,e.error=void 0,e.answers+=1,e.onChange({del:i,put:n,answer:!0}),e.resolveReady()}let _,v=()=>{c=s(),_||=t.subscribe(()=>{let e=s();if(e!==c){c=e;for(let e of r)e.error||p(e)}})},y=()=>{r.size>0||(_?.(),_=void 0)};return{watch(e,t,n,i){let a=Promise.withResolvers();a.promise.catch(()=>{});let o={query:e,row:t,onChange:n,rows:/* @__PURE__ */ new Map,gen:void 0,rev:-1,q:void 0,full:!1,answers:0,frames:0,restarts:0,restartedAt:0,error:void 0,start:void 0,handle:void 0,ready:a.promise,resolveReady:a.resolve,rejectReady:a.reject,stop(){r.delete(s)&&(f(s),y())}},s=o,c=i;return c?.gen&&k(c.query)===k(e)&&(o.rows=new Map(c.rows),o.gen=c.gen,o.rev=c.rev??-1,o.q=c.q),r.add(s),v(),p(s),o},onBatch(e){return i.add(e),()=>i.delete(e)},support:()=>o,subscribe(e){return a.add(e),()=>a.delete(e)},close(){for(let e of r)f(e);r.clear(),y()}}}function j(e){let t=[`/`],n=``;for(let r of e.path.split(`/`).filter(Boolean))t.push(n+=`/${r}`);let r=e.path.lastIndexOf(`/`),i=e.path===`/`?``:r<=0?`/`:e.path.slice(0,r);return{...e,parent:i,under:t}}const M=(e,...t)=>e?.type===`ref`&&e.path.length===t.length&&e.path.every((e,n)=>e===t[n]),N=e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`,P=e=>e.type===`ref`&&e.path.length===2&&e.path[0]===`metadata`?e.path[1]:void 0,F={activeMs:`active`,createdMs:`created`,path:`path`};function I(e){if(e.type!==`func`)return;let[t,n]=e.args;if(!t||!n)return;if(e.name===`eq`){let[e,r]=t.type===`ref`?[t,n]:[n,t];if(e.type!==`ref`||r.type!==`val`)return;let i=r.value;if(!N(i))return;if(M(e,`path`))return typeof i==`string`?{keys:[i]}:void 0;if(M(e,`activeMs`)||M(e,`createdMs`))return{tie:!0};if(M(e,`parent`))return typeof i==`string`?{childrenOf:i}:void 0;let a=P(e);return a?{fact:[a,i]}:void 0}if(e.name!==`in`)return;if(M(t,`path`)&&n.type===`val`){let e=l(o()).safeParse(n.value);return e.success?{keys:e.data}:void 0}if(t.type!==`val`||n.type!==`ref`)return;let r=t.value;if(!N(r))return;if(M(n,`under`))return typeof r==`string`?{under:r}:void 0;if(M(n,`processors`))return{fact:[`$processor`,r]};let i=P(n);return i?{fact:[i,r]}:void 0}const L=e=>e?e.type===`func`&&e.name===`and`?e.args.flatMap(L):[e]:[];function R(e){let[t,n,...r]=e||[];if(!t||r.length>0||t.expression.type!==`ref`)return;let[i,...a]=t.expression.path;if(a.length>0||!i||!Object.hasOwn(F,i))return;let o=F[i],s=o===`path`?`asc`:`desc`;if(t.compareOptions.direction===s&&(!n||o!==`path`&&M(n.expression,`path`))&&!(n&&n.compareOptions.direction!==s))return o}const z=500;function B(e){let t=[],n={},r,i=0;for(let a of L(e.where)){let e=I(a);if(!e)i+=1;else if(`tie`in e)return{nothing:!0};else if(`keys`in e){let t=new Set(e.keys);r=r?r.filter(e=>t.has(e)):e.keys}else`fact`in e?t.push(e.fact):`under`in e&&!n.under?n.under=e.under:`childrenOf`in e&&!n.childrenOf?n.childrenOf=e.childrenOf:i+=1}if(r)return r.length>0?{keys:[...new Set(r)]}:{nothing:!0};let a=t.toSorted(([e],[t])=>T(e,t)),o={...a.length>0&&{where:Object.fromEntries(a)},...n};if(e.limit===void 0)return{query:{...o,limit:500},unlimited:!0};if(i>0)throw Error(`the catalog has no index for a condition of this query, and a limit over a guessed set gives wrong rows: use facts (eq(c.metadata.x, value)), or drop the limit`);let s=R(e.orderBy);if(!s)throw Error(`the catalog keeps three orders: a query with a limit says orderBy(c.activeMs, "desc"), orderBy(c.createdMs, "desc") or orderBy(c.path, "asc")`);if(e.limit>500)throw Error(`the catalog's largest window is 500 rows`);let c={...o,order:s,limit:e.limit};return e.cursor||e.offset?{query:c,unlimited:!1,after:!0}:{query:c,unlimited:!1}}function V({watcher:e,id:t,index:n}){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a={watch:void 0,settled:Promise.resolve(),scheduled:!1},o=/* @__PURE__ */ new Map,s=()=>[...[...r.values()].map(e=>e.watch),a.watch].flatMap(e=>e?[{query:e.query,rows:e.rows.size,full:e.full,frames:e.frames}]:[]);return{id:t,...n,getKey:e=>e.path,syncMode:`on-demand`,utils:{demands:s},sync:{rowUpdateMode:`full`,sync:({begin:t,write:n,commit:s,markReady:c,collection:l})=>{let u=!1,d=!0,f=/* @__PURE__ */ new Map,p=()=>{u||t(),u=!0},m=()=>{u&&(u=!1,f.clear(),d=s())},h=e.onBatch(m),g=e=>f.has(e)?f.get(e):l.get(e)?.rev??!1,_=(e,t)=>{let r=o.get(t.path)??/* @__PURE__ */ new Set;o.set(t.path,r),r.add(e);let i=g(t.path);if(i===t.rev)return;p();let a=j(t);n(i===!1?{type:`insert`,value:a}:{type:`update`,value:a}),f.set(t.path,t.rev)},v=(e,t)=>{let r=o.get(t);r?.delete(e),!r?.size&&(o.delete(t),g(t)!==!1&&(p(),n({type:`delete`,key:t}),f.set(t,!1)))},y=(e,t,n)=>{if(n.error)return;for(let t of n.del)v(e,t);let r=n.answer?t()?.rows.values()??n.put:n.put;for(let t of r)_(e,t)},b=(e,t)=>{t?.stop();for(let n of t?.rows.keys()??[])v(e,n)},x=async()=>{a.scheduled=!1;let t=[...i.keys()].toSorted(T),n=a.watch;if(t.length===0){a.watch=void 0,b(a,n),m();return}if(JSON.stringify(n?.query.keys)===JSON.stringify(t))return n?.ready;let r=e.watch({keys:t},S,e=>{y(a,()=>r,e)},n);a.watch=r,n?.stop(),await r.ready},C=(e,t)=>{for(let n of e){let e=(i.get(n)??0)+t;e>0?i.set(n,e):i.delete(n)}return a.scheduled?a.settled:(a.scheduled=!0,a.settled=Promise.resolve().then(x),a.settled.catch(()=>{}),a.settled)},w=async()=>{d!==!0&&await d};return c(),{loadSubset:t=>{let n=B(t);if(`nothing`in n)return!0;if(`keys`in n)return C(n.keys,1).then(w);let i=JSON.stringify(n.query),{limit:a,...o}=n.query,s=JSON.stringify(o),c=[...r.values()].find(({watch:e})=>{let{limit:t,...n}=e.query;return JSON.stringify(n)===s})?.watch;if(n.after){if(c&&c.answers>0)return!0;throw Error(`the catalog serves a window from its start: ask for a larger limit`)}let l=r.get(i);if(!l){let t={holds:0,unlimited:n.unlimited,watch:e.watch(n.query,S,e=>{y(t,()=>t.watch,e)},c)};l=t,r.set(i,l)}l.holds+=1;let{watch:u,unlimited:f}=l,p=()=>{if(f&&u.full)throw Error(`more than ${String(u.rows.size)} rows match and the query has no limit: say an order and a limit`)};return u.answers>0&&d===!0?(p(),!0):u.ready.then(p).then(w)},unloadSubset:e=>{let t;try{t=B(e)}catch{return}if(`nothing`in t)return;if(`keys`in t)return void C(t.keys,-1);if(t.after)return;let n=JSON.stringify(t.query),i=r.get(n);i&&(--i.holds,!(i.holds>0)&&(r.delete(n),b(i,i.watch),m()))},cleanup:()=>{h();for(let e of r.values())e.watch.stop();a.watch?.stop(),a.watch=void 0,r.clear(),i.clear(),o.clear()}}}}}}function H({watcher:e,id:t,query:n,row:r,index:i}){return{id:t,...i,getKey:e=>e.path,sync:{rowUpdateMode:`full`,sync:({begin:t,write:i,commit:a,markReady:o,fail:s,collection:c})=>{let l=!1,u=e.onBatch(()=>{l&&(l=!1,a(),o())}),d=e.watch(n,r,({del:e,put:n,error:r})=>{if(r){s(Error(r));return}l||t(),l=!0;for(let t of e)c.has(t)&&i({type:`delete`,key:t});for(let e of n)i({type:c.has(e.path)?`update`:`insert`,value:e})});return()=>{u(),d.stop()}}}}}const U={defaultIndexType:h,autoIndex:`eager`};function W(e){let t=A(e),n=p(V({watcher:t,index:U})),r=p(H({watcher:t,query:{awake:!0},row:C,index:U})),i=m(e=>e.from({context:n}).orderBy(({context:e})=>e.activeMs,`desc`).limit(500));return{watcher:t,contexts:n,awake:r,listings:m(e=>e.from({context:i}).join({awake:r},({context:e,awake:t})=>g(e.path,t.path),`left`))}}const G=/* @__PURE__ */ new WeakMap;function K(e){let t=G.get(e)??W(e);return G.set(e,t),t}function q(e,t,{of:n,pollMs:r}){let i=K(e),a=(0,x.useSyncExternalStore)(i.watcher.subscribe,i.watcher.support,i.watcher.support);(0,x.useEffect)(()=>{if(a!==`asking`)return;let e=i.watcher.watch({awake:!0},C,()=>{});return()=>{e.stop()}},[i,a]);let o=b(a===`none`?t:null,{of:n,pollMs:r}),s=_({query:e=>a===`live`?e.from({listing:i.listings}):void 0}),c=s.isReady?s.data:void 0,l=(0,x.useMemo)(()=>c?.map(({context:e,awake:t})=>({...e,...t&&{awake:{since:t.since}},...t?.activities&&{activities:t.activities}})).toSorted((e,t)=>D(e,t)),[c]);return a===`none`?o:{rows:l,error:s.isLoadingError?`The mind did not answer the catalog's query.`:void 0}}export{S as a,D as c,V as d,H as f,C as i,T as l,q as n,B as o,z as r,A as s,K as t,j as u};
+import{r as e}from"./rolldown-runtime.mjs";import{a as t}from"./vendor-react";import{itxSessionOf as n}from"../lib/itx-session";import{a as r,d as i,f as a,h as o,i as s,l as c,r as l,s as u,u as d,v as f}from"./vendor-zod";import{Pt as p,St as m,b as h,gn as g,s as _}from"./vendor-db";import{C as v,n as y}from"./context-catalog-rows.mjs";import{r as b}from"./context-catalog-list.mjs";var x=/* @__PURE__ */ e(t(),1);const S=y.omit({awake:!0,activities:!0}).extend({activeMs:i(),createdMs:i(),rev:i()}),C=d({path:o(),since:i(),activities:l(v).optional()}),w=u(a({gen:o(),rev:i(),more:c(!0).optional()}),r(`type`,[a({type:c(`reset`),q:o(),full:s(),rows:l(f())}),a({type:c(`resume`),q:o(),full:s(),ids:l(o()),rows:l(f())}),a({type:c(`change`),from:i(),del:l(o()),rows:l(f())})]));function T(e,t){if(e===t)return 0;let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e.charCodeAt(r),i=t.charCodeAt(r);if(n===i)continue;let a=n>=55296&&n<=57343;return a===(i>=55296&&i<=57343)?n<i?-1:1:a?1:-1}return e.length<t.length?-1:1}function E(e,t){return t===`path`?[0,e.path]:[(t===`created`?e.createdMs:e.activeMs)??0,e.path]}function D(e,t,n=`active`){if(n===`path`)return T(e.path,t.path);let[r]=E(e,n),[i]=E(t,n);return r===i?-T(e.path,t.path):i-r}const O=a({code:o()}),k=e=>e.keys?`keys`:e.awake?`awake`:`window`;function A(e){let t=n(e),r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=`asking`,l=()=>Math.max(t.get().epoch,1),u=1,d=e=>{if(c!==e){c=e;for(let e of s)e()}};function f(e){if(!e.gen||!e.q)return;let t=k(e.query);if(t===`awake`)return;let n={gen:e.gen,rev:e.rev,q:e.q};if(t===`keys`)return{...n,have:[...e.rows.keys()]};let r=e.query.order||`active`,i=[...e.rows.values()].toSorted((e,t)=>D(e,t,r)).at(-1);return{...n,bound:i?E(i,r):null}}let p,m=()=>{clearTimeout(p),p=void 0;for(let e of i)e()};function h(e,t){e.error=t,g(e),e.rejectReady(Error(t)),e.onChange({del:[],put:[],error:t})}function g(e){let t=e.handle;e.start=void 0,e.handle=void 0,Promise.resolve(t).then(e=>e?.[Symbol.dispose](),()=>{})}function _(n){g(n);let r={};n.start=r;let i=l(),a=f(n),o;try{o=e.contexts.watch(n.query,e=>{b(n,r,e)},a?{cursor:a}:void 0)}catch(e){o=Promise.reject(e)}n.handle=o,Promise.resolve(o).then(void 0,e=>{if(n.start!==r||l()!==i||t.get().state!==`open`)return;let a=O.safeParse(e).data?.code;a!==`INVALID_INPUT`&&a!==`WATCH_LIMIT`&&d(`none`),h(n,e instanceof Error?e.message:String(e))}),Promise.resolve(o).then(e=>e.ended?e.ended():new Promise(()=>{})).then(()=>{n.start===r&&t.get().state===`open`&&y(n,`the catalog ended the watch three times in half a minute`)},()=>{})}let v=e=>k(e.query)===`window`&&e.rows.size>=(e.query.limit||50);function y(e,t){let n=Date.now();if(n-e.restartedAt>3e4&&(e.restarts=0,e.restartedAt=n),e.restarts>=2){d(`none`),h(e,t);return}e.restarts+=1,_(e)}function b(e,t,n){let r=w.safeParse(n);e.start===t&&(r.success?x(e,r.data):(d(`none`),h(e,`the catalog sent a frame that this page cannot read`))),r.success&&r.data.more?(clearTimeout(p),p=setTimeout(m,50)):m()}function x(e,t){c===`asking`&&d(`live`);let n=t.rows.flatMap(t=>{let n=e.row.safeParse(t);return n.success?[n.data]:[]});if(t.type===`change`){if(e.gen!==t.gen||e.rev!==t.from){y(e,`the catalog's changes came with a gap three times in half a minute`);return}for(let n of t.del)e.rows.delete(n);for(let t of n)e.rows.set(t.path,t);e.rev=t.rev,e.frames+=1,e.full=v(e),e.onChange({del:t.del,put:n});return}let r=new Set(t.type===`reset`?n.map(e=>e.path):t.ids),i=[...e.rows.keys()].filter(e=>!r.has(e));for(let t of i)e.rows.delete(t);for(let t of n)e.rows.set(t.path,t);e.gen=t.gen,e.rev=t.rev,e.q=t.q,e.full=t.full,e.error=void 0,e.answers+=1,e.onChange({del:i,put:n,answer:!0,...t.type===`reset`&&{whole:!0}}),e.resolveReady()}let S=!1,C,T=()=>{u=l(),C||=t.subscribe(()=>{let e=l();if(e!==u){u=e;for(let e of r)e.error||_(e)}})},A=()=>{r.size>0||(C?.(),C=void 0)};return{watch(e,t,n,i){let a=Promise.withResolvers();a.promise.catch(()=>{});let o={query:e,row:t,onChange:n,rows:/* @__PURE__ */ new Map,gen:void 0,rev:-1,q:void 0,full:!1,answers:0,frames:0,restarts:0,restartedAt:0,error:void 0,start:void 0,handle:void 0,ready:a.promise,resolveReady:a.resolve,rejectReady:a.reject,stop(){r.delete(s)&&(g(s),a.reject(/* @__PURE__ */ Error(`the watch was stopped`)),A())}},s=o,c=i;return c?.gen&&k(c.query)===k(e)&&(o.rows=new Map(c.rows),o.gen=c.gen,o.rev=c.rev??-1,o.q=c.q),r.add(s),T(),_(s),o},onBatch(e){return i.add(e),()=>i.delete(e)},batchOpen:()=>!!p,support:()=>c,probe(){if(S)return;S=!0;let e=this.watch({awake:!0},a({path:o()}),()=>{});e.ready.then(()=>{d(`live`)},()=>{d(`none`)}).finally(()=>{S=!1,e.stop()})},subscribe(e){return s.add(e),()=>s.delete(e)},close(){for(let e of r)g(e);r.clear(),A()}}}function j(e){let t=[`/`],n=``;for(let r of e.path.split(`/`).filter(Boolean))t.push(n+=`/${r}`);let r=e.path.lastIndexOf(`/`),i=e.path===`/`?``:r<=0?`/`:e.path.slice(0,r);return{...e,parent:i,under:t}}const M=(e,...t)=>e?.type===`ref`&&e.path.length===t.length&&e.path.every((e,n)=>e===t[n]),N=e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`,P=e=>e.type===`ref`&&e.path.length===2&&e.path[0]===`metadata`?e.path[1]:void 0,F={activeMs:`active`,createdMs:`created`,path:`path`};function I(e){if(e.type!==`func`)return;let[t,n]=e.args;if(!t||!n)return;if(e.name===`eq`){let[e,r]=t.type===`ref`?[t,n]:[n,t];if(e.type!==`ref`||r.type!==`val`)return;let i=r.value;if(!N(i))return;if(M(e,`path`))return typeof i==`string`?{keys:[i]}:void 0;if(M(e,`activeMs`)||M(e,`createdMs`))return{tie:!0};if(M(e,`parent`))return typeof i==`string`?{childrenOf:i}:void 0;let a=P(e);return a?{fact:[a,i]}:void 0}if(e.name!==`in`)return;if(M(t,`path`)&&n.type===`val`){let e=l(o()).safeParse(n.value);return e.success?{keys:e.data}:void 0}if(t.type!==`val`||n.type!==`ref`)return;let r=t.value;if(!N(r))return;if(M(n,`under`))return typeof r==`string`?{under:r}:void 0;if(M(n,`processors`))return{fact:[`$processor`,r]};let i=P(n);return i?{fact:[i,r]}:void 0}const L=e=>e?e.type===`func`&&e.name===`and`?e.args.flatMap(L):[e]:[];function R(e){let[t,n,...r]=e||[];if(!t||r.length>0||t.expression.type!==`ref`)return;let[i,...a]=t.expression.path;if(a.length>0||!i||!Object.hasOwn(F,i))return;let o=F[i],s=o===`path`?`asc`:`desc`;if(t.compareOptions.direction===s&&(!n||o!==`path`&&M(n.expression,`path`))&&!(n&&n.compareOptions.direction!==s))return o}const z=500;function B(e){let t=[],n={},r,i=0;for(let a of L(e.where)){let e=I(a);if(!e)i+=1;else if(`tie`in e)return{nothing:!0};else if(`keys`in e){let t=new Set(e.keys);r=r?r.filter(e=>t.has(e)):e.keys}else`fact`in e?t.push(e.fact):`under`in e&&!n.under?n.under=e.under:`childrenOf`in e&&!n.childrenOf?n.childrenOf=e.childrenOf:i+=1}if(r)return r.length>0?{keys:[...new Set(r)]}:{nothing:!0};let a=t.toSorted(([e],[t])=>T(e,t)),o={...a.length>0&&{where:Object.fromEntries(a)},...n};if(e.limit===void 0)return{query:{...o,limit:500},unlimited:!0};if(i>0)throw Error(`the catalog has no index for a condition of this query, and a limit over a guessed set gives wrong rows: use facts (eq(c.metadata.x, value)), or drop the limit`);let s=R(e.orderBy);if(!s)throw Error(`the catalog keeps three orders: a query with a limit says orderBy(c.activeMs, "desc"), orderBy(c.createdMs, "desc") or orderBy(c.path, "asc")`);if(e.limit>500)throw Error(`the catalog's largest window is 500 rows`);let c={...o,order:s,limit:e.limit};return e.cursor||e.offset?{query:c,unlimited:!1,after:!0}:{query:c,unlimited:!1}}function V({watcher:e,id:t,index:n}){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a={watch:void 0,settled:Promise.resolve(),scheduled:!1},o=/* @__PURE__ */ new Map,s=()=>[...[...r.values()].map(e=>e.watch),a.watch].flatMap(e=>e?[{query:e.query,rows:e.rows.size,full:e.full,frames:e.frames}]:[]);return{id:t,...n,getKey:e=>e.path,syncMode:`on-demand`,utils:{demands:s},sync:{rowUpdateMode:`full`,sync:({begin:t,write:n,commit:s,markReady:c,reportError:l,reportHealthy:u,collection:d})=>{let f=!1,p=!0,m=/* @__PURE__ */ new Map,h=()=>{f||t(),f=!0},g=()=>{f&&(f=!1,m.clear(),p=s())},_=e.onBatch(g),v=e=>m.has(e)?m.get(e):d.get(e)?.rev??!1,y=(e,t,r)=>{let i=o.get(t.path)??/* @__PURE__ */ new Set;o.set(t.path,i),i.add(e);let a=v(t.path);if(a===t.rev&&!r)return;h();let s=j(t);n(a===!1?{type:`insert`,value:s}:{type:`update`,value:s}),m.set(t.path,t.rev)},b=(e,t)=>{let r=o.get(t);r?.delete(e),!r?.size&&(o.delete(t),v(t)!==!1&&(h(),n({type:`delete`,key:t}),m.set(t,!1)))},x=(e,t,n)=>{if(n.error)return;for(let t of n.del)b(e,t);let r=n.answer?t()?.rows.values()??n.put:n.put;for(let t of r)y(e,t,!!n.whole)},C=/* @__PURE__ */ new Map,w=e=>{if(!e.unlimited)return;let t=C.get(e);if(e.watch.full&&!t){let t=/* @__PURE__ */ Error(`more than ${String(e.watch.rows.size-1)} rows match a query with no limit, and the catalog holds ${String(e.watch.rows.size)}: say an order and a limit`);C.set(e,t),l(t)}else!e.watch.full&&t&&(C.delete(e),u(t))},E=(e,t)=>{t?.stop();for(let n of t?.rows.keys()??[])b(e,n)},D=async()=>{a.scheduled=!1;let t=[...i.keys()].toSorted(T),n=a.watch;if(t.length===0){a.watch=void 0,E(a,n),e.batchOpen()||g();return}if(JSON.stringify(n?.query.keys)===JSON.stringify(t))return;if(t.length>500)throw Error(`the joins of this page ask for ${String(t.length)} contexts by path, and the catalog watches 500 at most: join fewer rows`);let r=e.watch({keys:t},S,e=>{x(a,()=>r,e)},n);a.watch=r,n?.stop()},O=async()=>{let e=a.watch;if(e){try{await e.ready}catch(t){if(a.watch===e)throw t}if(a.watch!==e)return O()}},k=(e,t)=>{for(let n of e){let e=(i.get(n)??0)+t;e>0?i.set(n,e):i.delete(n)}return a.scheduled?a.settled:(a.scheduled=!0,a.settled=Promise.resolve().then(D).then(O),a.settled.catch(()=>{}),a.settled)},A=async()=>{p!==!0&&await p};return c(),{loadSubset:t=>{let n=B(t);if(`nothing`in n)return!0;if(`keys`in n)return k(n.keys,1).then(A);let i=JSON.stringify(n.query),{limit:a,...o}=n.query,s=JSON.stringify(o),c=[...r.values()].find(({watch:e})=>{let{limit:t,...n}=e.query;return JSON.stringify(n)===s})?.watch;if(n.after){if(c&&c.answers>0)return!0;throw Error(`the catalog serves a window from its start: ask for a larger limit`)}let l=r.get(i);if(!l){let t={holds:0,unlimited:n.unlimited,watch:e.watch(n.query,S,e=>{x(t,()=>t.watch,e),w(t)},c)};l=t,r.set(i,l)}l.holds+=1;let{watch:u}=l;return u.answers>0&&p===!0||u.ready.then(A)},unloadSubset:t=>{let n;try{n=B(t)}catch{return}if(`nothing`in n)return;if(`keys`in n)return void k(n.keys,-1);if(n.after)return;let i=JSON.stringify(n.query),a=r.get(i);if(!a||(--a.holds,a.holds>0))return;r.delete(i);let o=C.get(a);C.delete(a),o&&u(o),E(a,a.watch),e.batchOpen()||g()},cleanup:()=>{_();for(let e of r.values())e.watch.stop();a.watch?.stop(),a.watch=void 0,r.clear(),i.clear(),o.clear()}}}}}}function H({watcher:e,id:t,query:n,row:r,index:i}){return{id:t,...i,getKey:e=>e.path,sync:{rowUpdateMode:`full`,sync:({begin:t,write:i,commit:a,markReady:o,fail:s,collection:c})=>{let l=!1,u=e.onBatch(()=>{l&&(l=!1,d.clear(),a(),o())}),d=/* @__PURE__ */ new Map,f=e=>d.get(e)??c.has(e),p=e.watch(n,r,({del:e,put:n,error:r})=>{if(r){s(Error(r));return}l||t(),l=!0;for(let t of e)f(t)&&(i({type:`delete`,key:t}),d.set(t,!1));for(let e of n)i({type:f(e.path)?`update`:`insert`,value:e}),d.set(e.path,!0)});return()=>{u(),p.stop()}}}}}const U={defaultIndexType:h,autoIndex:`eager`};function W(e){let t=p(V({watcher:e,index:U})),n=p(H({watcher:e,query:{awake:!0},row:C,index:U})),r=m(e=>e.from({context:t}).orderBy(({context:e})=>e.activeMs,`desc`).limit(500));return{contexts:t,awake:n,listings:m(e=>e.from({context:r}).join({awake:n},({context:e,awake:t})=>g(e.path,t.path),`left`))}}const G=/* @__PURE__ */ new WeakMap;function K(e){let t=G.get(e);if(t)return t;let n=A(e),r=W(n),i=!1;n.subscribe(()=>{let e=n.support();e===`none`&&(i=!0),e===`live`&&i&&(i=!1,r=W(n))});let a={watcher:n,get contexts(){return r.contexts},get awake(){return r.awake},get listings(){return r.listings}};return G.set(e,a),a}function q(e,t,{of:n,pollMs:r}){let i=K(e),a=(0,x.useSyncExternalStore)(i.watcher.subscribe,i.watcher.support,i.watcher.support);(0,x.useEffect)(()=>{if(a===`asking`&&i.watcher.probe(),a!==`none`)return;let e=setInterval(()=>{i.watcher.probe()},6e4);return()=>{clearInterval(e)}},[i,a]);let o=b(a===`none`?t:null,{of:n,pollMs:r}),s=a===`live`?i.listings:void 0,c=_({query:e=>s?e.from({listing:s}):void 0}),l=c.isReady?c.data:void 0,u=(0,x.useMemo)(()=>l?.map(({context:e,awake:t})=>({...e,...t&&{awake:{since:t.since}},...t?.activities&&{activities:t.activities}})).toSorted((e,t)=>D(e,t)),[l]);return a===`none`?o:{rows:u,error:c.isLoadingError?`The mind did not answer the catalog's query.`:void 0}}export{S as a,D as c,V as d,H as f,C as i,T as l,q as n,B as o,z as r,A as s,K as t,j as u};
M files.json
@@ -21,7 +21,7 @@
  "dist/chunks/composer.mjs": "sha256-ur1Yc6UJdn4864bX5qikQ8aw7CWyyzYnsumUCpyCHTw=",
  "dist/chunks/context-about.mjs": "sha256-vePZmuv7+0T5OHzCFAE7RkyJeI2s0lKrhNNdMN9XOQs=",
  "dist/chunks/context-catalog-list.mjs": "sha256-QVSUaiCvmrUJ9SRzqUd4QE1dVo3zNKEsnbjyMOUFeBM=",
- "dist/chunks/context-catalog-live.mjs": "sha256-DpVtFhPyBtCObz82KIZELnItO0ILMI2LmS7UjBfqLek=",
+ "dist/chunks/context-catalog-live.mjs": "sha256-r3IvzjsJcv27q9s+lkY6kD5kkVo0km6eTyZoRIt1Jss=",
  "dist/chunks/context-catalog-rows.mjs": "sha256-dylpbLcTFFJEur59B7MTsy95FvWDeqmJpAf2yPTmONA=",
  "dist/chunks/context-view-search.mjs": "sha256-4T7Z+BrSTDf066lVYqQRHfaorkJ59XuMoK9mI670FvA=",
  "dist/chunks/context-view.mjs": "sha256-PoD8eBs1Svd957Fh6WqC5LVJWlFwEiBJChVE6KZ5NDM=",
M release.json
@@ -1,7 +1,7 @@
 {
   "package": "@iterate-com/ui",
-  "source": "2dad9d70df726cde287b3b2066cc14a672d236e8",
-  "workspace": "5b863d456d2bf5614906676736e7171d6b9685f8",
+  "source": "c35a49357c06026b8cf833dd25635a336a615ab6",
+  "workspace": "b57e184844d40fd1df428c55d9da4291f110dc1b",
   "modules": 189,
   "rewritten": 529
 }