@kedem/okdb 3.1.0 → 3.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kedem/okdb",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "A fast, type-oriented database — strong consistency and rich indexing at the core, with sync, vector embeddings, full-text search, and AI tooling built in. Designed for the AI era.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "engines": {
@@ -1 +1 @@
1
- import e from"@toolkit/elements/ok-icon.ok.js";import t from"@toolkit/core/ok-overlay.ok.js";import n from"@admin/components/field-path-input.ok.js";export default{tag:"create-index-modal",dependencies:[n,t,e],attr:{modal:{},type:{},deepPaths:{},geoFields:{},onDone:{}},context:e=>({busy:!1,parts:[],selected:"",isGeo:!1,isUnique:!1,precision:7,get items(){const t=e.$attr.deepPaths;if(t&&"object"==typeof t&&Object.keys(t).length)return Object.entries(t).map(([e,t])=>({path:e,types:Array.isArray(t)?t:[],hint:Array.isArray(t)&&t.includes("geo")?"geo":null}));const n=new Set(e.$attr.geoFields??[]);return(e.$attr.possibleFields??[]).map(e=>({path:e,types:n.has(e)?["geo"]:["string"],hint:n.has(e)?"geo":null}))},get geoSet(){return new Set(e.$attr.geoFields??[])},addPart(){const e=String(this.selected||"").trim();e&&!this.parts.includes(e)&&(this.parts.push(e),this.geoSet.has(e)&&(this.isGeo=!0,this.isUnique=!1),this.selected="")},removePart(e){const t=this.parts.indexOf(e);t>=0&&this.parts.splice(t,1)},onGeoToggle(e){this.isGeo=!!e,this.isGeo&&(this.isUnique=!1)},async save(){if(this.parts.length){this.busy=!0;try{const t={};this.isGeo&&(t.type="geo",t.precision=this.precision),this.isUnique&&!this.isGeo&&(t.unique=!0);const n={method:"POST",...Object.keys(t).length?{headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}:{}},i=await fetch(`${e.$ok.stores.okdb.apiBase}/type/${e.$attr.type}/index/${this.parts.join("~")}`,n);if(!i.ok)throw new Error((await i.json())?.error?.message||i.statusText);await e.$attr.modal.close(),await(e.$attr.onDone?.())}catch(t){e.$ok.shared?.toast?.error?.(t?.message||"Create index failed"),console.error("Create index error",t)}finally{this.busy=!1}}},cancel(){e.$attr.modal.close()}}),template:'\n<div style="position:relative; min-width:380px; display:flex; flex-direction:column; gap:14px;">\n\n <if :="busy">\n <ok-overlay>\n <div class="loader-center">\n <ok-icon name="loader" class="spin" style="width:32px;height:32px;"></ok-icon>\n </div>\n </ok-overlay>\n </if>\n\n \x3c!-- Field picker --\x3e\n <div>\n <div style="font-size:11px; opacity:.5; margin-bottom:6px; text-transform:uppercase; letter-spacing:.05em;">Fields</div>\n <div style="display:flex; gap:8px; align-items:center;">\n <div style="flex:1;">\n <field-path-input\n :value="selected"\n :items="items"\n placeholder="Field path (dot-notation)"\n @change="selected = $event.detail"\n />\n </div>\n <button @click="addPart()" :disabled="!selected || parts.includes(selected)">+ Add</button>\n </div>\n\n \x3c!-- Parts chips --\x3e\n <div style="margin-top:8px; min-height:28px; display:flex; align-items:center; gap:6px; flex-wrap:wrap;">\n <span style="font-size:12px; opacity:.4; user-select:none;">Index:</span>\n <each :of="parts" let:item="p">\n <span style="background:var(--okdb-app-border); padding:3px 8px; border-radius:4px; font-size:12px; display:inline-flex; align-items:center; gap:4px;">\n {{ p }}\n <span style="cursor:pointer; opacity:.6; font-weight:bold;" @click="removePart(p)">×</span>\n </span>\n </each>\n <if :="isGeo && parts.length > 0">\n <span style="font-size:10px; color:var(--okdb-success); opacity:.7;">◎ geo</span>\n </if>\n <if :="isUnique && !isGeo && parts.length > 0">\n <span style="font-size:10px; color:var(--okdb-warning); opacity:.7;">◆ unique</span>\n </if>\n <span style="opacity:.3; font-size:12px;" :style="parts.length ? \'display:none\' : \'\'">(none yet)</span>\n </div>\n </div>\n\n \x3c!-- Index type options --\x3e\n <div style="display:flex; flex-direction:column; gap:6px;">\n\n <label style="font-size:12px; display:flex; align-items:center; gap:6px; cursor:pointer; user-select:none;">\n <input type="checkbox" :checked="isGeo" @change="onGeoToggle($event.target.checked)" />\n ◎ Geo index\n <span style="opacity:.4; font-size:11px;">(field stores <code style="font-size:11px;">{ lat, lon }</code> coordinates)</span>\n </label>\n\n <if :="isGeo">\n <div style="display:flex; align-items:center; gap:8px; padding-left:22px;">\n <span style="font-size:11px; opacity:.5;">Precision</span>\n <input type="range" min="4" max="9" step="1" :value="precision" @input="precision = Number($event.target.value)" style="width:120px;" />\n <span style="font-size:12px; min-width:16px;">{{ precision }}</span>\n <span style="font-size:11px; opacity:.35;">\n {{ precision <= 6 ? \'~\' + [39, 4.9, 1.2][precision - 4] + \' km cells\' :\n \'~\' + [153, 38, 4.8][precision - 7] + \' m cells\' }}\n </span>\n </div>\n </if>\n\n <label style="font-size:12px; display:flex; align-items:center; gap:6px; cursor:pointer; user-select:none;" :style="isGeo ? \'opacity:.35; pointer-events:none;\' : \'\'">\n <input type="checkbox" :checked="isUnique" :disabled="isGeo" @change="isUnique = $event.target.checked" />\n ◆ Unique index\n <span style="opacity:.4; font-size:11px;">(enforces one record per index key)</span>\n </label>\n\n </div>\n\n <div style="display:flex; gap:8px; justify-content:flex-end; padding-top:4px; border-top:1px solid var(--okdb-app-border);">\n <button @click="cancel()">Cancel</button>\n <button @click="save()" :disabled="!parts.length || busy">Create Index</button>\n </div>\n\n</div>\n'};
1
+ import e from"@toolkit/elements/ok-icon.ok.js";import n from"@toolkit/core/ok-overlay.ok.js";import t from"@admin/components/field-path-input.ok.js";export default{tag:"create-index-modal",dependencies:[t,n,e],attr:{modal:{},type:{},deepPaths:{},geoFields:{},onDone:{}},context:e=>({busy:!1,parts:[],selected:"",isGeo:!1,isUnique:!1,isSparse:!1,precision:7,get items(){const n=e.$attr.deepPaths;if(n&&"object"==typeof n&&Object.keys(n).length)return Object.entries(n).map(([e,n])=>({path:e,types:Array.isArray(n)?n:[],hint:Array.isArray(n)&&n.includes("geo")?"geo":null}));const t=new Set(e.$attr.geoFields??[]);return(e.$attr.possibleFields??[]).map(e=>({path:e,types:t.has(e)?["geo"]:["string"],hint:t.has(e)?"geo":null}))},get geoSet(){return new Set(e.$attr.geoFields??[])},addPart(){const e=String(this.selected||"").trim();e&&!this.parts.includes(e)&&(this.parts.push(e),this.geoSet.has(e)&&(this.isGeo=!0,this.isUnique=!1),this.selected="")},removePart(e){const n=this.parts.indexOf(e);n>=0&&this.parts.splice(n,1)},onGeoToggle(e){this.isGeo=!!e,this.isGeo&&(this.isUnique=!1,this.isSparse=!1)},async save(){if(this.parts.length){this.busy=!0;try{const n={};this.isGeo&&(n.type="geo",n.precision=this.precision),this.isUnique&&!this.isGeo&&(n.unique=!0),this.isSparse&&!this.isGeo&&(n.sparse=!0);const t={method:"POST",...Object.keys(n).length?{headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}:{}},s=await fetch(`${e.$ok.stores.okdb.apiBase}/type/${e.$attr.type}/index/${this.parts.join("~")}`,t);if(!s.ok)throw new Error((await s.json())?.error?.message||s.statusText);await e.$attr.modal.close(),await(e.$attr.onDone?.())}catch(n){e.$ok.shared?.toast?.error?.(n?.message||"Create index failed"),console.error("Create index error",n)}finally{this.busy=!1}}},cancel(){e.$attr.modal.close()}}),template:'\n<div style="position:relative; min-width:380px; display:flex; flex-direction:column; gap:14px;">\n\n <if :="busy">\n <ok-overlay>\n <div class="loader-center">\n <ok-icon name="loader" class="spin" style="width:32px;height:32px;"></ok-icon>\n </div>\n </ok-overlay>\n </if>\n\n \x3c!-- Field picker --\x3e\n <div>\n <div style="font-size:11px; opacity:.5; margin-bottom:6px; text-transform:uppercase; letter-spacing:.05em;">Fields</div>\n <div style="display:flex; gap:8px; align-items:center;">\n <div style="flex:1;">\n <field-path-input\n :value="selected"\n :items="items"\n placeholder="Field path (dot-notation)"\n @change="selected = $event.detail"\n />\n </div>\n <button @click="addPart()" :disabled="!selected || parts.includes(selected)">+ Add</button>\n </div>\n\n \x3c!-- Parts chips --\x3e\n <div style="margin-top:8px; min-height:28px; display:flex; align-items:center; gap:6px; flex-wrap:wrap;">\n <span style="font-size:12px; opacity:.4; user-select:none;">Index:</span>\n <each :of="parts" let:item="p">\n <span style="background:var(--okdb-app-border); padding:3px 8px; border-radius:4px; font-size:12px; display:inline-flex; align-items:center; gap:4px;">\n {{ p }}\n <span style="cursor:pointer; opacity:.6; font-weight:bold;" @click="removePart(p)">×</span>\n </span>\n </each>\n <if :="isGeo && parts.length > 0">\n <span style="font-size:10px; color:var(--okdb-success); opacity:.7;">◎ geo</span>\n </if>\n <if :="isUnique && !isGeo && parts.length > 0">\n <span style="font-size:10px; color:var(--okdb-warning); opacity:.7;">◆ unique</span>\n </if>\n <if :="isSparse && !isGeo && parts.length > 0">\n <span style="font-size:10px; opacity:.6;">sparse</span>\n </if>\n <span style="opacity:.3; font-size:12px;" :style="parts.length ? \'display:none\' : \'\'">(none yet)</span>\n </div>\n </div>\n\n \x3c!-- Index type options --\x3e\n <div style="display:flex; flex-direction:column; gap:6px;">\n\n <label style="font-size:12px; display:flex; align-items:center; gap:6px; cursor:pointer; user-select:none;">\n <input type="checkbox" :checked="isGeo" @change="onGeoToggle($event.target.checked)" />\n ◎ Geo index\n <span style="opacity:.4; font-size:11px;">(field stores <code style="font-size:11px;">{ lat, lon }</code> coordinates)</span>\n </label>\n\n <if :="isGeo">\n <div style="display:flex; align-items:center; gap:8px; padding-left:22px;">\n <span style="font-size:11px; opacity:.5;">Precision</span>\n <input type="range" min="4" max="9" step="1" :value="precision" @input="precision = Number($event.target.value)" style="width:120px;" />\n <span style="font-size:12px; min-width:16px;">{{ precision }}</span>\n <span style="font-size:11px; opacity:.35;">\n {{ precision <= 6 ? \'~\' + [39, 4.9, 1.2][precision - 4] + \' km cells\' :\n \'~\' + [153, 38, 4.8][precision - 7] + \' m cells\' }}\n </span>\n </div>\n </if>\n\n <label style="font-size:12px; display:flex; align-items:center; gap:6px; cursor:pointer; user-select:none;" :style="isGeo ? \'opacity:.35; pointer-events:none;\' : \'\'">\n <input type="checkbox" :checked="isUnique" :disabled="isGeo" @change="isUnique = $event.target.checked" />\n ◆ Unique index\n <span style="opacity:.4; font-size:11px;">(enforces one record per index key)</span>\n </label>\n\n <label style="font-size:12px; display:flex; align-items:center; gap:6px; cursor:pointer; user-select:none;" :style="isGeo ? \'opacity:.35; pointer-events:none;\' : \'\'">\n <input type="checkbox" :checked="isSparse" :disabled="isGeo" @change="isSparse = $event.target.checked" />\n <span style="white-space:nowrap;">Sparse index</span>\n <span style="opacity:.4; font-size:11px;">(only records that have every field above; others are left out of this index, so writes are cheaper)</span>\n </label>\n <if :="isSparse && !isGeo">\n <div style="padding-left:22px; font-size:11px; opacity:.5;">\n Records missing any of these fields will not appear in queries or counts on this index. Cannot be changed later &mdash; drop and re-create the index.\n </div>\n </if>\n\n </div>\n\n <div style="display:flex; gap:8px; justify-content:flex-end; padding-top:4px; border-top:1px solid var(--okdb-app-border);">\n <button @click="cancel()">Cancel</button>\n <button @click="save()" :disabled="!parts.length || busy">Create Index</button>\n </div>\n\n</div>\n'};
@@ -1 +1 @@
1
- import e from"@toolkit/elements/ok-icon.ok.js";import t from"@admin/stores/events-store.js";import{createPipelineModal as n}from"@features/pipelines/exports.js";import*as s from"../type-ops.js";import i from"../modals/create-fts-modal.ok.js";import a from"../modals/create-index-modal.ok.js";export default{tag:"type-manage-tab",dependencies:[e,a,i,n],attr:{type:{},env:{}},context:e=>({get type(){return e.$attr.type},get env(){return e.$attr.env||null},get apiBase(){return s.envApiBase(this.env)},get canVector(){return s.canViewVectorEngines(e)},get canPipelines(){return s.enginesTabAllowed(e)},get canTTLStats(){return e.$ok.stores.auth.canView(["system:read"])},possibleIndexes:[],indexStatuses:{},ftsList:[],vectorEngines:[],get typeFields(){const t=(e.$ok.stores.okdb.types||[]).find(e=>e.type===this.type);return t?.fields||{}},get typeCount(){const t=(e.$ok.stores.okdb.types||[]).find(e=>e.type===this.type);return t?.count??"?"},get typeFieldEntries(){return Object.entries(this.typeFields).map(([e,t])=>({name:e,types:t}))},get indexEntries(){return this.possibleIndexes.map(e=>({name:e,fields:e.split("~"),status:this.indexStatuses[e]?.status||"ready",procState:this.indexStatuses[e]?.procState??null,progress:this.indexStatuses[e]?.progress??null,isGeo:!!this.indexStatuses[e]?.geoConfig,geoPrecision:this.indexStatuses[e]?.geoConfig?.precision??null,isUnique:!!this.indexStatuses[e]?.unique,createdBy:this.indexStatuses[e]?.createdBy??null,usedBy:this.indexStatuses[e]?.usedBy??[]}))},get ftsEntries(){return this.ftsList.map(e=>({name:e.name,status:e.status||"ready",fields:(e.config&&e.config.fields?e.config.fields:[]).join(", "),sizeBytes:e.sizeBytes??null}))},get vectorEntries(){return this.vectorEngines.map(e=>({name:e.name,displayName:s.displayVectorName(this.env,e.name),status:e.isRunning?"running":e.status||"stopped",running:e.isRunning,pipeline:e.meta&&e.meta.pipeline?e.meta.pipeline:null}))},fmtBytes(e){if(null==e||0===e)return"—";const t=["B","KB","MB","GB"];let n=e,s=0;for(;n>=1024&&s<t.length-1;)n/=1024,s++;return n.toFixed(1)+" "+t[s]},fmtDuration(e){if(null==e)return"—";const t=Math.floor(e/1e3);return t<60?t+"s":t<3600?Math.floor(t/60)+"m "+t%60+"s":t<86400?Math.floor(t/3600)+"h "+Math.floor(t%3600/60)+"m":Math.floor(t/86400)+"d "+Math.floor(t%86400/3600)+"h"},async loadIndexes(){const{env:e,type:t}=this;if(e&&t)try{const n=await s.fetchIndexes(e,t);if(e!==this.env||t!==this.type)return;this.possibleIndexes=Object.keys(n),this.indexStatuses=n}catch(e){console.error("Error fetching indexes",e)}},async loadFtsIndexes(){const{env:e,type:t}=this;if(e&&t)try{const n=await s.fetchFtsIndexes(e,t);if(e!==this.env||t!==this.type)return;this.ftsList=n}catch(e){console.error("Error fetching FTS indexes",e)}},async loadVectorEngines(){const{env:e,type:t}=this;if(e&&t&&this.canVector)try{const n=await s.fetchVectorEngines(e,t);if(e!==this.env||t!==this.type)return;this.vectorEngines=n}catch(e){this.vectorEngines=[]}else this.vectorEngines=[]},async loadAll(){this.env&&this.type&&await Promise.all([this.loadIndexes(),this.loadFtsIndexes(),this.loadVectorEngines(),this.loadTTLStats(),this.loadDefaultTTL()])},ttlStats:null,ttlStatsLoading:!1,ttlSweepBusy:!1,defaultTTL:null,defaultTTLInput:"",defaultTTLPreset:"",defaultTTLBusy:!1,async loadTTLStats(){if(this.env&&this.type&&this.canTTLStats){this.ttlStatsLoading=!0;try{const e=await fetch(`${this.apiBase}/ttl/stats?type=${encodeURIComponent(this.type)}`),t=await e.json();this.ttlStats=t.data??t.result??null}catch{this.ttlStats=null}finally{this.ttlStatsLoading=!1}}},async loadDefaultTTL(){if(this.env&&this.type)try{const e=await fetch(`${this.apiBase}/type/${encodeURIComponent(this.type)}/ttl/default`),t=await e.json(),n=t.data?.defaultTTL??t.result?.defaultTTL??null;this.defaultTTL=n,this.defaultTTLInput=n?String(n):"",this.defaultTTLPreset=n?String(n):""}catch{this.defaultTTL=null}},async setDefaultTTLAction(){const t=parseInt(this.defaultTTLInput);if(t&&!(t<=0)){this.defaultTTLBusy=!0;try{const n=await fetch(`${this.apiBase}/type/${encodeURIComponent(this.type)}/ttl/default`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({ttl:t})});if(!n.ok){const e=await n.json().catch(()=>({}));throw new Error(e?.error?.message||n.statusText)}this.defaultTTL=t,e.$ok.shared?.toast?.info?.("Default TTL set ("+this.fmtDuration(t)+")")}catch(t){e.$ok.shared?.toast?.error?.(t.message||"Failed to set default TTL")}finally{this.defaultTTLBusy=!1}}},async clearDefaultTTLAction(){this.defaultTTLBusy=!0;try{const t=await fetch(`${this.apiBase}/type/${encodeURIComponent(this.type)}/ttl/default`,{method:"DELETE"});if(!t.ok)throw new Error(t.statusText);this.defaultTTL=null,this.defaultTTLInput="",this.defaultTTLPreset="",e.$ok.shared?.toast?.info?.("Default TTL cleared")}catch(t){e.$ok.shared?.toast?.error?.(t.message||"Failed to clear default TTL")}finally{this.defaultTTLBusy=!1}},onDefaultTTLPresetChange(e){this.defaultTTLPreset=e,e&&(this.defaultTTLInput=e)},async triggerSweep(){this.ttlSweepBusy=!0;try{const t=await fetch(`${this.apiBase}/ttl/sweep`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({batchSize:1e3})}),n=await t.json(),s=n.data??n.result??{};e.$ok.shared?.toast?.info?.(`Sweep done: ${s.removed??0} expired item(s) removed`),await this.loadTTLStats()}catch(t){e.$ok.shared?.toast?.error?.(t.message||"Sweep failed")}finally{this.ttlSweepBusy=!1}},openCreateIndex(){const t=this;return s.openCreateIndex(e,{env:this.env,type:this.type,onDone:()=>t.loadIndexes()})},async removeIndex(t){await s.removeIndex(e,{env:this.env,type:this.type,name:t})&&await this.loadIndexes()},async rebuildIndex(t){await s.rebuildIndex(e,{env:this.env,type:this.type,name:t})&&await this.loadIndexes()},openCreateFtsModal(){const t=this;return s.openCreateFts(e,{env:this.env,type:this.type,onDone:()=>t.loadFtsIndexes()})},async dropFtsIndex(t){await s.dropFts(e,{env:this.env,type:this.type,name:t})&&await this.loadFtsIndexes()},async rebuildFts(t){await s.rebuildFts(e,{env:this.env,type:this.type,name:t})&&await this.loadFtsIndexes()},openEnginesWorkspace(t={}){s.openTypePipelines(e,this.type,{mode:t.mode||"engines",pipeline:t.pipeline||null})},openEnginesPipeline(t=null){s.openTypePipelines(e,this.type,{mode:"pipelines",pipeline:t||null})},openEnginesCreatePipeline(){const t=this;return s.openCreatePipeline(e,{env:this.env,type:this.type,onDone:async()=>{await t.loadVectorEngines(),e.$dispatch("db-type-badges",null,{bubbles:!0})}})},async recomputeFields(){if(this.env&&this.type)try{await fetch(`${this.apiBase}/type/${this.type}/recompute-fields`,{method:"POST"}),await e.$ok.stores.okdb.reloadTypes(),e.$ok.shared?.toast?.success?.("Fields recomputed")}catch(t){console.error("recomputeFields error",t),e.$ok.shared?.toast?.error?.("Recompute failed")}},async dropType(){const t=this.type;if(t&&this.env&&await e.$ok.shared.modal.confirm(`Drop type "${t}"? This cannot be undone.`))try{await fetch(`${this.apiBase}/type/${t}`,{method:"DELETE"}),await e.$ok.stores.okdb.reloadTypes(),e.$ok.shell.navigate("db",{replace:!0})}catch(e){console.error("Drop type error",e)}}}),_unsubs:[],mount(e){e.$watch(()=>[e.$attr.type,e.$attr.env],()=>{this.possibleIndexes=[],this.indexStatuses={},this.ftsList=[],this.vectorEngines=[],this.ttlStats=null,this.loadAll()}),this._unsubs=[t.on("index:reset",()=>{this.loadIndexes(),this.loadFtsIndexes()}),t.on("processor:progress",e=>{e?.meta?.name?.startsWith("index:"+this.type+":")&&this.loadIndexes()}),t.on("index:ready",()=>{this.loadIndexes(),this.loadFtsIndexes()}),t.on("index:registered",()=>this.loadIndexes()),t.on("index:drop",()=>this.loadIndexes()),t.on("fts:registered",()=>this.loadFtsIndexes()),t.on("fts:drop",()=>this.loadFtsIndexes()),t.on("engine:started",()=>this.loadVectorEngines()),t.on("engine:stopped",()=>this.loadVectorEngines()),t.on("engine:error",()=>this.loadVectorEngines()),t.on("engine:installed",()=>this.loadVectorEngines()),t.on("engine:uninstalled",()=>this.loadVectorEngines()),t.on("embeddings:pipeline:ready",()=>this.loadVectorEngines())],this.loadAll()},unmount(){for(const e of this._unsubs)e();this._unsubs=[]},template:'\n <div style="display:flex; flex-direction:column; gap:12px; flex:1; overflow:auto; padding-right:4px;">\n\n \x3c!-- Overview --\x3e\n <div class="card" style="display:flex; gap:24px; align-items:center;">\n <div>\n <div style="font-size:15px; font-weight:600;">{{ type }}</div>\n <div style="font-size:12px; opacity:.5; margin-top:2px;">type</div>\n </div>\n <div>\n <div style="font-size:22px; font-weight:600; color:var(--okdb-accent);">{{ typeCount }}</div>\n <div style="font-size:12px; opacity:.5; margin-top:2px;">records</div>\n </div>\n </div>\n\n \x3c!-- Fields --\x3e\n <div class="card">\n <div class="manage-section-title">Fields</div>\n <if :="typeFieldEntries.length === 0">\n <div style="opacity:.4; font-size:13px;">No fields tracked yet — add items or use Recompute.</div>\n </if>\n <if :="typeFieldEntries.length > 0">\n <div class="manage-grid manage-grid--2">\n <div class="manage-col-hd">Field</div>\n <div class="manage-col-hd">Observed types</div>\n <each :of="typeFieldEntries" let:item="tf">\n <div class="manage-cell"><code>{{ tf.name }}</code></div>\n <div class="manage-cell manage-cell--dim">{{ tf.types.join(\', \') }}</div>\n </each>\n </div>\n </if>\n </div>\n\n \x3c!-- Secondary Indexes --\x3e\n <div class="card">\n <div class="manage-section-header">\n <div class="manage-section-title">Secondary Indexes</div>\n <button @click="openCreateIndex()" class="btn-icon" style="font-size:11px; padding:3px 10px;"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="plus"></ok-icon>Create index\n </button>\n </div>\n <if :="indexEntries.length === 0">\n <div style="opacity:.4; font-size:13px;">No indexes yet.</div>\n </if>\n <if :="indexEntries.length > 0">\n <div class="manage-grid manage-grid--idx">\n <div class="manage-col-hd">Fields</div>\n <div class="manage-col-hd">Kind</div>\n <div class="manage-col-hd">Ownership</div>\n <div class="manage-col-hd">Status</div>\n <div class="manage-col-hd"></div>\n <div class="manage-col-hd"></div>\n <each :of="indexEntries" let:item="ix">\n <div class="manage-cell" style="gap:4px; flex-wrap:wrap;">\n <each :of="ix.fields" let:item="f" let:index="fi">\n <code style="font-size:12px; color:var(--okdb-json-key);">{{ f }}</code><span style="opacity:.3; font-size:11px; margin-left:0;" :style="fi < ix.fields.length - 1 ? \'\' : \'display:none\'">·</span>\n </each>\n </div>\n <div class="manage-cell" style="gap:6px;">\n <if :="ix.isGeo">\n <span class="idx-kind-badge idx-kind-badge--geo">◎ geo</span>\n <span style="font-size:10px; opacity:.45; white-space:nowrap;">precision {{ ix.geoPrecision ?? 7 }}</span>\n </if>\n <if :="ix.isUnique && !ix.isGeo">\n <span class="idx-kind-badge idx-kind-badge--unique">◆ unique</span>\n </if>\n <if :="!ix.isGeo && !ix.isUnique">\n <span class="idx-kind-badge idx-kind-badge--regular">regular</span>\n </if>\n </div>\n <div class="manage-cell" style="gap:3px; flex-direction:column; align-items:flex-start;">\n <if :="ix.createdBy">\n <span class="idx-owned-badge">{{ ix.createdBy.kind }}:{{ ix.createdBy.name }}</span>\n </if>\n <each :of="ix.usedBy" let:item="consumer">\n <span class="idx-consumer-badge">{{ consumer }}</span>\n </each>\n </div>\n <div class="manage-cell" style="flex-direction:column; align-items:flex-start; gap:4px;">\n <span :class="\'manage-status manage-status--\' + ix.status">{{ ix.status }}</span>\n <if :="ix.procState === \'building\' && ix.progress">\n <div class="proc-card__progress" style="width:100%; min-width:60px;">\n <div class="proc-card__progress-bar" :style="\'width:\' + Math.round((ix.progress.percent ?? 0) * 100) + \'%\'"></div>\n </div>\n <span style="font-size:10px; opacity:.55;">{{ Math.round((ix.progress.percent ?? 0) * 100) }}%</span>\n </if>\n </div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <button @click="rebuildIndex(ix.name)" class="btn-icon" style="font-size:11px; padding:2px 10px; opacity:.7;" title="Rebuild this index from all current records"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.can(\'schema:write\') ? \'Rebuild this index from all current records\' : $ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="refresh-cw"></ok-icon>Rebuild\n </button>\n </div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <button @click="removeIndex(ix.name)" class="btn-icon" style="font-size:11px; padding:2px 10px; color:var(--okdb-danger); opacity:.8;"\n :disabled="!$ok.stores.auth.can(\'schema:write\') || ix.usedBy.length > 0"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="ix.usedBy.length > 0 ? \'Used by: \' + ix.usedBy.join(\', \') : ($ok.stores.auth.can(\'schema:write\') ? \'Remove this index\' : $ok.stores.auth.permTooltip(\'schema:write\'))">\n <ok-icon name="trash-2"></ok-icon>Remove\n </button>\n </div>\n </each>\n </div>\n </if>\n </div>\n\n \x3c!-- FTS Indexes --\x3e\n <div class="card">\n <div class="manage-section-header">\n <div class="manage-section-title">FTS Indexes</div>\n <button @click="openCreateFtsModal()" class="btn-icon" style="font-size:11px; padding:3px 10px;"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="plus"></ok-icon>Create FTS index\n </button>\n </div>\n <if :="ftsEntries.length === 0">\n <div style="opacity:.4; font-size:13px;">No FTS indexes yet.</div>\n </if>\n <if :="ftsEntries.length > 0">\n <div class="manage-grid manage-grid--fts">\n <div class="manage-col-hd">Name</div>\n <div class="manage-col-hd">Fields</div>\n <div class="manage-col-hd">Status</div>\n <div class="manage-col-hd">Size</div>\n <div class="manage-col-hd"></div>\n <div class="manage-col-hd"></div>\n <each :of="ftsEntries" let:item="fe">\n <div class="manage-cell"><code>{{ fe.name }}</code></div>\n <div class="manage-cell manage-cell--dim">{{ fe.fields }}</div>\n <div class="manage-cell">\n <span :class="\'manage-status manage-status--\' + fe.status">{{ fe.status }}</span>\n </div>\n <div class="manage-cell manage-cell--dim" style="font-size:11px; font-family:monospace;">{{ fmtBytes(fe.sizeBytes) }}</div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <button @click="rebuildFts(fe.name)" class="btn-icon" style="font-size:11px; padding:2px 10px; opacity:.7;" title="Rebuild this FTS index from all current records"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.can(\'schema:write\') ? \'Rebuild this FTS index from all current records\' : $ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="refresh-cw"></ok-icon>Rebuild\n </button>\n </div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <button @click="dropFtsIndex(fe.name)" class="btn-icon" style="font-size:11px; padding:2px 10px; color:var(--okdb-danger); opacity:.8;" title="Drop this FTS index"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.can(\'schema:write\') ? \'Drop this FTS index\' : $ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="trash-2"></ok-icon>Drop\n </button>\n </div>\n </each>\n </div>\n </if>\n </div>\n\n \x3c!-- Vector Search Engines (embeddings UI kept in DB — design/admin-shell.md §5.5; needs system:read) --\x3e\n <if :="canVector">\n <div class="card">\n <div class="manage-section-header">\n <div class="manage-section-title">Vector Search Engines</div>\n <if :="canPipelines">\n <button\n @click="openEnginesWorkspace()"\n class="btn-icon"\n style="font-size:11px; padding:3px 10px; color:var(--okdb-indigo); border-color:color-mix(in srgb, var(--okdb-indigo) 27%, transparent);"\n title="Open the type-scoped engines view for this type"\n >\n ⛓ Type Engines →\n </button>\n </if>\n </div>\n <if :="vectorEntries.length === 0">\n <div style="opacity:.4; font-size:13px;">\n No vector search engines for this type yet.\n <if :="canPipelines">\n <button\n @click="openEnginesCreatePipeline()"\n style="margin-left:6px; font-size:11px; padding:1px 8px; border-radius:999px; border:1px solid color-mix(in srgb, var(--okdb-indigo) 27%, transparent); color:var(--okdb-indigo); background:color-mix(in srgb, var(--okdb-indigo) 5%, transparent); cursor:pointer;"\n >Create Pipeline…</button>\n </if>\n </div>\n </if>\n <if :="vectorEntries.length > 0">\n <div class="manage-grid manage-grid--vec">\n <div class="manage-col-hd">Engine</div>\n <div class="manage-col-hd">Status</div>\n <div class="manage-col-hd">Pipeline</div>\n <div class="manage-col-hd"></div>\n <each :of="vectorEntries" let:item="ve">\n <div class="manage-cell"><code>{{ ve.displayName }}</code></div>\n <div class="manage-cell">\n <span :class="\'manage-status manage-status--\' + (ve.running ? \'ready\' : \'creating\')">{{ ve.status }}</span>\n </div>\n <div class="manage-cell manage-cell--dim">{{ ve.pipeline ?? \'—\' }}</div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <if :="canPipelines">\n <button\n @click="openEnginesPipeline(ve.pipeline)"\n class="btn-icon"\n style="font-size:11px; padding:2px 10px; color:var(--okdb-indigo); opacity:.85;"\n title="Open this type-scoped pipeline view"\n >\n ⛓ View local →\n </button>\n </if>\n </div>\n </each>\n </div>\n </if>\n </div>\n </if>\n\n \x3c!-- TTL --\x3e\n <div class="card">\n <div class="manage-section-header">\n <div class="manage-section-title">Time-to-Live (TTL)</div>\n <button @click="(loadTTLStats(), loadDefaultTTL())" class="btn-icon" style="font-size:11px; padding:3px 10px; opacity:.6;" :disabled="ttlStatsLoading" title="Refresh TTL stats">\n ↻\n </button>\n </div>\n\n \x3c!-- Default TTL --\x3e\n <div style="margin-bottom:12px; padding:10px; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px;">\n <div style="font-size:12px; font-weight:600; opacity:.7; margin-bottom:8px;">Default TTL for new items</div>\n <if :="defaultTTL">\n <div style="font-size:13px; color:var(--okdb-success); margin-bottom:8px;">\n Currently: <span style="font-family:monospace; font-weight:600;">{{ fmtDuration(defaultTTL) }}</span>\n <span style="opacity:.4; font-size:11px;"> ({{ defaultTTL }}ms)</span>\n </div>\n </if>\n <if :="!defaultTTL">\n <div style="font-size:12px; opacity:.4; margin-bottom:8px;">No default — items don\'t expire unless TTL is set explicitly.</div>\n </if>\n <div style="display:flex; gap:6px; align-items:center; flex-wrap:wrap;">\n <select\n @change="onDefaultTTLPresetChange($event.target.value)"\n style="font-size:11px; padding:2px 6px; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:4px; color:var(--okdb-app-fg);"\n >\n <option value="">Custom…</option>\n <option value="60000">1 min</option>\n <option value="300000">5 min</option>\n <option value="900000">15 min</option>\n <option value="3600000">1 hr</option>\n <option value="21600000">6 hr</option>\n <option value="86400000">24 hr</option>\n <option value="604800000">7 days</option>\n <option value="2592000000">30 days</option>\n </select>\n <input\n type="number"\n !value="defaultTTLInput"\n @input="(defaultTTLInput = $el.value, defaultTTLPreset = \'\')"\n placeholder="ms"\n style="width:110px; font-size:11px; padding:2px 6px; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:4px; color:var(--okdb-app-fg);"\n />\n <button @click="setDefaultTTLAction()" :disabled="defaultTTLBusy || !defaultTTLInput || !$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')"\n style="font-size:11px; padding:2px 10px; color:var(--okdb-success); border-color:color-mix(in srgb, var(--okdb-success) 33%, transparent);">Set</button>\n <if :="defaultTTL">\n <button @click="clearDefaultTTLAction()" :disabled="defaultTTLBusy || !$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')"\n style="font-size:11px; padding:2px 10px; color:var(--okdb-danger); border-color:color-mix(in srgb, var(--okdb-danger) 33%, transparent);">Clear</button>\n </if>\n </div>\n </div>\n\n \x3c!-- TTL stats (system:read; the sweep is system:write) --\x3e\n <if :="!canTTLStats">\n <div style="opacity:.4; font-size:13px;">TTL entry stats and the expiry sweep need the system:read permission.</div>\n </if>\n <if :="canTTLStats && (!ttlStats || !ttlStats.enabled)">\n <div style="opacity:.4; font-size:13px;">No TTL entries for this type — TTL sub-databases are created lazily on first use.</div>\n </if>\n <if :="canTTLStats && ttlStats && ttlStats.enabled">\n <div style="display:flex; gap:24px; align-items:center; margin-bottom:10px;">\n <div>\n <div style="font-size:18px; font-weight:600; color:var(--okdb-success);">{{ ttlStats.totalEntries }}</div>\n <div style="font-size:11px; opacity:.5;">entries</div>\n </div>\n <div>\n <div :style="\'font-size:18px; font-weight:600; color:\' + (ttlStats.expiredEntries > 0 ? \'var(--okdb-danger)\' : \'var(--okdb-app-fg-muted)\') + \';\'">{{ ttlStats.expiredEntries }}</div>\n <div style="font-size:11px; opacity:.5;">expired</div>\n </div>\n <div>\n <div style="font-size:13px; font-family:monospace; color:var(--okdb-app-fg);">{{ ttlStats.nextExpiry ? fmtDuration(ttlStats.nextExpiry - Date.now()) : \'—\' }}</div>\n <div style="font-size:11px; opacity:.5;">next expiry</div>\n </div>\n </div>\n <div style="display:flex; gap:8px; align-items:center;">\n <button @click="triggerSweep()" :disabled="ttlSweepBusy || !$ok.stores.auth.can(\'system:write\')" class="btn-icon" style="font-size:11px; padding:3px 10px;"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'system:write\') }"\n :title="$ok.stores.auth.permTooltip(\'system:write\')">\n <ok-icon name="refresh-cw"></ok-icon>Sweep expired now\n </button>\n <if :="ttlSweepBusy"><span style="font-size:11px; opacity:.5;">Sweeping…</span></if>\n </div>\n </if>\n </div>\n\n \x3c!-- Danger zone --\x3e\n <div class="card card--danger">\n <div class="manage-section-title" style="color:var(--okdb-danger);">⚠ Danger Zone</div>\n <div style="display:flex; gap:8px; flex-wrap:wrap; align-items:center;">\n <button @click="recomputeFields" class="btn-icon"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.can(\'schema:write\') ? \'Rescan all records to rebuild the field schema\' : $ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="refresh-cw"></ok-icon>Recompute fields\n </button>\n <button @click="dropType" class="btn-danger btn-icon"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="trash-2"></ok-icon>Drop type\n </button>\n </div>\n </div>\n\n </div>',style:"[tag]{display:flex;flex-direction:column;flex:1;min-width:0;min-height:0}.manage-section-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px}.manage-section-title{font-weight:600;font-size:12px;text-transform:uppercase;letter-spacing:.06em;opacity:.5;margin-bottom:0}.manage-grid{display:grid;gap:0}.manage-grid--2{grid-template-columns:1fr 1fr}.manage-grid--idx{grid-template-columns:minmax(80px,2fr) minmax(90px,1fr) minmax(80px,1fr) auto auto auto}.manage-grid--fts{grid-template-columns:minmax(80px,1fr) 2fr minmax(60px,auto) minmax(50px,auto) auto auto}.manage-grid--vec{grid-template-columns:minmax(80px,1fr) minmax(60px,auto) minmax(80px,1fr) auto}.idx-owned-badge{padding:1px 6px;border-radius:3px;background:color-mix(in srgb,var(--okdb-accent) 12%,transparent);color:var(--okdb-accent);border:1px solid color-mix(in srgb,var(--okdb-accent) 25%,transparent)}.idx-consumer-badge,.idx-kind-badge,.idx-owned-badge{display:inline-block;font-size:10px;white-space:nowrap}.idx-consumer-badge{padding:1px 6px;border-radius:3px;background:color-mix(in srgb,var(--okdb-sky) 12%,transparent);color:var(--okdb-sky);border:1px solid color-mix(in srgb,var(--okdb-sky) 25%,transparent)}.idx-kind-badge{padding:1px 7px;border-radius:999px;border:1px solid}.idx-kind-badge--geo{color:var(--okdb-success);border-color:color-mix(in srgb,var(--okdb-success) 33%,transparent)}.idx-kind-badge--unique{color:var(--okdb-warning);border-color:color-mix(in srgb,var(--okdb-warning) 33%,transparent)}.idx-kind-badge--regular{color:var(--okdb-app-fg-muted);border-color:color-mix(in srgb,var(--okdb-app-fg-muted) 20%,transparent)}.manage-col-hd{font-size:11px;opacity:.4;padding:0 12px 6px 0;border-bottom:1px solid var(--okdb-app-border);font-weight:400}.manage-cell{padding:6px 12px 6px 0;border-bottom:1px solid var(--okdb-app-surface);font-size:13px;display:flex;align-items:center;min-width:0}.manage-cell--dim{opacity:.5;font-size:12px}.manage-status{display:inline-block;padding:1px 7px;border-radius:999px;font-size:10px;border:1px solid}.manage-status--ready{color:var(--okdb-success);border-color:color-mix(in srgb,var(--okdb-success) 33%,transparent)}.manage-status--creating,.manage-status--resetting{color:var(--okdb-warning);border-color:color-mix(in srgb,var(--okdb-warning) 33%,transparent)}.card--danger{border:1px solid color-mix(in srgb,var(--okdb-danger) 13%,transparent)!important}.proc-card__progress{background:var(--okdb-app-border);border-radius:999px;height:4px;overflow:hidden}.proc-card__progress-bar{height:100%;background:var(--okdb-warning);border-radius:999px;transition:width .3s}"};
1
+ import e from"@toolkit/elements/ok-icon.ok.js";import t from"@admin/stores/events-store.js";import{createPipelineModal as n}from"@features/pipelines/exports.js";import*as s from"../type-ops.js";import i from"../modals/create-fts-modal.ok.js";import a from"../modals/create-index-modal.ok.js";export default{tag:"type-manage-tab",dependencies:[e,a,i,n],attr:{type:{},env:{}},context:e=>({get type(){return e.$attr.type},get env(){return e.$attr.env||null},get apiBase(){return s.envApiBase(this.env)},get canVector(){return s.canViewVectorEngines(e)},get canPipelines(){return s.enginesTabAllowed(e)},get canTTLStats(){return e.$ok.stores.auth.canView(["system:read"])},possibleIndexes:[],indexStatuses:{},ftsList:[],vectorEngines:[],get typeFields(){const t=(e.$ok.stores.okdb.types||[]).find(e=>e.type===this.type);return t?.fields||{}},get typeCount(){const t=(e.$ok.stores.okdb.types||[]).find(e=>e.type===this.type);return t?.count??"?"},get typeFieldEntries(){return Object.entries(this.typeFields).map(([e,t])=>({name:e,types:t}))},get indexEntries(){return this.possibleIndexes.map(e=>({name:e,fields:e.split("~"),status:this.indexStatuses[e]?.status||"ready",procState:this.indexStatuses[e]?.procState??null,progress:this.indexStatuses[e]?.progress??null,isGeo:!!this.indexStatuses[e]?.geoConfig,geoPrecision:this.indexStatuses[e]?.geoConfig?.precision??null,isUnique:!!this.indexStatuses[e]?.unique,isSparse:!!this.indexStatuses[e]?.sparse,createdBy:this.indexStatuses[e]?.createdBy??null,usedBy:this.indexStatuses[e]?.usedBy??[]}))},get ftsEntries(){return this.ftsList.map(e=>({name:e.name,status:e.status||"ready",fields:(e.config&&e.config.fields?e.config.fields:[]).join(", "),sizeBytes:e.sizeBytes??null}))},get vectorEntries(){return this.vectorEngines.map(e=>({name:e.name,displayName:s.displayVectorName(this.env,e.name),status:e.isRunning?"running":e.status||"stopped",running:e.isRunning,pipeline:e.meta&&e.meta.pipeline?e.meta.pipeline:null}))},fmtBytes(e){if(null==e||0===e)return"—";const t=["B","KB","MB","GB"];let n=e,s=0;for(;n>=1024&&s<t.length-1;)n/=1024,s++;return n.toFixed(1)+" "+t[s]},fmtDuration(e){if(null==e)return"—";const t=Math.floor(e/1e3);return t<60?t+"s":t<3600?Math.floor(t/60)+"m "+t%60+"s":t<86400?Math.floor(t/3600)+"h "+Math.floor(t%3600/60)+"m":Math.floor(t/86400)+"d "+Math.floor(t%86400/3600)+"h"},async loadIndexes(){const{env:e,type:t}=this;if(e&&t)try{const n=await s.fetchIndexes(e,t);if(e!==this.env||t!==this.type)return;this.possibleIndexes=Object.keys(n),this.indexStatuses=n}catch(e){console.error("Error fetching indexes",e)}},async loadFtsIndexes(){const{env:e,type:t}=this;if(e&&t)try{const n=await s.fetchFtsIndexes(e,t);if(e!==this.env||t!==this.type)return;this.ftsList=n}catch(e){console.error("Error fetching FTS indexes",e)}},async loadVectorEngines(){const{env:e,type:t}=this;if(e&&t&&this.canVector)try{const n=await s.fetchVectorEngines(e,t);if(e!==this.env||t!==this.type)return;this.vectorEngines=n}catch(e){this.vectorEngines=[]}else this.vectorEngines=[]},async loadAll(){this.env&&this.type&&await Promise.all([this.loadIndexes(),this.loadFtsIndexes(),this.loadVectorEngines(),this.loadTTLStats(),this.loadDefaultTTL()])},ttlStats:null,ttlStatsLoading:!1,ttlSweepBusy:!1,defaultTTL:null,defaultTTLInput:"",defaultTTLPreset:"",defaultTTLBusy:!1,async loadTTLStats(){if(this.env&&this.type&&this.canTTLStats){this.ttlStatsLoading=!0;try{const e=await fetch(`${this.apiBase}/ttl/stats?type=${encodeURIComponent(this.type)}`),t=await e.json();this.ttlStats=t.data??t.result??null}catch{this.ttlStats=null}finally{this.ttlStatsLoading=!1}}},async loadDefaultTTL(){if(this.env&&this.type)try{const e=await fetch(`${this.apiBase}/type/${encodeURIComponent(this.type)}/ttl/default`),t=await e.json(),n=t.data?.defaultTTL??t.result?.defaultTTL??null;this.defaultTTL=n,this.defaultTTLInput=n?String(n):"",this.defaultTTLPreset=n?String(n):""}catch{this.defaultTTL=null}},async setDefaultTTLAction(){const t=parseInt(this.defaultTTLInput);if(t&&!(t<=0)){this.defaultTTLBusy=!0;try{const n=await fetch(`${this.apiBase}/type/${encodeURIComponent(this.type)}/ttl/default`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({ttl:t})});if(!n.ok){const e=await n.json().catch(()=>({}));throw new Error(e?.error?.message||n.statusText)}this.defaultTTL=t,e.$ok.shared?.toast?.info?.("Default TTL set ("+this.fmtDuration(t)+")")}catch(t){e.$ok.shared?.toast?.error?.(t.message||"Failed to set default TTL")}finally{this.defaultTTLBusy=!1}}},async clearDefaultTTLAction(){this.defaultTTLBusy=!0;try{const t=await fetch(`${this.apiBase}/type/${encodeURIComponent(this.type)}/ttl/default`,{method:"DELETE"});if(!t.ok)throw new Error(t.statusText);this.defaultTTL=null,this.defaultTTLInput="",this.defaultTTLPreset="",e.$ok.shared?.toast?.info?.("Default TTL cleared")}catch(t){e.$ok.shared?.toast?.error?.(t.message||"Failed to clear default TTL")}finally{this.defaultTTLBusy=!1}},onDefaultTTLPresetChange(e){this.defaultTTLPreset=e,e&&(this.defaultTTLInput=e)},async triggerSweep(){this.ttlSweepBusy=!0;try{const t=await fetch(`${this.apiBase}/ttl/sweep`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({batchSize:1e3})}),n=await t.json(),s=n.data??n.result??{};e.$ok.shared?.toast?.info?.(`Sweep done: ${s.removed??0} expired item(s) removed`),await this.loadTTLStats()}catch(t){e.$ok.shared?.toast?.error?.(t.message||"Sweep failed")}finally{this.ttlSweepBusy=!1}},openCreateIndex(){const t=this;return s.openCreateIndex(e,{env:this.env,type:this.type,onDone:()=>t.loadIndexes()})},async removeIndex(t){await s.removeIndex(e,{env:this.env,type:this.type,name:t})&&await this.loadIndexes()},async rebuildIndex(t){await s.rebuildIndex(e,{env:this.env,type:this.type,name:t})&&await this.loadIndexes()},openCreateFtsModal(){const t=this;return s.openCreateFts(e,{env:this.env,type:this.type,onDone:()=>t.loadFtsIndexes()})},async dropFtsIndex(t){await s.dropFts(e,{env:this.env,type:this.type,name:t})&&await this.loadFtsIndexes()},async rebuildFts(t){await s.rebuildFts(e,{env:this.env,type:this.type,name:t})&&await this.loadFtsIndexes()},openEnginesWorkspace(t={}){s.openTypePipelines(e,this.type,{mode:t.mode||"engines",pipeline:t.pipeline||null})},openEnginesPipeline(t=null){s.openTypePipelines(e,this.type,{mode:"pipelines",pipeline:t||null})},openEnginesCreatePipeline(){const t=this;return s.openCreatePipeline(e,{env:this.env,type:this.type,onDone:async()=>{await t.loadVectorEngines(),e.$dispatch("db-type-badges",null,{bubbles:!0})}})},async recomputeFields(){if(this.env&&this.type)try{await fetch(`${this.apiBase}/type/${this.type}/recompute-fields`,{method:"POST"}),await e.$ok.stores.okdb.reloadTypes(),e.$ok.shared?.toast?.success?.("Fields recomputed")}catch(t){console.error("recomputeFields error",t),e.$ok.shared?.toast?.error?.("Recompute failed")}},async dropType(){const t=this.type;if(t&&this.env&&await e.$ok.shared.modal.confirm(`Drop type "${t}"? This cannot be undone.`))try{await fetch(`${this.apiBase}/type/${t}`,{method:"DELETE"}),await e.$ok.stores.okdb.reloadTypes(),e.$ok.shell.navigate("db",{replace:!0})}catch(e){console.error("Drop type error",e)}}}),_unsubs:[],mount(e){e.$watch(()=>[e.$attr.type,e.$attr.env],()=>{this.possibleIndexes=[],this.indexStatuses={},this.ftsList=[],this.vectorEngines=[],this.ttlStats=null,this.loadAll()}),this._unsubs=[t.on("index:reset",()=>{this.loadIndexes(),this.loadFtsIndexes()}),t.on("processor:progress",e=>{e?.meta?.name?.startsWith("index:"+this.type+":")&&this.loadIndexes()}),t.on("index:ready",()=>{this.loadIndexes(),this.loadFtsIndexes()}),t.on("index:registered",()=>this.loadIndexes()),t.on("index:drop",()=>this.loadIndexes()),t.on("fts:registered",()=>this.loadFtsIndexes()),t.on("fts:drop",()=>this.loadFtsIndexes()),t.on("engine:started",()=>this.loadVectorEngines()),t.on("engine:stopped",()=>this.loadVectorEngines()),t.on("engine:error",()=>this.loadVectorEngines()),t.on("engine:installed",()=>this.loadVectorEngines()),t.on("engine:uninstalled",()=>this.loadVectorEngines()),t.on("embeddings:pipeline:ready",()=>this.loadVectorEngines())],this.loadAll()},unmount(){for(const e of this._unsubs)e();this._unsubs=[]},template:'\n <div style="display:flex; flex-direction:column; gap:12px; flex:1; overflow:auto; padding-right:4px;">\n\n \x3c!-- Overview --\x3e\n <div class="card" style="display:flex; gap:24px; align-items:center;">\n <div>\n <div style="font-size:15px; font-weight:600;">{{ type }}</div>\n <div style="font-size:12px; opacity:.5; margin-top:2px;">type</div>\n </div>\n <div>\n <div style="font-size:22px; font-weight:600; color:var(--okdb-accent);">{{ typeCount }}</div>\n <div style="font-size:12px; opacity:.5; margin-top:2px;">records</div>\n </div>\n </div>\n\n \x3c!-- Fields --\x3e\n <div class="card">\n <div class="manage-section-title">Fields</div>\n <if :="typeFieldEntries.length === 0">\n <div style="opacity:.4; font-size:13px;">No fields tracked yet — add items or use Recompute.</div>\n </if>\n <if :="typeFieldEntries.length > 0">\n <div class="manage-grid manage-grid--2">\n <div class="manage-col-hd">Field</div>\n <div class="manage-col-hd">Observed types</div>\n <each :of="typeFieldEntries" let:item="tf">\n <div class="manage-cell"><code>{{ tf.name }}</code></div>\n <div class="manage-cell manage-cell--dim">{{ tf.types.join(\', \') }}</div>\n </each>\n </div>\n </if>\n </div>\n\n \x3c!-- Secondary Indexes --\x3e\n <div class="card">\n <div class="manage-section-header">\n <div class="manage-section-title">Secondary Indexes</div>\n <button @click="openCreateIndex()" class="btn-icon" style="font-size:11px; padding:3px 10px;"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="plus"></ok-icon>Create index\n </button>\n </div>\n <if :="indexEntries.length === 0">\n <div style="opacity:.4; font-size:13px;">No indexes yet.</div>\n </if>\n <if :="indexEntries.length > 0">\n <div class="manage-grid manage-grid--idx">\n <div class="manage-col-hd">Fields</div>\n <div class="manage-col-hd">Kind</div>\n <div class="manage-col-hd">Ownership</div>\n <div class="manage-col-hd">Status</div>\n <div class="manage-col-hd"></div>\n <div class="manage-col-hd"></div>\n <each :of="indexEntries" let:item="ix">\n <div class="manage-cell" style="gap:4px; flex-wrap:wrap;">\n <each :of="ix.fields" let:item="f" let:index="fi">\n <code style="font-size:12px; color:var(--okdb-json-key);">{{ f }}</code><span style="opacity:.3; font-size:11px; margin-left:0;" :style="fi < ix.fields.length - 1 ? \'\' : \'display:none\'">·</span>\n </each>\n </div>\n <div class="manage-cell" style="gap:6px;">\n <if :="ix.isGeo">\n <span class="idx-kind-badge idx-kind-badge--geo">◎ geo</span>\n <span style="font-size:10px; opacity:.45; white-space:nowrap;">precision {{ ix.geoPrecision ?? 7 }}</span>\n </if>\n <if :="ix.isUnique && !ix.isGeo">\n <span class="idx-kind-badge idx-kind-badge--unique">◆ unique</span>\n </if>\n <if :="!ix.isGeo && !ix.isUnique && !ix.isSparse">\n <span class="idx-kind-badge idx-kind-badge--regular">regular</span>\n </if>\n <if :="ix.isSparse">\n <span class="idx-kind-badge idx-kind-badge--regular" title="Only records that have every indexed field are in this index">sparse</span>\n </if>\n </div>\n <div class="manage-cell" style="gap:3px; flex-direction:column; align-items:flex-start;">\n <if :="ix.createdBy">\n <span class="idx-owned-badge">{{ ix.createdBy.kind }}:{{ ix.createdBy.name }}</span>\n </if>\n <each :of="ix.usedBy" let:item="consumer">\n <span class="idx-consumer-badge">{{ consumer }}</span>\n </each>\n </div>\n <div class="manage-cell" style="flex-direction:column; align-items:flex-start; gap:4px;">\n <span :class="\'manage-status manage-status--\' + ix.status">{{ ix.status }}</span>\n <if :="ix.procState === \'building\' && ix.progress">\n <div class="proc-card__progress" style="width:100%; min-width:60px;">\n <div class="proc-card__progress-bar" :style="\'width:\' + Math.round((ix.progress.percent ?? 0) * 100) + \'%\'"></div>\n </div>\n <span style="font-size:10px; opacity:.55;">{{ Math.round((ix.progress.percent ?? 0) * 100) }}%</span>\n </if>\n </div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <button @click="rebuildIndex(ix.name)" class="btn-icon" style="font-size:11px; padding:2px 10px; opacity:.7;" title="Rebuild this index from all current records"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.can(\'schema:write\') ? \'Rebuild this index from all current records\' : $ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="refresh-cw"></ok-icon>Rebuild\n </button>\n </div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <button @click="removeIndex(ix.name)" class="btn-icon" style="font-size:11px; padding:2px 10px; color:var(--okdb-danger); opacity:.8;"\n :disabled="!$ok.stores.auth.can(\'schema:write\') || ix.usedBy.length > 0"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="ix.usedBy.length > 0 ? \'Used by: \' + ix.usedBy.join(\', \') : ($ok.stores.auth.can(\'schema:write\') ? \'Remove this index\' : $ok.stores.auth.permTooltip(\'schema:write\'))">\n <ok-icon name="trash-2"></ok-icon>Remove\n </button>\n </div>\n </each>\n </div>\n </if>\n </div>\n\n \x3c!-- FTS Indexes --\x3e\n <div class="card">\n <div class="manage-section-header">\n <div class="manage-section-title">FTS Indexes</div>\n <button @click="openCreateFtsModal()" class="btn-icon" style="font-size:11px; padding:3px 10px;"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="plus"></ok-icon>Create FTS index\n </button>\n </div>\n <if :="ftsEntries.length === 0">\n <div style="opacity:.4; font-size:13px;">No FTS indexes yet.</div>\n </if>\n <if :="ftsEntries.length > 0">\n <div class="manage-grid manage-grid--fts">\n <div class="manage-col-hd">Name</div>\n <div class="manage-col-hd">Fields</div>\n <div class="manage-col-hd">Status</div>\n <div class="manage-col-hd">Size</div>\n <div class="manage-col-hd"></div>\n <div class="manage-col-hd"></div>\n <each :of="ftsEntries" let:item="fe">\n <div class="manage-cell"><code>{{ fe.name }}</code></div>\n <div class="manage-cell manage-cell--dim">{{ fe.fields }}</div>\n <div class="manage-cell">\n <span :class="\'manage-status manage-status--\' + fe.status">{{ fe.status }}</span>\n </div>\n <div class="manage-cell manage-cell--dim" style="font-size:11px; font-family:monospace;">{{ fmtBytes(fe.sizeBytes) }}</div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <button @click="rebuildFts(fe.name)" class="btn-icon" style="font-size:11px; padding:2px 10px; opacity:.7;" title="Rebuild this FTS index from all current records"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.can(\'schema:write\') ? \'Rebuild this FTS index from all current records\' : $ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="refresh-cw"></ok-icon>Rebuild\n </button>\n </div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <button @click="dropFtsIndex(fe.name)" class="btn-icon" style="font-size:11px; padding:2px 10px; color:var(--okdb-danger); opacity:.8;" title="Drop this FTS index"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.can(\'schema:write\') ? \'Drop this FTS index\' : $ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="trash-2"></ok-icon>Drop\n </button>\n </div>\n </each>\n </div>\n </if>\n </div>\n\n \x3c!-- Vector Search Engines (embeddings UI kept in DB — design/admin-shell.md §5.5; needs system:read) --\x3e\n <if :="canVector">\n <div class="card">\n <div class="manage-section-header">\n <div class="manage-section-title">Vector Search Engines</div>\n <if :="canPipelines">\n <button\n @click="openEnginesWorkspace()"\n class="btn-icon"\n style="font-size:11px; padding:3px 10px; color:var(--okdb-indigo); border-color:color-mix(in srgb, var(--okdb-indigo) 27%, transparent);"\n title="Open the type-scoped engines view for this type"\n >\n ⛓ Type Engines →\n </button>\n </if>\n </div>\n <if :="vectorEntries.length === 0">\n <div style="opacity:.4; font-size:13px;">\n No vector search engines for this type yet.\n <if :="canPipelines">\n <button\n @click="openEnginesCreatePipeline()"\n style="margin-left:6px; font-size:11px; padding:1px 8px; border-radius:999px; border:1px solid color-mix(in srgb, var(--okdb-indigo) 27%, transparent); color:var(--okdb-indigo); background:color-mix(in srgb, var(--okdb-indigo) 5%, transparent); cursor:pointer;"\n >Create Pipeline…</button>\n </if>\n </div>\n </if>\n <if :="vectorEntries.length > 0">\n <div class="manage-grid manage-grid--vec">\n <div class="manage-col-hd">Engine</div>\n <div class="manage-col-hd">Status</div>\n <div class="manage-col-hd">Pipeline</div>\n <div class="manage-col-hd"></div>\n <each :of="vectorEntries" let:item="ve">\n <div class="manage-cell"><code>{{ ve.displayName }}</code></div>\n <div class="manage-cell">\n <span :class="\'manage-status manage-status--\' + (ve.running ? \'ready\' : \'creating\')">{{ ve.status }}</span>\n </div>\n <div class="manage-cell manage-cell--dim">{{ ve.pipeline ?? \'—\' }}</div>\n <div class="manage-cell" style="justify-content:flex-end;">\n <if :="canPipelines">\n <button\n @click="openEnginesPipeline(ve.pipeline)"\n class="btn-icon"\n style="font-size:11px; padding:2px 10px; color:var(--okdb-indigo); opacity:.85;"\n title="Open this type-scoped pipeline view"\n >\n ⛓ View local →\n </button>\n </if>\n </div>\n </each>\n </div>\n </if>\n </div>\n </if>\n\n \x3c!-- TTL --\x3e\n <div class="card">\n <div class="manage-section-header">\n <div class="manage-section-title">Time-to-Live (TTL)</div>\n <button @click="(loadTTLStats(), loadDefaultTTL())" class="btn-icon" style="font-size:11px; padding:3px 10px; opacity:.6;" :disabled="ttlStatsLoading" title="Refresh TTL stats">\n ↻\n </button>\n </div>\n\n \x3c!-- Default TTL --\x3e\n <div style="margin-bottom:12px; padding:10px; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:6px;">\n <div style="font-size:12px; font-weight:600; opacity:.7; margin-bottom:8px;">Default TTL for new items</div>\n <if :="defaultTTL">\n <div style="font-size:13px; color:var(--okdb-success); margin-bottom:8px;">\n Currently: <span style="font-family:monospace; font-weight:600;">{{ fmtDuration(defaultTTL) }}</span>\n <span style="opacity:.4; font-size:11px;"> ({{ defaultTTL }}ms)</span>\n </div>\n </if>\n <if :="!defaultTTL">\n <div style="font-size:12px; opacity:.4; margin-bottom:8px;">No default — items don\'t expire unless TTL is set explicitly.</div>\n </if>\n <div style="display:flex; gap:6px; align-items:center; flex-wrap:wrap;">\n <select\n @change="onDefaultTTLPresetChange($event.target.value)"\n style="font-size:11px; padding:2px 6px; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:4px; color:var(--okdb-app-fg);"\n >\n <option value="">Custom…</option>\n <option value="60000">1 min</option>\n <option value="300000">5 min</option>\n <option value="900000">15 min</option>\n <option value="3600000">1 hr</option>\n <option value="21600000">6 hr</option>\n <option value="86400000">24 hr</option>\n <option value="604800000">7 days</option>\n <option value="2592000000">30 days</option>\n </select>\n <input\n type="number"\n !value="defaultTTLInput"\n @input="(defaultTTLInput = $el.value, defaultTTLPreset = \'\')"\n placeholder="ms"\n style="width:110px; font-size:11px; padding:2px 6px; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:4px; color:var(--okdb-app-fg);"\n />\n <button @click="setDefaultTTLAction()" :disabled="defaultTTLBusy || !defaultTTLInput || !$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')"\n style="font-size:11px; padding:2px 10px; color:var(--okdb-success); border-color:color-mix(in srgb, var(--okdb-success) 33%, transparent);">Set</button>\n <if :="defaultTTL">\n <button @click="clearDefaultTTLAction()" :disabled="defaultTTLBusy || !$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')"\n style="font-size:11px; padding:2px 10px; color:var(--okdb-danger); border-color:color-mix(in srgb, var(--okdb-danger) 33%, transparent);">Clear</button>\n </if>\n </div>\n </div>\n\n \x3c!-- TTL stats (system:read; the sweep is system:write) --\x3e\n <if :="!canTTLStats">\n <div style="opacity:.4; font-size:13px;">TTL entry stats and the expiry sweep need the system:read permission.</div>\n </if>\n <if :="canTTLStats && (!ttlStats || !ttlStats.enabled)">\n <div style="opacity:.4; font-size:13px;">No TTL entries for this type — TTL sub-databases are created lazily on first use.</div>\n </if>\n <if :="canTTLStats && ttlStats && ttlStats.enabled">\n <div style="display:flex; gap:24px; align-items:center; margin-bottom:10px;">\n <div>\n <div style="font-size:18px; font-weight:600; color:var(--okdb-success);">{{ ttlStats.totalEntries }}</div>\n <div style="font-size:11px; opacity:.5;">entries</div>\n </div>\n <div>\n <div :style="\'font-size:18px; font-weight:600; color:\' + (ttlStats.expiredEntries > 0 ? \'var(--okdb-danger)\' : \'var(--okdb-app-fg-muted)\') + \';\'">{{ ttlStats.expiredEntries }}</div>\n <div style="font-size:11px; opacity:.5;">expired</div>\n </div>\n <div>\n <div style="font-size:13px; font-family:monospace; color:var(--okdb-app-fg);">{{ ttlStats.nextExpiry ? fmtDuration(ttlStats.nextExpiry - Date.now()) : \'—\' }}</div>\n <div style="font-size:11px; opacity:.5;">next expiry</div>\n </div>\n </div>\n <div style="display:flex; gap:8px; align-items:center;">\n <button @click="triggerSweep()" :disabled="ttlSweepBusy || !$ok.stores.auth.can(\'system:write\')" class="btn-icon" style="font-size:11px; padding:3px 10px;"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'system:write\') }"\n :title="$ok.stores.auth.permTooltip(\'system:write\')">\n <ok-icon name="refresh-cw"></ok-icon>Sweep expired now\n </button>\n <if :="ttlSweepBusy"><span style="font-size:11px; opacity:.5;">Sweeping…</span></if>\n </div>\n </if>\n </div>\n\n \x3c!-- Danger zone --\x3e\n <div class="card card--danger">\n <div class="manage-section-title" style="color:var(--okdb-danger);">⚠ Danger Zone</div>\n <div style="display:flex; gap:8px; flex-wrap:wrap; align-items:center;">\n <button @click="recomputeFields" class="btn-icon"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.can(\'schema:write\') ? \'Rescan all records to rebuild the field schema\' : $ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="refresh-cw"></ok-icon>Recompute fields\n </button>\n <button @click="dropType" class="btn-danger btn-icon"\n :disabled="!$ok.stores.auth.can(\'schema:write\')"\n :class="{ \'perm-denied\': !$ok.stores.auth.can(\'schema:write\') }"\n :title="$ok.stores.auth.permTooltip(\'schema:write\')">\n <ok-icon name="trash-2"></ok-icon>Drop type\n </button>\n </div>\n </div>\n\n </div>',style:"[tag]{display:flex;flex-direction:column;flex:1;min-width:0;min-height:0}.manage-section-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px}.manage-section-title{font-weight:600;font-size:12px;text-transform:uppercase;letter-spacing:.06em;opacity:.5;margin-bottom:0}.manage-grid{display:grid;gap:0}.manage-grid--2{grid-template-columns:1fr 1fr}.manage-grid--idx{grid-template-columns:minmax(80px,2fr) minmax(90px,1fr) minmax(80px,1fr) auto auto auto}.manage-grid--fts{grid-template-columns:minmax(80px,1fr) 2fr minmax(60px,auto) minmax(50px,auto) auto auto}.manage-grid--vec{grid-template-columns:minmax(80px,1fr) minmax(60px,auto) minmax(80px,1fr) auto}.idx-owned-badge{padding:1px 6px;border-radius:3px;background:color-mix(in srgb,var(--okdb-accent) 12%,transparent);color:var(--okdb-accent);border:1px solid color-mix(in srgb,var(--okdb-accent) 25%,transparent)}.idx-consumer-badge,.idx-kind-badge,.idx-owned-badge{display:inline-block;font-size:10px;white-space:nowrap}.idx-consumer-badge{padding:1px 6px;border-radius:3px;background:color-mix(in srgb,var(--okdb-sky) 12%,transparent);color:var(--okdb-sky);border:1px solid color-mix(in srgb,var(--okdb-sky) 25%,transparent)}.idx-kind-badge{padding:1px 7px;border-radius:999px;border:1px solid}.idx-kind-badge--geo{color:var(--okdb-success);border-color:color-mix(in srgb,var(--okdb-success) 33%,transparent)}.idx-kind-badge--unique{color:var(--okdb-warning);border-color:color-mix(in srgb,var(--okdb-warning) 33%,transparent)}.idx-kind-badge--regular{color:var(--okdb-app-fg-muted);border-color:color-mix(in srgb,var(--okdb-app-fg-muted) 20%,transparent)}.manage-col-hd{font-size:11px;opacity:.4;padding:0 12px 6px 0;border-bottom:1px solid var(--okdb-app-border);font-weight:400}.manage-cell{padding:6px 12px 6px 0;border-bottom:1px solid var(--okdb-app-surface);font-size:13px;display:flex;align-items:center;min-width:0}.manage-cell--dim{opacity:.5;font-size:12px}.manage-status{display:inline-block;padding:1px 7px;border-radius:999px;font-size:10px;border:1px solid}.manage-status--ready{color:var(--okdb-success);border-color:color-mix(in srgb,var(--okdb-success) 33%,transparent)}.manage-status--creating,.manage-status--resetting{color:var(--okdb-warning);border-color:color-mix(in srgb,var(--okdb-warning) 33%,transparent)}.card--danger{border:1px solid color-mix(in srgb,var(--okdb-danger) 13%,transparent)!important}.proc-card__progress{background:var(--okdb-app-border);border-radius:999px;height:4px;overflow:hidden}.proc-card__progress-bar{height:100%;background:var(--okdb-warning);border-radius:999px;transition:width .3s}"};
@@ -252,11 +252,13 @@ export interface OKDBQueryOptions {
252
252
  };
