@kedem/okdb 1.1.4 → 1.2.0

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": "1.1.4",
3
+ "version": "1.2.0",
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
- export default class t{constructor({type:t,pageSize:e=50,apiBase:s}){this.type=t,this._apiBaseFn="function"==typeof s?s:()=>s||__ENV__.API,this.busy=!1,this.items=[],this.values=[],this.total=0,this.time=null,this.query={},this.selectedIndex=null,this.selectedDirection="desc",this.queryMode="prefix",this.selectedPrefix=void 0,this.selectedIndexStart=void 0,this.selectedIndexEnd=void 0,this.selectedFtsIndex=null,this.ftsText="",this.ftsMode="and",this.ftsPrefix=!1,this.ftsScoreMap={},this.selectedVectorEngine=null,this.vectorText="",this.vectorLimit=20,this.vectorScoreMap={},this.vectorChunkMetaMap={},this.pageSize=e,this.hasNext=!1,this.hasPrev=!1,this._current=null,this._backStack=[]}get _apiBase(){return this._apiBaseFn()}resetPaging(){this._current=null,this._backStack=[],this.hasNext=!1,this.hasPrev=!1}nextPage(){if(!this.busy&&this.hasNext)return this._load("next")}prevPage(){if(this.busy||!this.hasPrev)return;const t=this._backStack.pop();return t?(this._current=t,this._load("restore")):void 0}async load(){return this.resetPaging(),this.selectedFtsIndex?this._loadFts():this.selectedVectorEngine?this._loadVector():this._load(null)}async _loadFts(){if(this.type&&this.selectedFtsIndex){this.busy=!0;try{const t=await fetch(`${this._apiBase}/type/${this.type}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:this.query,options:{fts:{name:this.selectedFtsIndex,query:this.ftsText,mode:this.ftsMode,prefix:this.ftsPrefix,limit:this.pageSize}}})});if(!t.ok)throw new Error(t.statusText);const{data:s,meta:i}=await t.json(),h=s??[];this.items=h,this.ftsScoreMap={},this.values=h.map(t=>(e(t.value,t.key),null!=t.score&&(this.ftsScoreMap[t.key]={score:t.score,numTerms:t.numTerms,maxScore:t.maxScore}),t.value)),this.hasNext=!1,this.hasPrev=!1,this._current=null,this._backStack=[],this.time=i?.time??null,this.total=h.length}catch(t){console.error("TypeQueryVM FTS load error",t)}finally{this.busy=!1}}}async _loadVector(){if(this.type&&this.selectedVectorEngine){this.busy=!0;try{const t=await fetch(`${this._apiBase}/type/${this.type}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:this.query,options:{vectorSearch:{name:this.selectedVectorEngine,query:this.vectorText,limit:this.vectorLimit}}})});if(!t.ok)throw new Error((await t.json())?.error?.message||t.statusText);const{data:s,meta:i}=await t.json(),h=s??[];this.items=h,this.vectorScoreMap={},this.vectorChunkMetaMap={},this.values=h.map(t=>(e(t.value,t.key),null!=t.score&&(this.vectorScoreMap[t.key]=t.score),t.chunkHash&&(this.vectorChunkMetaMap[t.key]={chunkHash:t.chunkHash,...t.chunk??{}}),t.value)),this.hasNext=!1,this.hasPrev=!1,this._current=null,this._backStack=[],this.time=i?.time??null,this.total=h.length}catch(t){console.error("TypeQueryVM vector load error",t)}finally{this.busy=!1}}}async _load(t){if(!this.type)return;this.busy=!0,this.ftsScoreMap={},this.vectorScoreMap={},this.vectorChunkMetaMap={};const s="desc"===this.selectedDirection;this.selectedIndex;try{const i={index:this.selectedIndex,reverse:s,limit:this.pageSize+1};if(this.selectedIndex&&("prefix"===this.queryMode?void 0!==this.selectedPrefix&&(i.prefix=this.selectedPrefix):(void 0!==this.selectedIndexStart&&(i.startIndex=this.selectedIndexStart),void 0!==this.selectedIndexEnd&&(i.endIndex=this.selectedIndexEnd))),"next"===t&&this._current){const t=this._current.last;i.startKey=t,this._backStack.push(this._current)}if("restore"===t&&this._current){const t=this._current.first;i.startKey=t}const h=await fetch(`${this._apiBase}/type/${this.type}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:this.query,options:i})});if(!h.ok)throw new Error(h.statusText);const{data:r,meta:a}=await h.json(),n=r??[];this.hasNext=n.length>this.pageSize;const o=n.slice(0,this.pageSize);this.items=o,this.values=o.map(t=>(e(t.value,t.key),t.value));const c=o[0],l=o[o.length-1],d=t=>t?.key;this._current={first:d(c),last:d(l)},this.hasPrev=this._backStack.length>0,this.time=a?.time??null,this.total="…";const u={index:this.selectedIndex,reverse:s};this.selectedIndex&&("prefix"===this.queryMode?void 0!==this.selectedPrefix&&(u.prefix=this.selectedPrefix):(void 0!==this.selectedIndexStart&&(u.startIndex=this.selectedIndexStart),void 0!==this.selectedIndexEnd&&(u.endIndex=this.selectedIndexEnd))),fetch(`${this._apiBase}/type/${this.type}/count`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:this.query,options:u})}).then(t=>t.json()).then(t=>this.total=t.data).catch(t=>this.total=t.message)}catch(t){console.error("TypeQueryVM load error",t)}finally{this.busy=!1}}}function e(t,e){t&&"object"==typeof t&&t.__key!==e&&Object.defineProperty(t,"__key",{value:e,enumerable:!1,configurable:!1,writable:!1})}
1
+ export default class t{constructor({type:t,pageSize:e=50,apiBase:s}){this.type=t,this._apiBaseFn="function"==typeof s?s:()=>s||__ENV__.API,this.busy=!1,this.items=[],this.values=[],this.total=0,this.time=null,this.query={},this.selectedIndex=null,this.selectedDirection="desc",this.queryMode="prefix",this.selectedPrefix=void 0,this.selectedIndexStart=void 0,this.selectedIndexEnd=void 0,this.selectedFtsIndex=null,this.ftsText="",this.ftsMode="and",this.ftsPrefix=!1,this.ftsScoreMap={},this.selectedVectorEngine=null,this.vectorText="",this.vectorLimit=20,this.vectorScoreMap={},this.vectorChunkMetaMap={},this.pageSize=e,this.hasNext=!1,this.hasPrev=!1,this._current=null,this._fetchStartKey=void 0,this._backStack=[]}get _apiBase(){return this._apiBaseFn()}resetPaging(){this._current=null,this._fetchStartKey=void 0,this._backStack=[],this.hasNext=!1,this.hasPrev=!1}nextPage(){if(!this.busy&&this.hasNext)return this._load("next")}prevPage(){if(this.busy||!this.hasPrev)return;const t=this._backStack.pop();return this._load("restore",t)}async load(){return this.resetPaging(),this.selectedFtsIndex?this._loadFts():this.selectedVectorEngine?this._loadVector():this._load(null)}async _loadFts(){if(this.type&&this.selectedFtsIndex){this.busy=!0;try{const t=await fetch(`${this._apiBase}/type/${this.type}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:this.query,options:{fts:{name:this.selectedFtsIndex,query:this.ftsText,mode:this.ftsMode,prefix:this.ftsPrefix,limit:this.pageSize}}})});if(!t.ok)throw new Error(t.statusText);const{data:s,meta:i}=await t.json(),h=s??[];this.items=h,this.ftsScoreMap={},this.values=h.map(t=>(e(t.value,t.key),null!=t.score&&(this.ftsScoreMap[t.key]={score:t.score,numTerms:t.numTerms,maxScore:t.maxScore}),t.value)),this.hasNext=!1,this.hasPrev=!1,this._current=null,this._backStack=[],this.time=i?.time??null,this.total=h.length}catch(t){console.error("TypeQueryVM FTS load error",t)}finally{this.busy=!1}}}async _loadVector(){if(this.type&&this.selectedVectorEngine){this.busy=!0;try{const t=await fetch(`${this._apiBase}/type/${this.type}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:this.query,options:{vectorSearch:{name:this.selectedVectorEngine,query:this.vectorText,limit:this.vectorLimit}}})});if(!t.ok)throw new Error((await t.json())?.error?.message||t.statusText);const{data:s,meta:i}=await t.json(),h=s??[];this.items=h,this.vectorScoreMap={},this.vectorChunkMetaMap={},this.values=h.map(t=>(e(t.value,t.key),null!=t.score&&(this.vectorScoreMap[t.key]=t.score),t.chunkHash&&(this.vectorChunkMetaMap[t.key]={chunkHash:t.chunkHash,...t.chunk??{}}),t.value)),this.hasNext=!1,this.hasPrev=!1,this._current=null,this._backStack=[],this.time=i?.time??null,this.total=h.length}catch(t){console.error("TypeQueryVM vector load error",t)}finally{this.busy=!1}}}async _load(t,s){if(!this.type)return;this.busy=!0,this.ftsScoreMap={},this.vectorScoreMap={},this.vectorChunkMetaMap={};const i="desc"===this.selectedDirection;this.selectedIndex;try{const h={index:this.selectedIndex,reverse:i,limit:this.pageSize+1};if(this.selectedIndex&&("prefix"===this.queryMode?void 0!==this.selectedPrefix&&(h.prefix=this.selectedPrefix):(void 0!==this.selectedIndexStart&&(h.startIndex=this.selectedIndexStart),void 0!==this.selectedIndexEnd&&(h.endIndex=this.selectedIndexEnd))),"next"===t&&this._current){const t=this._current.last;h.startKey=t,this._backStack.push(this._fetchStartKey),this._fetchStartKey=t}"restore"===t&&(this._fetchStartKey=s,null!=s&&(h.startKey=s));const a=await fetch(`${this._apiBase}/type/${this.type}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:this.query,options:h})});if(!a.ok)throw new Error(a.statusText);const{data:r,meta:n}=await a.json(),o=r??[];this.hasNext=o.length>this.pageSize;const c=o.slice(0,this.pageSize);this.items=c,this.values=c.map(t=>(e(t.value,t.key),t.value));const l=c[0],d=c[c.length-1],u=t=>t?.key;this._current={first:u(l),last:u(d)},this.hasPrev=this._backStack.length>0,this.time=n?.time??null,this.total="…";const y={index:this.selectedIndex,reverse:i};this.selectedIndex&&("prefix"===this.queryMode?void 0!==this.selectedPrefix&&(y.prefix=this.selectedPrefix):(void 0!==this.selectedIndexStart&&(y.startIndex=this.selectedIndexStart),void 0!==this.selectedIndexEnd&&(y.endIndex=this.selectedIndexEnd))),fetch(`${this._apiBase}/type/${this.type}/count`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:this.query,options:y})}).then(t=>t.json()).then(t=>this.total=t.data).catch(t=>this.total=t.message)}catch(t){console.error("TypeQueryVM load error",t)}finally{this.busy=!1}}}function e(t,e){t&&"object"==typeof t&&t.__key!==e&&Object.defineProperty(t,"__key",{value:e,enumerable:!1,configurable:!1,writable:!1})}