genosdb 0.6.4 → 0.6.6

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
@@ -62,7 +62,7 @@ This project is under active development. Do not use it in production environmen
62
62
  - **Pending Features**:
63
63
  - No major features are currently pending. The project has entered a hardening phase with a focus on rigorous testing and stability improvements.
64
64
 
65
- > ⚠️ The API is under active development and may change without notice. Use fixed versions and check the [changelog](https://github.com/estebanrfp/gdb/blob/main/CHANGELOG.md) before upgrading.
65
+ > ⚠️ The API is under active development and may change without notice. Use fixed versions and check the [changelog](CHANGELOG.md) before upgrading.
66
66
 
67
67
  ### ✅ **Role Based Access Control (RBAC)**
68
68
 
@@ -109,7 +109,7 @@ import { GDB } from "genosdb"
109
109
 
110
110
  ```html
111
111
  <script type="module">
112
- import { GDB } from "https://cdn.jsdelivr.net/npm/genosdb/+esm"
112
+ import { GDB } from "https://cdn.jsdelivr.net/npm/genosdb@latest/dist/index.min.js"
113
113
  </script>
114
114
  ```
115
115
 
@@ -174,7 +174,7 @@ This graphical view is especially useful for new contributors or anyone looking
174
174
 
175
175
  ## Contributing
176
176
 
177
- We welcome contributions to improve this project! Please read our [Contribution Guidelines](https://github.com/estebanrfp/gdb/wiki/Contributing) for details on how to get started.
177
+ We welcome contributions to improve this project! Please read our [Contribution Guidelines](CONTRIBUTING.md) for details on how to get started.
178
178
 
179
179
 
180
180
  ## Community
@@ -192,11 +192,11 @@ We value community contributions and discussions! Here's how you can get involve
192
192
 
193
193
  Feel free to ask questions, share ideas, or just say hello! 👋
194
194
 
195
- For more details on contributing, check out our [Contributing Guidelines](https://github.com/estebanrfp/gdb/wiki/Contributing).
195
+ For more details on contributing, check out our [Contributing Guidelines](CONTRIBUTING.md).
196
196
 
197
197
  ## Licenses
198
198
 
199
- This project includes third-party dependencies with their respective licenses. For detailed information, see the [Licenses page](https://github.com/estebanrfp/gdb/wiki/Licenses/) in the Wiki.
199
+ This project includes third-party dependencies with their respective licenses. For detailed information, see the [Licenses page](THIRD_PARTY_LICENSES.md).
200
200
 
201
201
  The source code of this project is licensed under the [MIT License](https://opensource.org/licenses/MIT). For more information, see the [LICENSE](LICENSE) file.
202
202
 
@@ -1,13 +1,13 @@
1
- function w(c){const S=c.map;return c.map=async function(...E){const N=await S.call(this,...E),b=E.find((h)=>h&&typeof h==="object")||{},{prompt:f}=b;if(f)N.results=await k(N.results,f);return N},c}async function k(c,S){const E=c.map((f)=>f.value),N=`
2
- ${S}
1
+ function C(c){const O=c.map;return c.map=async function(...A){const L=await O.call(this,...A),h=A.find((j)=>j&&typeof j==="object")||{},{prompt:b}=h;if(b)L.results=await w(L.results,b);return L},c}async function w(c,O){const A=c.map((b)=>b.value),L=`
2
+ ${O}
3
3
 
4
- Reglas estrictas:
5
- - Devuelve un array JSON con la MISMA estructura de entrada.
6
- - Cada elemento del array debe ser una modificaci\xF3n del objeto correspondiente en la entrada.
7
- - S\xF3lo se deben modificar campos DENTRO del objeto \`value\`.
8
- - NO a\xF1adas, elimines ni reestructures nodos externos como \`id\`, \`edges\`, o \`timestamp\`.
9
- - NO agregues explicaciones ni texto adicional. Devuelve SOLO el array JSON con los objetos \`value\` modificados.
4
+ Strict rules:
5
+ - Return a JSON array with the SAME structure as the input.
6
+ - Each array element must be a modification of the corresponding input object.
7
+ - Only modify fields INSIDE the \`value\` object.
8
+ - DO NOT add, remove, or restructure external nodes like \`id\`, \`edges\`, or \`timestamp\`.
9
+ - DO NOT include explanations or extra text. Return ONLY the JSON array with modified \`value\` objects.
10
10
 
11
- Ejemplo de entrada:
12
- ${JSON.stringify(E)}
13
- `,b=await v(N);return console.log(b),c.map((f,h)=>{const j=Array.isArray(b)?b[h]:b;return{...f,value:{...f.value,...j||{}}}})}async function v(c){try{const E=await fetch("https://text.pollinations.ai/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"system",content:"You are an AI assistant specialized in processing structured data objects."},{role:"user",content:c}],model:"openai",seed:Math.floor(Math.random()*1000),jsonMode:!0})});if(!E.ok)throw new Error(`Error calling the Pollinations API: ${E.statusText}`);const N=await E.json();return N.data||N}catch(S){throw console.error("Error processing the prompt with the Pollinations API:",S.message),S}}export{w as withAI};
11
+ Input example:
12
+ ${JSON.stringify(A)}
13
+ `,h=await z(L);return console.log(h),c.map((b,j)=>{const k=Array.isArray(h)?h[j]:h;return{...b,value:{...b.value,...k||{}}}})}async function z(c){try{const A=await fetch("https://text.pollinations.ai/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"system",content:"You are an AI assistant specialized in processing structured data objects."},{role:"user",content:c}],model:"openai",seed:Math.floor(Math.random()*1000),jsonMode:!0})});if(!A.ok)throw new Error(`Pollinations API error: ${A.statusText}`);const L=await A.json();return L.data||L}catch(O){throw console.error("Error processing prompt with Pollinations API:",O.message),O}}export{C as withAI};
Binary file
@@ -1,15 +1,21 @@
1
- function v(y){const C=y.map;return y.map=async function(...f){let h={},U=null;if(f.forEach((j)=>{if(typeof j==="object")h={...h,...j};if(typeof j==="function")U=j}),h.prompt)try{const j=await $(h.prompt);console.log("Consulta generada desde IA:",j),h={...h,...j},delete h.prompt}catch(j){console.error("Error generando consulta desde IA:",j.message),h.query={}}return C.call(this,h,U)},y}async function $(y){const C=`
2
- Convierte la siguiente instrucci\xF3n en lenguaje natural a un objeto de consulta estructurado:
3
- "${y}"
4
-
5
- Reglas:
6
- - Devuelve un JSON con campos "query", "order" y "field"
7
- - Usa operadores MongoDB como "$between", "$gt", "$lt"
8
- - Para rangos usa "$between": [min, max]
9
- - Para ordenamiento usa "order": "asc" o "desc" y especifica "field"
10
- - Ejemplo:
11
- Entrada: "Busca personas de 10-20 a\xF1os y ord\xE9nalas por edad descendente"
12
- Salida: {"query": {"age": {"$between": [10, 20]}}, "order": "desc", "field": "age"}
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=`
2
+ You are an assistant that converts natural language instructions into a structured MongoDB query object.
13
3
 
14
- Responde SOLO con el JSON, sin texto adicional.
15
- `;try{const f=await q(C);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("Formato de respuesta de IA inv\xE1lido")}catch(f){return console.warn("Usando consulta vac\xEDa debido a error de IA:",f.message),{query:{}}}}async function q(y){try{const f=await fetch("https://text.pollinations.ai/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"system",content:"Eres un asistente especializado en convertir lenguaje natural a consultas estructuradas."},{role:"user",content:y}],model:"openai",seed:Math.floor(Math.random()*1000),jsonMode:!0})});if(!f.ok)throw new Error(`Error en la API de Pollinations: ${f.statusText}`);const h=await f.json();try{return typeof h==="string"?JSON.parse(h):h}catch{return h}}catch(C){throw console.error("Error procesando el prompt con la API:",C.message),C}}export{v as withAI};
4
+ Rules:
5
+ - Output ONLY a valid JSON object with the fields: "query", "order", and "field".
6
+ - Use MongoDB operators such as "\$between", "\$gt", "\$lt".
7
+ - For ranges, use "\$between": [min, max].
8
+ - For sorting, use "order": "asc" or "desc" and specify the "field".
9
+ - "\$edge" operator: allows chaining queries to related/descendant entities.
10
+ - No extra text, no explanations, no formatting besides the JSON.
11
+
12
+ Examples:
13
+ Input: "Find people aged 10 to 20 and sort them by age descending"
14
+ Output: {"query": {"age": {"\$between": [10, 20]}}, "order": "desc", "field": "age"}
15
+
16
+ Input: "Find a Company, then find a Developer descendant, then find that Developer's descendant named Bob."
17
+ Output: {"query": {"type":"Company", "\$edge": {"role":"Developer", "\$edge": {"name":"Bob"}}}}
18
+
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};
Binary file