genosdb 0.6.8 → 0.7.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/README.md CHANGED
@@ -23,6 +23,8 @@ A lightweight, decentralized graph database designed for modern web applications
23
23
 
24
24
  [![Liberapay receiving](https://img.shields.io/liberapay/receives/estebanrfp.svg?logo=liberapay)](https://liberapay.com/estebanrfp/donate)
25
25
 
26
+ > ⚠️ Migration Guide: The class-based API `new GDB()` has been removed. Please migrate to the async factory function. See the guide: [MIGRATION.md](./MIGRATION.md)
27
+
26
28
  <!-- ### Nostr.band Followers
27
29
 
28
30
  ![Nostr.band Followers](https://img.shields.io/nostr-band/followers/npub18c556t7n8xa3df2q82rwxejfglw5przds7sqvefylzjh8tjne28qld0we7) -->
@@ -1,4 +1,4 @@
1
- function q(v){const E=v.map;return v.map=async function(...j){let I={},N=null;if(j.forEach((h)=>{if(typeof h==="object")I={...I,...h};if(typeof h==="function")N=h}),I.prompt)try{const h=await T(I.prompt);console.log("Query generated from AI:",h),I={...I,...h},delete I.prompt}catch(h){console.error("Error generating query from AI:",h.message),I.query={}}return E.call(this,I,N)},v}async function T(v){const E=`
1
+ function j(u){const $=u.map;return u.map=async function(...f){let h={},b=null;if(f.forEach((Y)=>{if(typeof Y==="object")h={...h,...Y};if(typeof Y==="function")b=Y}),h.prompt)try{const Y=await v(h.prompt);console.log("Query generated from AI:",Y),h={...h,...Y},delete h.prompt}catch(Y){console.error("Error generating query from AI:",Y.message),h.query={}}return $.call(this,h,b)},u}async function v(u){const $=`
2
2
  You are an assistant that converts natural language instructions into a structured MongoDB query object.
3
3
 
4
4
  Rules:
@@ -17,5 +17,5 @@ function q(v){const E=v.map;return v.map=async function(...j){let I={},N=null;if
17
17
  Output: {"query": {"type":"Company", "\$edge": {"role":"Developer", "\$edge": {"name":"Bob"}}}}
18
18
 
19
19
  Instruction:
20
- "${v}"
21
- `;try{const j=await f(E);if(j&&typeof j==="object"&&j.query)return{query:j.query,order:j.order||"asc",field:j.field||Object.keys(j.query)[0]};throw new Error("Invalid AI response format")}catch(j){return console.warn("Using empty query due to AI error:",j.message),{query:{}}}}async function f(v){try{const j=await fetch("https://text.pollinations.ai/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"system",content:"You are an assistant specialized in converting natural language to structured queries."},{role:"user",content:v}],model:"openai",seed:Math.floor(Math.random()*1000),jsonMode:!0})});if(!j.ok)throw new Error(`Pollinations API error: ${j.statusText}`);const I=await j.json();try{return typeof I==="string"?JSON.parse(I):I}catch{return I}}catch(E){throw console.error("Error processing prompt with API:",E.message),E}}export{q as withAI};
20
+ "${u}"
21
+ `;try{const f=await w($);if(f&&typeof f==="object"&&f.query)return{query:f.query,order:f.order||"asc",field:f.field||Object.keys(f.query)[0]};throw new Error("Invalid AI response format")}catch(f){return console.warn("Using empty query due to AI error:",f.message),{query:{}}}}async function w(u){try{const f=await fetch("https://text.pollinations.ai/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"system",content:"You are an assistant specialized in converting natural language to structured queries."},{role:"user",content:u}],model:"openai",seed:Math.floor(Math.random()*1000),jsonMode:!0})});if(!f.ok)throw new Error(`Pollinations API error: ${f.statusText}`);const h=await f.json();try{return typeof h==="string"?JSON.parse(h):h}catch{return h}}catch($){throw console.error("Error processing prompt with API:",$.message),$}}var x=(u)=>{return console.log("\uD83E\uDDE0 AI: AIQuery module loaded."),j(u)};export{j as withModule,x as init};
Binary file
@@ -0,0 +1 @@
1
+ function I(A){console.log("\uD83D\uDCCD Extending GDB with geolocation operators...");const E={$near:(c,f)=>{console.log("Ejecutando operador $near");const{latitude:s,longitude:j,radius:b}=f;if(typeof s!=="number"||typeof j!=="number"||typeof b!=="number")return console.error("Consulta inv\xE1lida para $near:",f),!1;const z=c?.latitude||c?.location?.latitude,p=c?.longitude||c?.location?.longitude;if(typeof z!=="number"||typeof p!=="number")return!1;return F(z,p,s,j)<=b},$bbox:(c,f)=>{console.log("Ejecutando operador $bbox");const{minLat:s,maxLat:j,minLng:b,maxLng:z}=f;if(typeof s!=="number"||typeof j!=="number"||typeof b!=="number"||typeof z!=="number")return console.error("Consulta inv\xE1lida para $bbox:",f),!1;const p=c?.latitude||c?.location?.latitude,k=c?.longitude||c?.location?.longitude;if(typeof p!=="number"||typeof k!=="number")return!1;return p>=s&&p<=j&&k>=b&&k<=z}};function F(c,f,s,j){const b=(H)=>H*Math.PI/180,p=b(s-c),k=b(j-f),C=Math.sin(p/2)*Math.sin(p/2)+Math.cos(b(c))*Math.cos(b(s))*Math.sin(k/2)*Math.sin(k/2);return 6371*(2*Math.atan2(Math.sqrt(C),Math.sqrt(1-C)))}return A.operators={...A.operators,...E},A}var K=(A)=>{return console.log("\uD83D\uDCCD + Geolocation operators."),I(A)};export{I as withModule,K as init};
Binary file
@@ -1 +1 @@
1
- function I(z){const C={$near:(c,j)=>{console.log("Ejecutando operador $near");const{latitude:f,longitude:k,radius:h}=j;if(typeof f!=="number"||typeof k!=="number"||typeof h!=="number")return console.error("Consulta inv\xE1lida para $near:",j),!1;const w=c?.latitude||c?.location?.latitude,b=c?.longitude||c?.location?.longitude;if(typeof w!=="number"||typeof b!=="number")return!1;return E(w,b,f,k)<=h},$bbox:(c,j)=>{console.log("Ejecutando operador $bbox");const{minLat:f,maxLat:k,minLng:h,maxLng:w}=j;if(typeof f!=="number"||typeof k!=="number"||typeof h!=="number"||typeof w!=="number")return console.error("Consulta inv\xE1lida para $bbox:",j),!1;const b=c?.latitude||c?.location?.latitude,p=c?.longitude||c?.location?.longitude;if(typeof b!=="number"||typeof p!=="number")return!1;return b>=f&&b<=k&&p>=h&&p<=w}};function E(c,j,f,k){const h=(F)=>F*Math.PI/180,b=h(f-c),p=h(k-j),A=Math.sin(b/2)*Math.sin(b/2)+Math.cos(h(c))*Math.cos(h(f))*Math.sin(p/2)*Math.sin(p/2);return 6371*(2*Math.atan2(Math.sqrt(A),Math.sqrt(1-A)))}return z.operators={...z.operators,...C},z}export{I as withGeolocationOperators};
1
+ function H(w){const A={$near:(b,f)=>{console.log("Ejecutando operador $near");const{latitude:p,longitude:h,radius:s}=f;if(typeof p!=="number"||typeof h!=="number"||typeof s!=="number")return console.error("Consulta inv\xE1lida para $near:",f),!1;const k=b?.latitude||b?.location?.latitude,c=b?.longitude||b?.location?.longitude;if(typeof k!=="number"||typeof c!=="number")return!1;return C(k,c,p,h)<=s},$bbox:(b,f)=>{console.log("Ejecutando operador $bbox");const{minLat:p,maxLat:h,minLng:s,maxLng:k}=f;if(typeof p!=="number"||typeof h!=="number"||typeof s!=="number"||typeof k!=="number")return console.error("Consulta inv\xE1lida para $bbox:",f),!1;const c=b?.latitude||b?.location?.latitude,j=b?.longitude||b?.location?.longitude;if(typeof c!=="number"||typeof j!=="number")return!1;return c>=p&&c<=h&&j>=s&&j<=k}};function C(b,f,p,h){const s=(E)=>E*Math.PI/180,c=s(p-b),j=s(h-f),z=Math.sin(c/2)*Math.sin(c/2)+Math.cos(s(b))*Math.cos(s(p))*Math.sin(j/2)*Math.sin(j/2);return 6371*(2*Math.atan2(Math.sqrt(z),Math.sqrt(1-z)))}return w.operators={...w.operators,...A},w}export{H as withModule};
Binary file