253
253
  /** Index prefix (a single value or an array of leading values). Requires `index`. */
254
254
  prefix?: unknown;
255
- /** Inclusive index-key lower/upper bound. NOT `start`/`end` — those are byIndex/getRange
255
+ /** Index-key lower bound (inclusive) and upper bound (EXCLUSIVE; append `OKDBEnv.HIGH_SENTINEL` to include the last value).
256
+ * Always low/high, also with `reverse`. NOT `start`/`end` — those are byIndex/getRange
256
257
  * names and are not implemented by query(); passing them throws. */
257
258
  startIndex?: OKDBIndexKey;
258
259
  endIndex?: OKDBIndexKey;
259
- /** Primary-key page-boundary hint (cursor-style pagination). */
260
+ /** Primary-key page boundary for cursor-style paging with `index`: `startKey` = the last key of the previous page (that row is
261
+ * skipped, rows sharing its index key are paged correctly), `endKey` = stop before this key. Works forward and with `reverse`. */
260
262
  startKey?: OKDBPrimaryKey;
261
263
  endKey?: OKDBPrimaryKey;
262
264
  limit?: number;
@@ -404,6 +406,8 @@ export interface OKDBIndexDefinition {
404
406
  type?: 'geo';
405
407
  precision?: number;
406
408
  unique?: boolean;
409
+ /** Index only documents that have every indexed field (see {@link OKDBRegisterIndexOptions.sparse}). */
410
+ sparse?: boolean;
407
411
  }
408
412
 
409
413
  export interface OKDBRegisterIndexOptions {
@@ -411,6 +415,13 @@ export interface OKDBRegisterIndexOptions {
411
415
  /** Geohash precision (default 7). */
412
416
  precision?: number;
413
417
  unique?: boolean;
418
+ /**
419
+ * Index only documents that have a non-null value for EVERY indexed field. By default a document missing a field still gets an
420
+ * entry (with `null` in that position), so it can be found by a `null` / prefix query and counts toward the index. With
421
+ * `sparse: true` such documents get no entry at all: writes are cheaper and the index smaller, but they never appear in
422
+ * `byIndex` / `getIndex` / counts on this index. Fixed at registration; not allowed on geo indexes.
423
+ */
424
+ sparse?: boolean;
414
425
  timestamp?: number;
415
426
  }
416
427