@kedem/okdb 2.3.3 → 2.3.4
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/CHANGELOG.md +59 -0
- package/algorithm-worker-thread.js +1 -1
- package/bin/okdb.js +1 -1
- package/docs/auth-and-sync.md +170 -463
- package/docs/auth-permissions.md +3 -1
- package/docs/deployment.md +8 -0
- package/docs/embeddings.md +1 -0
- package/docs/files.md +176 -51
- package/docs/functions.md +1 -1
- package/docs/getting-started.md +40 -13
- package/docs/http-api.md +12 -3
- package/docs/http-cluster.md +25 -0
- package/docs/resolved-fields.md +2 -0
- package/okdb-functions-sandbox-worker.js +1 -1
- package/okdb-http-worker-child.js +1 -1
- package/okdb-views-bootstrap-worker.js +1 -1
- package/okdb.js +1 -1
- package/package.json +1 -1
- package/public/sections/files/parts/files-file-list.ok.js +1 -1
- package/public/sections/files/parts/files-preview.ok.js +1 -0
- package/types/features/files.d.ts +38 -3
- package/types/index.d.ts +18 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kedem/okdb",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
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 t from"./files-upload-panel.ok.js";import e from"../../../stores/events-store.js";import n from"../../../stores/okdb-store.js";export default{tag:"files-file-list",props:["path"],dependencies:[t],context:t=>({busy:!1,files:[],error:null,showUpload:!1,page:0,pageSize:50,totalLoaded:0,_unsubs:[],get path(){return t.$attr.path??"/"},get pagedFiles(){const t=this.page*this.pageSize;return this.files.slice(t,t+this.pageSize)},get totalPages(){return Math.max(1,Math.ceil(this.files.length/this.pageSize))},get hasNext(){return this.page<this.totalPages-1},get hasPrev(){return this.page>0},async load(){const e=t.$attr.path;if(null!=e){this.busy=!0,this.error=null;try{const t=`${n.apiBase}/files?path=${encodeURIComponent(e)}&recursive=true&limit=2000`,i=await fetch(t),o=await i.json();if(!i.ok)throw new Error(o?.error?.message||"failed");this.files=o.data??[],this.page=0}catch(t){this.error=t?.message||String(t),this.files=[]}finally{this.busy=!1}}else this.files=[]},async deleteFile(e){const i=this.filename(e);if(confirm(`Delete "${i}"?\n\nThis will decrement the blob ref-count.`))try{const i=n.apiBase,o=await fetch(`${i}/files/${encodeURIComponent(e.id)}`,{method:"DELETE"});if(!o.ok){const t=await o.json().catch(()=>({}));throw new Error(t?.error?.message||"Delete failed")}this.files=this.files.filter(t=>t.id!==e.id),t.$dispatch("refresh")}catch(t){this.error=t?.message||String(t)}},downloadUrl:t=>`${n.apiBase}/files/${encodeURIComponent(t.id)}`,statusUrl:t=>`${n.apiBase}/files/${encodeURIComponent(t.id)}/status`,filename(t){const e=t.path??"";return e?e.split("/").filter(Boolean).pop():t.id},displayPath(e){const n=e.path??"",i=t.$attr.path??"/";if("/"===i)return n||"/";const o=i.endsWith("/")?i:i+"/";return n.startsWith(o)?n.slice(o.length):n},onUploaded(){this.load(),t.$dispatch("refresh")},fmtSize:t=>null==t?"—":t<1024?t+" B":t<1048576?(t/1024).toFixed(1)+" KB":(t/1048576).toFixed(1)+" MB",fmtDate(t){if(!t)return"—";const e=new Date(t);return e.toLocaleDateString()+" "+e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},mimeColor:t=>t?t.startsWith("image/")?"#7c3aed":t.startsWith("video/")?"#0891b2":t.startsWith("audio/")?"#0d9488":t.startsWith("text/")?"#16a34a":t.includes("pdf")?"#dc2626":t.includes("json")||t.includes("xml")?"#d97706":t.includes("zip")||t.includes("tar")?"#ca8a04":"var(--okdb-mime-default)":"var(--okdb-mime-default)",shortMime(t){if(!t)return"—";const e=t.split("/");return e[1]??e[0]},hashShort:t=>t?t.slice(0,8)+"…":"—"}),watch:{path(){this.showUpload=!1,this.page=0,this.load()}},async mount(){await this.load();const t=()=>this.load();this._unsubs=[e.on("files:uploaded",t),e.on("files:removed",t)]},unmount(){for(const t of this._unsubs)t();this._unsubs=[]},template:'\n<div style="display:flex; flex-direction:column; gap:0; height:100%; min-height:0;">\n\n \x3c!-- ── Toolbar ─────────────────────────────────────────────────────── --\x3e\n <div style="display:flex; align-items:center; justify-content:space-between; gap:8px; flex-wrap:wrap; margin-bottom:10px; flex-shrink:0;">\n <div style="display:flex; align-items:center; gap:8px;">\n <span style="font-family:monospace; font-size:14px; font-weight:700; color:var(--okdb-accent);">{{ path }}</span>\n <span style="font-size:11px; opacity:.4; font-family:monospace;">{{ files.length }} file(s)</span>\n </div>\n <div style="display:flex; gap:6px;">\n <button\n @click="showUpload = !showUpload"\n :style="showUpload ? \'font-size:12px; background:var(--okdb-sky-soft-bg); border-color:var(--okdb-sky-soft-border); color:var(--okdb-sky);\' : \'font-size:12px;\'"\n >{{ showUpload ? \'✕ Close upload\' : \'↑ Upload\' }}</button>\n <button @click="load()" :disabled="busy" style="font-size:12px; opacity:.7;">↻</button>\n </div>\n </div>\n\n \x3c!-- ── Upload panel ────────────────────────────────────────────────── --\x3e\n <if :="showUpload">\n <div style="flex-shrink:0; margin-bottom:10px; padding:12px; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:8px;">\n <files-upload-panel\n :path="path"\n @uploaded="onUploaded()"\n />\n </div>\n </if>\n\n \x3c!-- ── Error ────────────────────────────────────────────────────────── --\x3e\n <if :="error">\n <div style="flex-shrink:0; color:var(--okdb-danger); font-size:12px; margin-bottom:8px; padding:6px 10px; border:1px solid color-mix(in srgb, var(--okdb-danger) 20%, transparent); border-radius:6px; background:var(--okdb-danger-soft-bg);">\n {{ error }}\n </div>\n </if>\n\n \x3c!-- ── Loading ──────────────────────────────────────────────────────── --\x3e\n <if :="busy">\n <div style="flex-shrink:0; font-size:12px; opacity:.4; padding:8px 0;">Loading…</div>\n </if>\n\n \x3c!-- ── Empty state ──────────────────────────────────────────────────── --\x3e\n <if :="!busy && files.length === 0 && !error">\n <div style="flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; opacity:.45;">\n <div style="font-size:32px;">📂</div>\n <div style="font-size:13px;">No files under <code>{{ path }}</code></div>\n <button @click="showUpload = true" style="font-size:12px; background:var(--okdb-sky-soft-bg); border-color:var(--okdb-sky-soft-border); color:var(--okdb-sky);">\n ↑ Upload a file\n </button>\n </div>\n </if>\n\n \x3c!-- ── Table ────────────────────────────────────────────────────────── --\x3e\n <if :="files.length > 0">\n <div style="flex:1; overflow:auto; min-height:0;">\n <table style="width:100%; border-collapse:collapse; font-size:12px; white-space:nowrap;">\n <thead style="position:sticky; top:0; z-index:2; background:var(--okdb-app-bg-deep);">\n <tr style="border-bottom:1px solid var(--okdb-app-border);">\n <th style="text-align:left; padding:6px 10px; font-weight:500; opacity:.6; font-size:11px;">Path / Name</th>\n <th style="text-align:left; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Type</th>\n <th style="text-align:right; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Size</th>\n <th style="text-align:left; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Hash</th>\n <th style="text-align:left; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Uploaded</th>\n <th style="text-align:center; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Actions</th>\n </tr>\n </thead>\n <tbody>\n <tr as="repeat" :of="pagedFiles" let:item="f" class="file-row">\n\n \x3c!-- Path / name --\x3e\n <td style="padding:6px 10px; max-width:300px;">\n <div style="display:flex; align-items:center; gap:6px;">\n <span style="font-size:13px; flex-shrink:0;">{{ (f.mime || \'\').startsWith(\'image/\') ? \'🖼\' : (f.mime || \'\').startsWith(\'video/\') ? \'🎬\' : (f.mime || \'\').startsWith(\'audio/\') ? \'🎵\' : (f.mime || \'\').includes(\'pdf\') ? \'📄\' : \'📎\' }}</span>\n <div style="overflow:hidden;">\n <div style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-family:monospace; font-size:11px; color:var(--okdb-app-fg-strong);" :title="f.path">\n {{ displayPath(f) }}\n </div>\n <div style="font-size:10px; opacity:.3; font-family:monospace; overflow:hidden; text-overflow:ellipsis;">\n {{ f.id ? f.id.slice(0,8) : \'\' }}…\n </div>\n </div>\n </div>\n </td>\n\n \x3c!-- MIME badge --\x3e\n <td style="padding:6px 8px;">\n <span :style="\'display:inline-block; padding:2px 7px; border-radius:999px; font-size:10px; font-family:monospace; background:\' + mimeColor(f.mime) + \'22; color:\' + mimeColor(f.mime) + \'; border:1px solid \' + mimeColor(f.mime) + \'44;\'">\n {{ shortMime(f.mime) }}\n </span>\n </td>\n\n \x3c!-- Size --\x3e\n <td style="padding:6px 8px; text-align:right; font-family:monospace; font-size:11px; opacity:.7;">\n {{ fmtSize(f.size) }}\n </td>\n\n \x3c!-- Hash --\x3e\n <td style="padding:6px 8px; font-family:monospace; font-size:10px; opacity:.4;" :title="f.hash">\n {{ hashShort(f.hash) }}\n </td>\n\n \x3c!-- Date --\x3e\n <td style="padding:6px 8px; font-size:11px; opacity:.5;">\n {{ fmtDate(f.createdAt) }}\n </td>\n\n \x3c!-- Actions --\x3e\n <td style="padding:6px 8px; text-align:center; white-space:nowrap;">\n <a\n :href="downloadUrl(f)"\n :download="filename(f)"\n style="display:inline-flex; align-items:center; justify-content:center; width:26px; height:22px; color:var(--okdb-sky); font-size:12px; text-decoration:none; border:1px solid var(--okdb-sky-soft-border); border-radius:4px; margin-right:4px;"\n title="Download"\n >↓</a>\n <button\n @click="deleteFile(f)"\n style="width:26px; height:22px; font-size:11px; padding:0; color:var(--okdb-danger); border-color:#5a1e1e44; background:var(--okdb-danger-soft-bg);"\n title="Delete"\n >🗑</button>\n </td>\n\n </tr>\n </tbody>\n </table>\n </div>\n\n \x3c!-- ── Pagination ──────────────────────────────────────────────────── --\x3e\n <div class="ok-pager">\n <button @click="page--" :disabled="!hasPrev">‹ Prev</button>\n <span>Page {{ page + 1 }} / {{ totalPages }} · {{ files.length }} total</span>\n <button @click="page++" :disabled="!hasNext">Next ›</button>\n </div>\n </if>\n\n</div>',style:"\n[tag] .file-row { border-bottom: 1px solid var(--okdb-app-bg); transition: background .1s; }\n[tag] .file-row:hover { background: var(--okdb-app-bg-deep); }\n"};
|
|
1
|
+
import e,{previewKind as t}from"./files-preview.ok.js";import n from"./files-upload-panel.ok.js";import i from"../../../stores/events-store.js";import s from"../../../stores/okdb-store.js";const o="~files";function a(e,t){const n=e.toLowerCase();let i=-1,s=0;for(const e of t){const t=n.indexOf(e);t>=0&&(i<0||t<i)&&(i=t,s=e.length)}if(i<0)return null;const o=e=>e.replace(/\s+/g," "),a=Math.max(0,i-70),r=Math.min(e.length,i+s+90);return{before:(a>0?"…":"")+o(e.slice(a,i)),hit:e.slice(i,i+s),after:o(e.slice(i+s,r))+(r<e.length?"…":"")}}export default{tag:"files-file-list",props:["path"],dependencies:[n,e],context:e=>({busy:!1,files:[],error:null,showUpload:!1,page:0,pageSize:50,totalLoaded:0,_unsubs:[],searchMode:"path",pathQuery:"",contentQuery:"",ftsIndex:null,ftsChecked:!1,hits:[],hitsHidden:0,searching:!1,searchError:null,searchTime:null,_searchSeq:0,snippets:{},selected:null,highlight:"",get path(){return e.$attr.path??"/"},get filteredFiles(){const e=this.pathQuery.trim().toLowerCase();return e?this.files.filter(t=>(t.path??"").toLowerCase().includes(e)||t.id===e):this.files},get pagedFiles(){const e=this.page*this.pageSize;return this.filteredFiles.slice(e,e+this.pageSize)},get totalPages(){return Math.max(1,Math.ceil(this.filteredFiles.length/this.pageSize))},get listCapped(){return this.files.length>=2e3},get showContent(){return"content"===this.searchMode},get hasNext(){return this.page<this.totalPages-1},get hasPrev(){return this.page>0},async load(){const t=e.$attr.path;if(null!=t){this.busy=!0,this.error=null;try{const e=`${s.apiBase}/files?path=${encodeURIComponent(t)}&recursive=true&limit=2000`,n=await fetch(e),i=await n.json();if(!n.ok)throw new Error(i?.error?.message||"failed");this.files=i.data??[],this.page=0}catch(e){this.error=e?.message||String(e),this.files=[]}finally{this.busy=!1}}else this.files=[]},async deleteFile(t,n){n?.stopPropagation?.();const i=this.filename(t);if(confirm(`Delete "${i}"?\n\nThis will decrement the blob ref-count.`))try{const n=s.apiBase,i=await fetch(`${n}/files/${encodeURIComponent(t.id)}`,{method:"DELETE"});if(!i.ok){const e=await i.json().catch(()=>({}));throw new Error(e?.error?.message||"Delete failed")}this.files=this.files.filter(e=>e.id!==t.id),this.hits=this.hits.filter(e=>e.id!==t.id),this.selected?.id===t.id&&this.closePreview(),e.$dispatch("refresh")}catch(e){this.error=e?.message||String(e)}},openPreview(e,t=""){this.selected=e,this.highlight=t},closePreview(){this.selected=null,this.highlight=""},isSelected(e){return this.selected?.id===e.id},onPathFilter(e){this.pathQuery=e,this.page=0},async loadFts(){try{const e=await fetch(`${s.apiBase}/type/${encodeURIComponent(o)}/fts`),t=await e.json().catch(()=>({})),n=e.ok?t.data??t.result??[]:[],i=e=>e?.config?.fields??[],a=n.find(e=>i(e).includes("content")||i(e).includes("*"))??n[0];this.ftsIndex=a?{name:a.name,fields:i(a),lag:a.lag??0,processorState:a.processorState??null}:null}catch{this.ftsIndex=null}finally{this.ftsChecked=!0}},async setSearchMode(e){this.searchMode=e,"content"===e&&await this.loadFts()},async runContentSearch(e){void 0!==e&&(this.contentQuery=e);const t=this.contentQuery.trim(),n=++this._searchSeq;if(this.searchError=null,!t||!this.ftsIndex)return this.hits=[],this.hitsHidden=0,void(this.searchTime=null);this.searching=!0;try{const e=`${s.apiBase}/type/${encodeURIComponent(o)}/fts/${encodeURIComponent(this.ftsIndex.name)}/search`,i=await fetch(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({query:t,options:{limit:50,mode:"and",prefix:!0}})}),a=await i.json().catch(()=>({}));if(!i.ok)throw new Error(a?.error?.message||`HTTP ${i.status}`);if(n!==this._searchSeq)return;const r=(a.data??a.result??[]).map(e=>({...e.value??{},id:e.value?.id??e.key,_score:e.score})).filter(e=>e.id),l=r.filter(e=>this.inFolder(e));this.hits=l,this.hitsHidden=r.length-l.length,this.searchTime=a.meta?.time??null,this.snippets={},this.loadSnippets(l,t,n)}catch(e){n===this._searchSeq&&(this.searchError=e?.message||String(e),this.hits=[])}finally{n===this._searchSeq&&(this.searching=!1)}},inFolder(t){const n=e.$attr.path??"/";if("/"===n)return!0;const i=n.endsWith("/")?n:n+"/";return(t.path??"").startsWith(i)},async loadSnippets(e,n,i){const o=n.toLowerCase().split(/[^\p{L}\p{N}_]+/u).filter(e=>e.length>=2);if(!o.length)return;const r=e.filter(e=>"text"===t(e)&&e.size>0).slice(0,12);await Promise.all(r.map(async e=>{try{const t=await fetch(`${s.apiBase}/files/${encodeURIComponent(e.id)}?inline=1`,{headers:{range:"bytes=0-16383"}});if(!t.ok)return;const n=new TextDecoder("utf-8").decode(new Uint8Array(await t.arrayBuffer()).subarray(0,16384));if(i!==this._searchSeq)return;this.snippets={...this.snippets,[e.id]:a(n,o)}}catch{}}))},snippetOf(e){return this.snippets[e.id]??null},downloadUrl:e=>`${s.apiBase}/files/${encodeURIComponent(e.id)}`,statusUrl:e=>`${s.apiBase}/files/${encodeURIComponent(e.id)}/status`,filename(e){const t=e.path??"";return t?t.split("/").filter(Boolean).pop():e.id},displayPath(t){const n=t.path??"",i=e.$attr.path??"/";if("/"===i)return n||"/";const s=i.endsWith("/")?i:i+"/";return n.startsWith(s)?n.slice(s.length):n},onUploaded(){this.load(),e.$dispatch("refresh")},fmtSize:e=>null==e?"—":e<1024?e+" B":e<1048576?(e/1024).toFixed(1)+" KB":(e/1048576).toFixed(1)+" MB",fmtDate(e){if(!e)return"—";const t=new Date(e);return t.toLocaleDateString()+" "+t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},mimeColor:e=>e?e.startsWith("image/")?"#7c3aed":e.startsWith("video/")?"#0891b2":e.startsWith("audio/")?"#0d9488":e.startsWith("text/")?"#16a34a":e.includes("pdf")?"#dc2626":e.includes("json")||e.includes("xml")?"#d97706":e.includes("zip")||e.includes("tar")?"#ca8a04":"var(--okdb-mime-default)":"var(--okdb-mime-default)",shortMime(e){if(!e)return"—";const t=e.split("/");return t[1]??t[0]},hashShort:e=>e?e.slice(0,8)+"…":"—"}),async mount(e){e.$watch(()=>e.$attr.path,()=>{this.showUpload=!1,this.page=0,this.pathQuery="",this.closePreview(),this.load(),this.contentQuery.trim()&&this.runContentSearch()}),this.loadFts(),await this.load();const t=()=>this.load();this._unsubs=[i.on("files:uploaded",t),i.on("files:removed",t)]},unmount(){for(const e of this._unsubs)e();this._unsubs=[]},template:'\n<div style="display:flex; gap:12px; height:100%; min-height:0;">\n\n\x3c!-- ═══ List column ═══════════════════════════════════════════════════ --\x3e\n<div class="fl-col">\n\n \x3c!-- ── Toolbar ─────────────────────────────────────────────────────── --\x3e\n <div style="display:flex; align-items:center; justify-content:space-between; gap:8px; flex-wrap:wrap; margin-bottom:8px; flex-shrink:0;">\n <div style="display:flex; align-items:center; gap:8px;">\n <span style="font-family:monospace; font-size:14px; font-weight:700; color:var(--okdb-accent);">{{ path }}</span>\n <span style="font-size:11px; opacity:.4; font-family:monospace;">{{ files.length }} file(s)</span>\n </div>\n <div style="display:flex; gap:6px;">\n <button\n @click="showUpload = !showUpload"\n :style="showUpload ? \'font-size:12px; background:var(--okdb-sky-soft-bg); border-color:var(--okdb-sky-soft-border); color:var(--okdb-sky);\' : \'font-size:12px;\'"\n >{{ showUpload ? \'✕ Close upload\' : \'↑ Upload\' }}</button>\n <button @click="load()" :disabled="busy" style="font-size:12px; opacity:.7;">↻</button>\n </div>\n </div>\n\n \x3c!-- ── Search bar ──────────────────────────────────────────────────── --\x3e\n <div style="display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-bottom:10px; flex-shrink:0;">\n <div class="seg-toggle" style="font-size:11.5px;" title="Path: filter this folder by name · Content: full-text search inside files">\n <button :class="searchMode === \'path\' ? \'active\' : \'\'" @click="setSearchMode(\'path\')">Path</button>\n <button :class="searchMode === \'content\' ? \'active\' : \'\'" @click="setSearchMode(\'content\')">Content</button>\n </div>\n\n <if :="searchMode === \'path\'">\n <input\n type="text"\n class="fl-search"\n placeholder="Filter by path…"\n :value="pathQuery"\n @input:debounce.150="onPathFilter($event.target.value)"\n />\n <if :="pathQuery">\n <span style="font-size:11px; opacity:.5; font-family:monospace;">{{ filteredFiles.length }} match(es)</span>\n </if>\n </if>\n\n <if :="searchMode === \'content\' && ftsIndex">\n <input\n type="text"\n class="fl-search"\n placeholder="Search file contents…"\n :value="contentQuery"\n @input:debounce.300="runContentSearch($event.target.value)"\n @keydown:enter="runContentSearch($event.target.value)"\n />\n <span style="font-size:10.5px; opacity:.45; font-family:monospace;" :title="\'FTS index on ~files: \' + ftsIndex.name">\n fts:{{ ftsIndex.name }} [{{ ftsIndex.fields.join(\', \') }}]{{ ftsIndex.lag > 0 ? \' · indexing, \' + ftsIndex.lag + \' behind\' : \'\' }}\n </span>\n </if>\n </div>\n\n \x3c!-- ── Content search: no index yet → how to enable it ─────────────── --\x3e\n <if :="showContent && ftsChecked && !ftsIndex">\n <div class="fl-hint">\n <div style="font-weight:600; margin-bottom:4px;">Content search is not enabled in this environment</div>\n <div style="opacity:.75; margin-bottom:6px;">It needs a full-text index on <code>~files</code> that covers file contents. Once, from code:</div>\n <pre>await db.files.indexContent();\nawait db.fts.ensure(\'~files\', \'text\', { fields: [\'path\', \'content\'] });</pre>\n <div style="opacity:.6; margin-top:6px;">Text, JSON and XML are extracted out of the box; register an extractor for PDF/Office (see <code>docs/files.md</code> → Searching file contents).\n <button @click="setSearchMode(\'content\')" style="font-size:11px; padding:1px 8px; margin-left:4px;">Re-check</button>\n </div>\n </div>\n </if>\n\n \x3c!-- ── Upload panel ────────────────────────────────────────────────── --\x3e\n <if :="showUpload">\n <div style="flex-shrink:0; margin-bottom:10px; padding:12px; background:var(--okdb-app-bg-deep); border:1px solid var(--okdb-app-border); border-radius:8px;">\n <files-upload-panel\n :path="path"\n @uploaded="onUploaded()"\n />\n </div>\n </if>\n\n \x3c!-- ── Error ────────────────────────────────────────────────────────── --\x3e\n <if :="error">\n <div style="flex-shrink:0; color:var(--okdb-danger); font-size:12px; margin-bottom:8px; padding:6px 10px; border:1px solid color-mix(in srgb, var(--okdb-danger) 20%, transparent); border-radius:6px; background:var(--okdb-danger-soft-bg);">\n {{ error }}\n </div>\n </if>\n\n \x3c!-- ═══ Content search results ═════════════════════════════════════ --\x3e\n <if :="showContent && ftsIndex">\n <div style="flex:1; overflow:auto; min-height:0;">\n <if :="searchError">\n <div style="color:var(--okdb-danger); font-size:12px; padding:6px 0;">{{ searchError }}</div>\n </if>\n <if :="!contentQuery.trim()">\n <div style="font-size:12px; opacity:.45; padding:14px 2px;">Type to search inside the files{{ path === \'/\' ? \'\' : \' under \' + path }}.</div>\n </if>\n <if :="contentQuery.trim() && !searching && !searchError">\n <div style="font-size:11px; opacity:.5; font-family:monospace; padding:0 2px 6px;">\n {{ hits.length }} hit(s){{ searchTime != null ? \' · \' + searchTime + \' ms\' : \'\' }}{{ hitsHidden ? \' · \' + hitsHidden + \' more outside \' + path : \'\' }}{{ hits.length + hitsHidden >= 50 ? \' · top 50 only\' : \'\' }}\n </div>\n </if>\n <if :="searching">\n <div style="font-size:12px; opacity:.4; padding:8px 2px;">Searching…</div>\n </if>\n <each :of="hits" let:item="h">\n <button :class="isSelected(h) ? \'fl-hit fl-hit--on\' : \'fl-hit\'" @click="openPreview(h, contentQuery)">\n <div style="display:flex; align-items:center; gap:8px; min-width:0;">\n <span style="font-family:monospace; font-size:11.5px; color:var(--okdb-app-fg-strong); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; flex:1; text-align:left;" :title="h.path">{{ h.path || h.id }}</span>\n <span :style="\'flex-shrink:0; padding:1px 6px; border-radius:999px; font-size:9.5px; font-family:monospace; background:\' + mimeColor(h.mime) + \'22; color:\' + mimeColor(h.mime) + \';\'">{{ shortMime(h.mime) }}</span>\n <span style="flex-shrink:0; font-size:10px; opacity:.4; font-family:monospace;">{{ fmtSize(h.size) }}</span>\n </div>\n <if :="snippetOf(h)">\n <div class="fl-snip">{{ snippetOf(h).before }}<mark>{{ snippetOf(h).hit }}</mark>{{ snippetOf(h).after }}</div>\n </if>\n </button>\n </each>\n </div>\n </if>\n\n \x3c!-- ═══ Folder listing (path mode) ═════════════════════════════════ --\x3e\n <if :="!showContent">\n\n \x3c!-- ── Loading ──────────────────────────────────────────────────────── --\x3e\n <if :="busy">\n <div style="flex-shrink:0; font-size:12px; opacity:.4; padding:8px 0;">Loading…</div>\n </if>\n\n \x3c!-- ── Empty state ──────────────────────────────────────────────────── --\x3e\n <if :="!busy && files.length === 0 && !error">\n <div style="flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; opacity:.45;">\n <div style="font-size:32px;">📂</div>\n <div style="font-size:13px;">No files under <code>{{ path }}</code></div>\n <button @click="showUpload = true" style="font-size:12px; background:var(--okdb-sky-soft-bg); border-color:var(--okdb-sky-soft-border); color:var(--okdb-sky);">\n ↑ Upload a file\n </button>\n </div>\n </if>\n\n <if :="files.length > 0 && filteredFiles.length === 0">\n <div style="font-size:12px; opacity:.5; padding:14px 2px;">No paths under <code>{{ path }}</code> contain “{{ pathQuery }}”.</div>\n </if>\n\n \x3c!-- ── Table ────────────────────────────────────────────────────────── --\x3e\n <if :="filteredFiles.length > 0">\n <div style="flex:1; overflow:auto; min-height:0;">\n <table style="width:100%; border-collapse:collapse; font-size:12px; white-space:nowrap;">\n <thead style="position:sticky; top:0; z-index:2; background:var(--okdb-app-bg-deep);">\n <tr style="border-bottom:1px solid var(--okdb-app-border);">\n <th style="text-align:left; padding:6px 10px; font-weight:500; opacity:.6; font-size:11px;">Path / Name</th>\n <th style="text-align:left; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Type</th>\n <th style="text-align:right; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Size</th>\n <th style="text-align:left; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Hash</th>\n <th style="text-align:left; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Uploaded</th>\n <th style="text-align:center; padding:6px 8px; font-weight:500; opacity:.6; font-size:11px;">Actions</th>\n </tr>\n </thead>\n <tbody>\n <tr as="repeat" :of="pagedFiles" let:item="f" :class="isSelected(f) ? \'file-row file-row--on\' : \'file-row\'" @click="openPreview(f)" title="Click to preview">\n\n \x3c!-- Path / name --\x3e\n <td style="padding:6px 10px; max-width:300px;">\n <div style="display:flex; align-items:center; gap:6px;">\n <span style="font-size:13px; flex-shrink:0;">{{ (f.mime || \'\').startsWith(\'image/\') ? \'🖼\' : (f.mime || \'\').startsWith(\'video/\') ? \'🎬\' : (f.mime || \'\').startsWith(\'audio/\') ? \'🎵\' : (f.mime || \'\').includes(\'pdf\') ? \'📄\' : \'📎\' }}</span>\n <div style="overflow:hidden;">\n <div style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-family:monospace; font-size:11px; color:var(--okdb-app-fg-strong);" :title="f.path">\n {{ displayPath(f) }}\n </div>\n <div style="font-size:10px; opacity:.3; font-family:monospace; overflow:hidden; text-overflow:ellipsis;">\n {{ f.id ? f.id.slice(0,8) : \'\' }}…\n </div>\n </div>\n </div>\n </td>\n\n \x3c!-- MIME badge --\x3e\n <td style="padding:6px 8px;">\n <span :style="\'display:inline-block; padding:2px 7px; border-radius:999px; font-size:10px; font-family:monospace; background:\' + mimeColor(f.mime) + \'22; color:\' + mimeColor(f.mime) + \'; border:1px solid \' + mimeColor(f.mime) + \'44;\'">\n {{ shortMime(f.mime) }}\n </span>\n </td>\n\n \x3c!-- Size --\x3e\n <td style="padding:6px 8px; text-align:right; font-family:monospace; font-size:11px; opacity:.7;">\n {{ fmtSize(f.size) }}\n </td>\n\n \x3c!-- Hash --\x3e\n <td style="padding:6px 8px; font-family:monospace; font-size:10px; opacity:.4;" :title="f.hash">\n {{ hashShort(f.hash) }}\n </td>\n\n \x3c!-- Date --\x3e\n <td style="padding:6px 8px; font-size:11px; opacity:.5;">\n {{ fmtDate(f.createdAt) }}\n </td>\n\n \x3c!-- Actions --\x3e\n <td style="padding:6px 8px; text-align:center; white-space:nowrap;">\n <a\n :href="downloadUrl(f)"\n :download="filename(f)"\n @click="$event.stopPropagation()"\n style="display:inline-flex; align-items:center; justify-content:center; width:26px; height:22px; color:var(--okdb-sky); font-size:12px; text-decoration:none; border:1px solid var(--okdb-sky-soft-border); border-radius:4px; margin-right:4px;"\n title="Download"\n >↓</a>\n <button\n @click="deleteFile(f, $event)"\n style="width:26px; height:22px; font-size:11px; padding:0; color:var(--okdb-danger); border-color:#5a1e1e44; background:var(--okdb-danger-soft-bg);"\n title="Delete"\n >🗑</button>\n </td>\n\n </tr>\n </tbody>\n </table>\n </div>\n\n \x3c!-- ── Pagination ──────────────────────────────────────────────────── --\x3e\n <div class="ok-pager">\n <button @click="page--" :disabled="!hasPrev">‹ Prev</button>\n <span>Page {{ page + 1 }} / {{ totalPages }} · {{ filteredFiles.length }}{{ pathQuery ? \' of \' + files.length : \'\' }} total{{ listCapped ? \' (first 2000 loaded)\' : \'\' }}</span>\n <button @click="page++" :disabled="!hasNext">Next ›</button>\n </div>\n </if>\n\n </if>\n</div>\n\n\x3c!-- ═══ Preview column ═══════════════════════════════════════════════ --\x3e\n<if :="selected">\n <div class="fl-preview">\n <files-preview :file="selected" :highlight="highlight" @close="closePreview()" />\n </div>\n</if>\n\n</div>',style:"\n[tag] .fl-col { flex:1 1 55%; min-width:0; display:flex; flex-direction:column; min-height:0; }\n[tag] .fl-preview { flex:1 1 45%; min-width:320px; min-height:0; display:flex; flex-direction:column; }\n[tag] .fl-preview > files-preview { flex:1; min-height:0; display:block; }\n[tag] .fl-search { flex:1; min-width:160px; max-width:360px; font-size:12px; }\n[tag] .fl-hint { flex-shrink:0; font-size:12px; line-height:1.5; margin-bottom:10px; padding:10px 12px; border:1px dashed var(--okdb-app-border-strong); border-radius:8px; background:var(--okdb-app-bg-deep); }\n[tag] .fl-hint pre { margin:0; padding:6px 8px; font-size:11px; border-radius:5px; background:var(--okdb-app-bg); color:var(--okdb-accent); white-space:pre-wrap; }\n[tag] .fl-hint code { font-size:11px; }\n[tag] .fl-hit { display:flex; flex-direction:column; gap:4px; width:100%; text-align:left; padding:7px 10px; margin-bottom:4px; border-radius:6px; border:1px solid var(--okdb-app-border); background:var(--okdb-app-bg-deep); cursor:pointer; }\n[tag] .fl-hit:hover { background:var(--okdb-app-surface); }\n[tag] .fl-hit--on { background:var(--okdb-accent-soft-bg); border-color:var(--okdb-accent-soft-border); }\n[tag] .fl-snip { font-size:11px; line-height:1.45; opacity:.75; font-family:monospace; white-space:normal; word-break:break-word; }\n[tag] .fl-snip mark { background:color-mix(in srgb, var(--okdb-warning) 38%, transparent); color:inherit; border-radius:2px; padding:0 1px; }\n[tag] .file-row { border-bottom: 1px solid var(--okdb-app-bg); transition: background .1s; cursor: pointer; }\n[tag] .file-row:hover { background: var(--okdb-app-bg-deep); }\n[tag] .file-row--on, [tag] .file-row--on:hover { background: var(--okdb-accent-soft-bg); }\n@media (max-width: 900px) {\n [tag] > div { flex-direction: column; }\n [tag] .fl-preview { min-width:0; flex-basis:auto; max-height:60vh; }\n}\n"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"../../../stores/okdb-store.js";const i=/\.(txt|text|md|markdown|log|csv|tsv|json|jsonl|ndjson|ya?ml|toml|ini|conf|cfg|env|xml|html?|css|js|mjs|cjs|ts|tsx|jsx|py|rb|go|rs|java|kt|c|h|cc|cpp|hpp|cs|php|sh|bash|zsh|sql|graphql|proto|vue|svelte)$/i;function t(e){return String(e||"").split(";")[0].trim().toLowerCase()}export function previewKind(e){const n=t(e?.mime),r=String(e?.path||"");return"image/svg+xml"===n||!n.startsWith("image/")&&/\.svg$/i.test(r)?"svg":n.startsWith("image/")?"image":"application/pdf"===n?"pdf":n.startsWith("audio/")?"audio":n.startsWith("video/")?"video":n.startsWith("text/")||"application/json"===n||"application/xml"===n||"application/javascript"===n||"application/x-ndjson"===n||"application/yaml"===n||n.endsWith("+json")||n.endsWith("+xml")?"text":n&&"application/octet-stream"!==n||!i.test(r)?"other":"text"}export default{tag:"files-preview",props:["file","highlight"],context:i=>({loading:!1,error:null,text:"",truncated:!1,binary:!1,pretty:!1,svgUrl:null,mediaError:!1,_seq:0,get file(){return i.$attr.file??null},get kind(){return previewKind(this.file)},get inlineUrl(){const i=this.file;return i?`${e.apiBase}/files/${encodeURIComponent(i.id)}?inline=1`:""},get downloadUrl(){const i=this.file;return i?`${e.apiBase}/files/${encodeURIComponent(i.id)}`:""},get filename(){const e=this.file?.path??"";return e?e.split("/").filter(Boolean).pop():this.file?.id??""},get terms(){const e=String(i.$attr.highlight??"").toLowerCase(),t=new Set;for(const i of e.split(/[^\p{L}\p{N}_]+/u))i.length>=2&&t.add(i);return[...t]},get segments(){const e=this.text,i=this.terms;if(!e||0===i.length)return[{t:e,hit:!1}];const t=new RegExp(i.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),"giu"),n=[];let r,a=0,o=0;for(;(r=t.exec(e))&&o<500;)r.index>a&&n.push({t:e.slice(a,r.index),hit:!1}),n.push({t:r[0],hit:!0}),a=r.index+r[0].length,o++;return a<e.length&&n.push({t:e.slice(a),hit:!1}),n},get markCount(){return this.segments.filter(e=>e.hit).length},_revokeSvg(){this.svgUrl&&URL.revokeObjectURL(this.svgUrl),this.svgUrl=null},async load(){const e=++this._seq,i=this.file;if(this.error=null,this.text="",this.truncated=!1,this.binary=!1,this.pretty=!1,this.mediaError=!1,this._revokeSvg(),!i)return;const n=this.kind;if(("text"===n||"svg"===n)&&i.size)if("svg"===n&&i.size>2097152)this.error=`SVG is ${this.fmtSize(i.size)} — too large to preview. Download it instead.`;else{this.loading=!0;try{const r="text"===n?{range:"bytes=0-65535"}:{},a=await fetch(this.inlineUrl,{headers:r});if(!a.ok)throw new Error(`HTTP ${a.status}`);const o=new Uint8Array(await a.arrayBuffer());if(e!==this._seq)return;if("svg"===n)return void(this.svgUrl=URL.createObjectURL(new Blob([o],{type:"image/svg+xml"})));const s=o.subarray(0,65536);this.truncated=(i.size??s.length)>s.length,this.binary=s.subarray(0,8192).includes(0);let d=new TextDecoder("utf-8").decode(s);if(!this.truncated&&function(e){const i=t(e?.mime);return"application/json"===i||i.endsWith("+json")||/\.json$/i.test(String(e?.path||""))}(i))try{d=JSON.stringify(JSON.parse(d),null,2),this.pretty=!0}catch{}this.text=d,this.scrollToMark()}catch(i){e===this._seq&&(this.error=i?.message||String(i))}finally{e===this._seq&&(this.loading=!1)}}},scrollToMark(){this.terms.length&&this.text&&requestAnimationFrame(()=>i.$el?.querySelector?.(".fp-text mark")?.scrollIntoView?.({block:"center"}))},close(){i.$dispatch("close")},fmtSize:e=>null==e?"—":e<1024?e+" B":e<1048576?(e/1024).toFixed(1)+" KB":e<1073741824?(e/1048576).toFixed(1)+" MB":(e/1073741824).toFixed(2)+" GB",fmtDate:e=>e?new Date(e).toLocaleString():"—"}),async mount(e){e.$watch(()=>e.$attr.file?.id,()=>this.load()),e.$watch(()=>e.$attr.highlight,()=>this.scrollToMark()),await this.load()},unmount(){this._seq++,this._revokeSvg()},template:'\n<div class="fp">\n\n \x3c!-- ── Header ──────────────────────────────────────────────────────── --\x3e\n <div class="fp-head">\n <div style="min-width:0; flex:1;">\n <div class="fp-name" :title="file?.path">{{ filename }}</div>\n <div class="fp-sub" :title="file?.path">{{ file?.path || file?.id }}</div>\n </div>\n <div style="display:flex; gap:4px; flex-shrink:0;">\n <a class="fp-btn" :href="inlineUrl" target="_blank" rel="noopener noreferrer" title="Open in a new tab (sandboxed)">↗</a>\n <a class="fp-btn" :href="downloadUrl" :download="filename" title="Download">↓</a>\n <button class="fp-btn" @click="close()" title="Close preview">✕</button>\n </div>\n </div>\n\n \x3c!-- ── Metadata ────────────────────────────────────────────────────── --\x3e\n <div class="fp-meta">\n <span><b>type</b> {{ file?.mime || \'—\' }}</span>\n <span><b>size</b> {{ fmtSize(file?.size) }}</span>\n <span><b>uploaded</b> {{ fmtDate(file?.createdAt) }}</span>\n <span :title="file?.hash"><b>sha256</b> {{ file?.hash ? file.hash.slice(0, 12) + \'…\' : \'—\' }}</span>\n </div>\n\n \x3c!-- ── Body ────────────────────────────────────────────────────────── --\x3e\n <div class="fp-body">\n\n <if :="error">\n <div class="fp-note fp-note--err">{{ error }}</div>\n </if>\n\n <if :="loading">\n <div class="fp-note">Loading preview…</div>\n </if>\n\n \x3c!-- text / JSON --\x3e\n <if :="kind === \'text\' && !loading && !error">\n <if :="!file?.size">\n <div class="fp-note">Empty file.</div>\n </if>\n <if :="file?.size">\n <if :="binary">\n <div class="fp-note fp-note--warn">Looks binary (NUL bytes in the first 8 KB) — shown as UTF-8 anyway.</div>\n </if>\n <if :="terms.length">\n <div class="fp-note">{{ markCount }}{{ markCount >= 500 ? \'+\' : \'\' }} match(es) for <code>{{ terms.join(\' \') }}</code>{{ truncated ? \' in the first 64 KB\' : \'\' }}</div>\n </if>\n <pre class="fp-text"><each :of="segments" let:item="s"><if :="s.hit"><mark>{{ s.t }}</mark></if><if :="!s.hit">{{ s.t }}</if></each></pre>\n <if :="truncated">\n <div class="fp-note">Showing the first 64 KB of {{ fmtSize(file?.size) }} — download for the full file.</div>\n </if>\n </if>\n </if>\n\n \x3c!-- image --\x3e\n <if :="kind === \'image\'">\n <if :="!mediaError">\n <div class="fp-media fp-checker">\n <img :src="inlineUrl" :alt="filename" @error="mediaError = true" />\n </div>\n </if>\n <if :="mediaError">\n <div class="fp-note fp-note--err">The browser could not render this image.</div>\n </if>\n </if>\n\n \x3c!-- SVG (blob: URL inside <img> — scripts never run) --\x3e\n <if :="kind === \'svg\' && svgUrl">\n <div class="fp-media fp-checker">\n <img :src="svgUrl" :alt="filename" />\n </div>\n </if>\n\n \x3c!-- PDF --\x3e\n <if :="kind === \'pdf\'">\n <iframe class="fp-frame" :src="inlineUrl" :title="filename"></iframe>\n </if>\n\n \x3c!-- audio --\x3e\n <if :="kind === \'audio\'">\n <div class="fp-media" style="padding:24px 12px;">\n <audio controls preload="metadata" :src="inlineUrl" style="width:100%;" @error="mediaError = true"></audio>\n </div>\n <if :="mediaError">\n <div class="fp-note fp-note--err">The browser cannot play this audio format.</div>\n </if>\n </if>\n\n \x3c!-- video --\x3e\n <if :="kind === \'video\'">\n <div class="fp-media" style="background:#000;">\n <video controls preload="metadata" :src="inlineUrl" @error="mediaError = true"></video>\n </div>\n <if :="mediaError">\n <div class="fp-note fp-note--err">The browser cannot play this video format.</div>\n </if>\n </if>\n\n \x3c!-- anything else --\x3e\n <if :="kind === \'other\'">\n <div class="fp-empty">\n <div style="font-size:30px;">📎</div>\n <div>No inline preview for <code>{{ file?.mime || \'unknown type\' }}</code>.</div>\n <a class="fp-dl" :href="downloadUrl" :download="filename">↓ Download {{ fmtSize(file?.size) }}</a>\n </div>\n </if>\n\n </div>\n</div>',style:"\n[tag] .fp { display:flex; flex-direction:column; height:100%; min-height:0; border:1px solid var(--okdb-app-border); border-radius:8px; background:var(--okdb-app-bg-deep); overflow:hidden; }\n[tag] .fp-head { display:flex; align-items:flex-start; gap:8px; padding:8px 10px; border-bottom:1px solid var(--okdb-app-border); flex-shrink:0; }\n[tag] .fp-name { font-family:monospace; font-size:12.5px; font-weight:700; color:var(--okdb-app-fg-strong); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }\n[tag] .fp-sub { font-family:monospace; font-size:10.5px; opacity:.45; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }\n[tag] .fp-btn { display:inline-flex; align-items:center; justify-content:center; width:26px; height:22px; padding:0; font-size:12px; text-decoration:none; color:var(--okdb-sky); border:1px solid var(--okdb-sky-soft-border); border-radius:4px; background:transparent; cursor:pointer; }\n[tag] .fp-meta { display:flex; flex-wrap:wrap; gap:4px 14px; padding:6px 10px; font-size:11px; font-family:monospace; opacity:.75; border-bottom:1px solid var(--okdb-app-border); flex-shrink:0; }\n[tag] .fp-meta b { font-weight:500; opacity:.55; margin-right:3px; }\n[tag] .fp-body { flex:1; min-height:0; overflow:auto; padding:10px; display:flex; flex-direction:column; gap:8px; }\n[tag] .fp-note { font-size:11.5px; opacity:.6; }\n[tag] .fp-note code { font-size:11px; }\n[tag] .fp-note--err { opacity:1; color:var(--okdb-danger); }\n[tag] .fp-note--warn { opacity:1; color:var(--okdb-warning-text); }\n[tag] .fp-text { margin:0; padding:10px; font-family:'Cascadia Code','Fira Code','Consolas',monospace; font-size:11.5px; line-height:1.5; white-space:pre-wrap; word-break:break-word; background:var(--okdb-app-bg); border:1px solid var(--okdb-app-border); border-radius:6px; color:var(--okdb-app-fg); }\n[tag] .fp-text mark { background:color-mix(in srgb, var(--okdb-warning) 38%, transparent); color:inherit; border-radius:2px; padding:0 1px; }\n[tag] .fp-media { display:flex; align-items:center; justify-content:center; border:1px solid var(--okdb-app-border); border-radius:6px; overflow:hidden; min-height:120px; }\n[tag] .fp-media img, [tag] .fp-media video { max-width:100%; max-height:70vh; display:block; }\n[tag] .fp-checker { background-color:var(--okdb-app-bg); background-image:linear-gradient(45deg, var(--okdb-app-surface) 25%, transparent 25%, transparent 75%, var(--okdb-app-surface) 75%), linear-gradient(45deg, var(--okdb-app-surface) 25%, transparent 25%, transparent 75%, var(--okdb-app-surface) 75%); background-size:16px 16px; background-position:0 0, 8px 8px; }\n[tag] .fp-frame { flex:1; width:100%; min-height:60vh; border:1px solid var(--okdb-app-border); border-radius:6px; background:#fff; }\n[tag] .fp-empty { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px; font-size:12.5px; opacity:.7; padding:30px 0; text-align:center; }\n[tag] .fp-dl { font-size:12px; padding:4px 14px; border-radius:999px; text-decoration:none; color:var(--okdb-sky); border:1px solid var(--okdb-sky-soft-border); background:var(--okdb-sky-soft-bg); }\n"};
|
|
@@ -18,12 +18,47 @@ export interface OKDBUploadOptions {
|
|
|
18
18
|
txn?: unknown;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export interface OKDBBlobStatus {
|
|
22
|
+
refs: number;
|
|
23
|
+
nodes?: Record<string, boolean>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OKDBIndexContentOptions {
|
|
27
|
+
/** Resolved field on `~files` that serves the extracted text (default `'content'`). */
|
|
28
|
+
field?: string;
|
|
29
|
+
/** Files larger than this get no content (default 16 MiB). */
|
|
30
|
+
maxBytes?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A mime (`'application/pdf'`), a wildcard (`'text/*'`, `'*+json'`), or a predicate. */
|
|
34
|
+
export type OKDBExtractorMatch = string | ((record: OKDBFileRecord) => boolean);
|
|
35
|
+
export type OKDBExtractor = (buffer: Buffer, record: OKDBFileRecord) => string | null | Promise<string | null>;
|
|
36
|
+
|
|
21
37
|
export declare class OKDBFiles {
|
|
22
38
|
upload(options: OKDBUploadOptions): Promise<OKDBFileRecord>;
|
|
23
|
-
stream(id: string): Promise<{ stream: ReadStream; record: OKDBFileRecord }>;
|
|
24
|
-
delete(id: string): Promise<boolean>;
|
|
25
39
|
get(id: string): OKDBFileRecord | null;
|
|
26
|
-
|
|
40
|
+
read(id: string): Promise<Buffer>;
|
|
41
|
+
stream(id: string): Promise<{ stream: ReadStream; record: OKDBFileRecord }>;
|
|
42
|
+
remove(id: string, options?: { txn?: unknown }): Promise<void>;
|
|
43
|
+
listPath(prefix: string, options?: { recursive?: boolean; limit?: number }): Promise<OKDBFileRecord[]>;
|
|
44
|
+
|
|
45
|
+
/** Make file contents searchable (FTS / embeddings) through a durable resolved field. */
|
|
46
|
+
indexContent(options?: OKDBIndexContentOptions): Promise<void>;
|
|
47
|
+
/** Register a content extractor (process-local; later registrations win). Returns an unregister function. */
|
|
48
|
+
registerExtractor(match: OKDBExtractorMatch, fn: OKDBExtractor): () => void;
|
|
49
|
+
|
|
50
|
+
getBlobStatus(hash: string): OKDBBlobStatus | null;
|
|
51
|
+
gcOrphanedBlobs(): number;
|
|
52
|
+
listBlobStatus(): Array<{
|
|
53
|
+
hash: string;
|
|
54
|
+
refs: number;
|
|
55
|
+
nodes: Record<string, boolean>;
|
|
56
|
+
onDisk: boolean;
|
|
57
|
+
sizeBytes: number | null;
|
|
58
|
+
}>;
|
|
59
|
+
streamByHash(hash: string): ReadStream;
|
|
60
|
+
syncBlobs(options?: { peerIds?: string[] }): Promise<{ synced: number; errors: string[] }>;
|
|
61
|
+
|
|
27
62
|
start(): Promise<void>;
|
|
28
63
|
stop(): void;
|
|
29
64
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -15,7 +15,15 @@ export type {
|
|
|
15
15
|
OKDBClaimOptions,
|
|
16
16
|
OKDBListJobsOptions,
|
|
17
17
|
} from './features/queue';
|
|
18
|
-
export type {
|
|
18
|
+
export type {
|
|
19
|
+
OKDBFiles,
|
|
20
|
+
OKDBFileRecord,
|
|
21
|
+
OKDBUploadOptions,
|
|
22
|
+
OKDBBlobStatus,
|
|
23
|
+
OKDBIndexContentOptions,
|
|
24
|
+
OKDBExtractorMatch,
|
|
25
|
+
OKDBExtractor,
|
|
26
|
+
} from './features/files';
|
|
19
27
|
export type { OKDBSync, OKDBSyncNode, OKDBSyncInfo } from './features/sync';
|
|
20
28
|
export type { OKDBAuth, OKDBToken, OKDBAuthContext, OKDBLoginResult } from './features/auth';
|
|
21
29
|
export type { OKDBEmbeddings, OKDBEmbeddingsPipeline, OKDBEmbeddingsSearchResult } from './features/embeddings';
|
|
@@ -86,8 +94,15 @@ export declare class OKDB {
|
|
|
86
94
|
// ── Subsystems ────────────────────────────────────────────────────────────
|
|
87
95
|
readonly http: {
|
|
88
96
|
/** Start the built-in HTTP server (REST API + admin UI). Single-process only —
|
|
89
|
-
* a `{ workers }` second argument throws HTTP_CLUSTER_REMOVED (okdb 2.0).
|
|
90
|
-
|
|
97
|
+
* a `{ workers }` second argument throws HTTP_CLUSTER_REMOVED (okdb 2.0).
|
|
98
|
+
* `host` binds one address (default: all interfaces); an array binds each address with its
|
|
99
|
+
* own server sharing one request handler. Returns the Node `http.Server` — for an array, the
|
|
100
|
+
* one bound to the first address (all of them are on `http.servers`; an 'error' from any is
|
|
101
|
+
* re-emitted on the returned one; `http.close()` closes them all). A string second argument
|
|
102
|
+
* is shorthand for `{ host }`. */
|
|
103
|
+
listen(port: number, opts?: string | string[] | { host?: string | string[] }): import('http').Server;
|
|
104
|
+
/** Every server the last listen() started (one per bound host). */
|
|
105
|
+
readonly servers: import('http').Server[];
|
|
91
106
|
[key: string]: unknown;
|
|
92
107
|
};
|
|
93
108
|
readonly auth: OKDBAuth;
|