genosdb 0.0.1 → 0.2.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/LICENSE +55 -0
- package/README.md +210 -0
- package/dist/AIModule.min.js +13 -0
- package/dist/AIModule.min.js.gz +0 -0
- package/dist/AIQuery.min.js +15 -0
- package/dist/AIQuery.min.js.gz +0 -0
- package/dist/GeolocationOperators.min.js +1 -0
- package/dist/GeolocationOperators.min.js.gz +0 -0
- package/dist/gdb.min.js +11 -0
- package/dist/gdb.min.js.gz +0 -0
- package/dist/index.js +11 -0
- package/dist/index.js.gz +0 -0
- package/dist/radixIndex.min.js +1 -0
- package/dist/radixIndex.min.js.gz +0 -0
- package/dist/rbac.min.js +2 -0
- package/dist/rbac.min.js.gz +0 -0
- package/package.json +61 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Copyright (c) 2025 Esteban Fuster Pozzi
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Copyright (c) 2025 Esteban Fuster Pozzi
|
|
24
|
+
|
|
25
|
+
This software is provided 'as-is', without any express or implied
|
|
26
|
+
warranty. In no event will the authors be held liable for any damages
|
|
27
|
+
arising from the use of this software.
|
|
28
|
+
|
|
29
|
+
Permission is granted to anyone to use this software for any purpose,
|
|
30
|
+
including commercial applications, and to alter it and redistribute it
|
|
31
|
+
freely, subject to the following restrictions:
|
|
32
|
+
|
|
33
|
+
1. The origin of this software must not be misrepresented; you must not
|
|
34
|
+
claim that you wrote the original software. If you use this software
|
|
35
|
+
in a product, an acknowledgement in the product documentation would be
|
|
36
|
+
appreciated but is not required.
|
|
37
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
|
38
|
+
misrepresented as being the original software.
|
|
39
|
+
3. This notice may not be removed or altered from any source distribution.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
Copyright 2025 Esteban Fuster Pozzi
|
|
44
|
+
|
|
45
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
46
|
+
you may not use this file except in compliance with the License.
|
|
47
|
+
You may obtain a copy of the License at
|
|
48
|
+
|
|
49
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
50
|
+
|
|
51
|
+
Unless required by applicable law or agreed to in writing, software
|
|
52
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
53
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
54
|
+
See the License for the specific language governing permissions and
|
|
55
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# GenosDB (GDB) – Decentralized P2P Graph Database
|
|
2
|
+
|
|
3
|
+
A lightweight, decentralized graph database designed for modern web applications, offering real-time peer-to-peer synchronization, WebAuthn-based authentication, role-based access control (RBAC), and efficient local storage utilizing OPFS.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.org/package/genosdb)
|
|
10
|
+
[](https://github.com/estebanrfp/gdb/blob/main/LICENSE)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
[](https://www.jsdelivr.com/package/npm/genosdb)
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
<!-- [](https://app.netlify.com/start/deploy?repository=https://github.com/estebanrfp/gdb&build=dist) -->
|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
[](https://liberapay.com/estebanrfp/donate)
|
|
25
|
+
|
|
26
|
+
<!-- ### Nostr.band Followers
|
|
27
|
+
|
|
28
|
+
 -->
|
|
29
|
+
|
|
30
|
+
<!--  -->
|
|
31
|
+
|
|
32
|
+
## Main Features
|
|
33
|
+
|
|
34
|
+
### ✅ **GenosDB Core**
|
|
35
|
+
|
|
36
|
+
- Efficient storage in OPFS.
|
|
37
|
+
- Real-time synchronization between tabs and devices.
|
|
38
|
+
- CRUD operations for nodes and relationships.
|
|
39
|
+
- Efficient serialization using MessagePack and compression with Pako.
|
|
40
|
+
- Enabling reverse or Radix Tree indexing through external modules.
|
|
41
|
+
- GenosDB supports external modules that extend its capabilities.
|
|
42
|
+
|
|
43
|
+
## Warning
|
|
44
|
+
|
|
45
|
+
This project is under active development. Do not use it in production environments until it reaches the beta or stable phase. Check the [Project Status](#project-status) section for more details.
|
|
46
|
+
|
|
47
|
+
## Project Status
|
|
48
|
+
|
|
49
|
+
- **Phase**: Beta
|
|
50
|
+
- **Completed Features**:
|
|
51
|
+
- Basic queries.
|
|
52
|
+
- Advanced queries.
|
|
53
|
+
- Modules for AI queries.
|
|
54
|
+
- Distributed storage.
|
|
55
|
+
- Conflict resolution module (LWW).
|
|
56
|
+
- Performance optimization.
|
|
57
|
+
|
|
58
|
+
- **Pending Features**:
|
|
59
|
+
- Improve incremental Synchronization:
|
|
60
|
+
Currently, when a change is detected in an element, the entire graph is updated in nodes that do not have the latest version. In future versions, incremental synchronization will be implemented to propagate only the specific changes, improving efficiency and reducing latency in distributed graph updates.
|
|
61
|
+
|
|
62
|
+
> ⚠️ The API is under active development and may change without notice. Use fixed versions and check the [changelog](https://github.com/estebanrfp/gdb/wiki/CHANGELOG.md) before upgrading.
|
|
63
|
+
|
|
64
|
+
### ✅ **Role Based Access Control (RBAC)**
|
|
65
|
+
|
|
66
|
+
- Customizable role hierarchy (`superadmin`, `admin`, etc)
|
|
67
|
+
- Biometric Registration and Authentication with WebAuthn
|
|
68
|
+
- Granular permissions (`read`/`write`/`delete`/`publish`)
|
|
69
|
+
- Role assignment with automatic expiration
|
|
70
|
+
- Cryptographic transaction verification
|
|
71
|
+
|
|
72
|
+
### ✅ **Security**
|
|
73
|
+
|
|
74
|
+
- Digital signature of critical operations
|
|
75
|
+
- Real-time permission validation
|
|
76
|
+
- Secure storage of roles in internal graph
|
|
77
|
+
- [Security Implementation](https://github.com/estebanrfp/gdb/wiki/RBAC-Security)
|
|
78
|
+
|
|
79
|
+
> **Important Notice**: This project has progressed from its active development phase and is now in the beta stage. While it is functional and stable in controlled environments, it is recommended to evaluate its suitability for production based on the specific needs of your environment. For more details, please refer to the [Project Status](#project-status)
|
|
80
|
+
|
|
81
|
+
## ⚠️ Reliability Notice
|
|
82
|
+
|
|
83
|
+
This is a distributed database (P2P + CRDT); therefore:
|
|
84
|
+
• In extreme conditions (network failures, partial synchronization, or unconventional usage), unexpected behavior may occur.
|
|
85
|
+
• Any reported issues will be prioritized and resolved in upcoming patch versions.
|
|
86
|
+
|
|
87
|
+
The project has achieved the expected stability goals (such as conflict resolution, synchronization, and distributed storage), without intending to ignore the limitations inherent to distributed technologies (P2P + CRDT).
|
|
88
|
+
|
|
89
|
+
gdb‑p2p has been rigorously tested with our common usage examples in such environments, demonstrating greater stability than many other well-known distributed databases.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Installation
|
|
94
|
+
|
|
95
|
+
### 1. Via NPM
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npm install genosdb
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
import { GDB } from "genosdb"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 2. Direct use in browser from a CDN
|
|
106
|
+
|
|
107
|
+
```html
|
|
108
|
+
<script type="module">
|
|
109
|
+
import { GDB } from "https://cdn.jsdelivr.net/npm/genosdb/+esm"
|
|
110
|
+
</script>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Documentation
|
|
114
|
+
|
|
115
|
+
For detailed documentation, visit our [GitHub Wiki](https://github.com/estebanrfp/gdb/wiki).
|
|
116
|
+
|
|
117
|
+
For interactive, AI-assisted GenosDB documentation, visit our [Devin Wiki](https://deepwiki.com/estebanrfp/gdb).
|
|
118
|
+
|
|
119
|
+
## Examples
|
|
120
|
+
|
|
121
|
+
We’ve created a collection of interactive examples to help you understand how GDB works in real-world scenarios. These examples cover everything from basic setup to advanced features like RBAC and P2P synchronization.
|
|
122
|
+
|
|
123
|
+
👉 [Explore Examples](https://github.com/estebanrfp/gdb/wiki/EXAMPLES.md)
|
|
124
|
+
|
|
125
|
+
### **Internal Dependencies**
|
|
126
|
+
|
|
127
|
+
Below is a list of internal dependencies and their purposes within the project:
|
|
128
|
+
|
|
129
|
+
| Dependency | Usage |
|
|
130
|
+
| ------------------ | ---------------------------------------------------------------------------------------|
|
|
131
|
+
| `@msgpack/msgpack` | Data serialization/deserialization in MessagePack format. |
|
|
132
|
+
| `pako` | Data compression/decompression using gzip. |
|
|
133
|
+
| `trystero` | P2P synchronization for sharing changes in real-time between tabs/devices. |
|
|
134
|
+
| `BroadcastChannel` | Communication between browser tabs to notify local changes. |
|
|
135
|
+
|
|
136
|
+
#### Additional Information
|
|
137
|
+
|
|
138
|
+
- **`@msgpack/msgpack`**:
|
|
139
|
+
This library is used to efficiently serialize and deserialize data, reducing payload sizes for storage and transmission.
|
|
140
|
+
|
|
141
|
+
- **`pako`**:
|
|
142
|
+
Provides gzip compression to optimize data storage and network communication.
|
|
143
|
+
|
|
144
|
+
- **`trystero`**:
|
|
145
|
+
Enables peer-to-peer synchronization, ensuring real-time updates across multiple instances of the application.
|
|
146
|
+
> **Note**: Among the available networks supported by Trystero, this project specifically uses the **Nostr** protocol for decentralized communication.
|
|
147
|
+
>
|
|
148
|
+
> **What is Nostr?**
|
|
149
|
+
> Nostr (Notes and Other Stuff Transmitted by Relays) is a decentralized protocol designed for censorship-resistant global communication. It operates without relying on centralized servers, instead using a network of relays to transmit signed messages between peers. Nostr is particularly well-suited for applications requiring secure, private, and scalable peer-to-peer interactions, such as social networks, messaging systems, or collaborative tools.
|
|
150
|
+
|
|
151
|
+
- **`BroadcastChannel`**:
|
|
152
|
+
Facilitates lightweight communication between browser tabs, allowing seamless updates without relying on external servers.
|
|
153
|
+
|
|
154
|
+
> **General Note**: These dependencies are integral to the project's performance and functionality, ensuring efficient data handling and real-time synchronization while leveraging decentralized technologies like Nostr.
|
|
155
|
+
|
|
156
|
+
## Repository Diagram
|
|
157
|
+
|
|
158
|
+
The project includes an interactive visualization of the repository’s history and structure, which you can explore by clicking the following link: gdb repository diagram.
|
|
159
|
+
|
|
160
|
+
The project includes an interactive visualization of the repository's history and structure, which you can explore here:
|
|
161
|
+
|
|
162
|
+
[gdb repository diagram](https://gitdiagram.com/estebanrfp/gdb)
|
|
163
|
+
|
|
164
|
+
This graphical view is especially useful for new contributors or anyone looking to gain deeper insight into the project’s evolution and structure, providing a clear and visual understanding of the workflow.
|
|
165
|
+
|
|
166
|
+
## Contributing
|
|
167
|
+
|
|
168
|
+
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.
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
## Community
|
|
172
|
+
|
|
173
|
+
We value community contributions and discussions! Here's how you can get involved:
|
|
174
|
+
|
|
175
|
+
- **Ask questions or share ideas**: Join our [GitHub Discussions](https://github.com/estebanrfp/gdb/discussions).
|
|
176
|
+
- **Real-time chat**: For quick conversations, join us on [Gitter](https://app.gitter.im/#/room/#GDB:gitter.im).
|
|
177
|
+
|
|
178
|
+
Here’s how you can participate in the Gitter room:
|
|
179
|
+
|
|
180
|
+
- `[DEV]`: Discussions about project development, new features, and technical improvements.
|
|
181
|
+
- `[ANNOUNCEMENT]`: Official updates, new releases, and important news about GDB.
|
|
182
|
+
- `[HELP]`: Technical support and troubleshooting for GDB-related questions.
|
|
183
|
+
|
|
184
|
+
Feel free to ask questions, share ideas, or just say hello! 👋
|
|
185
|
+
|
|
186
|
+
For more details on contributing, check out our [Contributing Guidelines](https://github.com/estebanrfp/gdb/wiki/Contributing).
|
|
187
|
+
|
|
188
|
+
## Licenses
|
|
189
|
+
|
|
190
|
+
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.
|
|
191
|
+
|
|
192
|
+
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.
|
|
193
|
+
|
|
194
|
+
## Maintenance
|
|
195
|
+
|
|
196
|
+
This repository provides minified builds of GenosDB (GDB), a decentralized P2P graph database designed for modern web applications. These builds are freely available for anyone to use and integrate into their projects. Please note that the source code is not publicly available at this time; only the minified versions are provided. The project is actively maintained by Esteban Fuster Pozzi ([@estebanrfp](https://github.com/estebanrfp))
|
|
197
|
+
|
|
198
|
+
## Author
|
|
199
|
+
|
|
200
|
+
[Esteban Fuster Pozzi (@estebanrfp)](https://estebanrfp.com) — Full Stack JavaScript Developer and creator of [GenosDB (GDB)](https://www.npmjs.com/package/genosdb), an open-source real-time graph database built entirely with modern vanilla JavaScript.
|
|
201
|
+
|
|
202
|
+
[](https://app.fossa.com/projects/git%2Bgithub.com%2Festebanrfp%2Fgdb?ref=badge_shield&issueType=security)
|
|
203
|
+
|
|
204
|
+
[](https://app.fossa.com/projects/git%2Bgithub.com%2Festebanrfp%2Fgdb?ref=badge_large&issueType=license)
|
|
205
|
+
|
|
206
|
+
## 💖 Support This Project
|
|
207
|
+
|
|
208
|
+
If you find this project useful and would like to support its development, please consider making a donation:
|
|
209
|
+
|
|
210
|
+
[](https://liberapay.com/estebanrfp/donate)
|
|
@@ -0,0 +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}
|
|
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.
|
|
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};
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
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"}
|
|
13
|
+
|
|
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};
|
|
Binary file
|
|
@@ -0,0 +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};
|
|
Binary file
|