genosdb 0.22.1 → 0.22.2

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
@@ -263,7 +263,7 @@ This project includes third-party dependencies with their own respective license
263
263
 
264
264
  ## Maintenance
265
265
 
266
- This repository provides production 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 production builds versions are provided. The project is actively maintained by Esteban Fuster Pozzi ([@estebanrfp](https://github.com/estebanrfp))
266
+ This repository provides production 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 production builds are provided. The project is actively maintained by Esteban Fuster Pozzi ([@estebanrfp](https://github.com/estebanrfp)), with development and verification support from AI systems audited under the Spec Driven Development (SDD) methodology. Future maintenance may also involve qualified developers aligned with our vision.
267
267
 
268
268
  ## Author
269
269
 
package/dist/index.d.ts CHANGED
@@ -1 +1,278 @@
1
- declare module 'genosdb';
1
+ // Type definitions for genosdb
2
+ // GenosDB is written in modern JavaScript; these typings describe its public,
3
+ // documented API surface (docs/genosdb-api-reference.md and module guides).
4
+ // Queries are intentionally permissive: the engine is dynamic, so filters are
5
+ // open objects — known operators are listed for discoverability, and any field
6
+ // name is allowed.
7
+
8
+ declare module "genosdb" {
9
+ // ── Nodes ──────────────────────────────────────────────────────────
10
+
11
+ /** Hybrid Logical Clock timestamp. */
12
+ export interface HLC {
13
+ physical: number
14
+ logical: number
15
+ }
16
+
17
+ /** A stored node as returned by queries and reactive callbacks. */
18
+ export interface NodeObject<V = any> {
19
+ id: string
20
+ value: V
21
+ /** Ids of nodes this node links to. */
22
+ edges: string[]
23
+ timestamp: HLC | number
24
+ }
25
+
26
+ // ── Queries ────────────────────────────────────────────────────────
27
+
28
+ /**
29
+ * Comparison / logical operators understood by the query engine
30
+ * (Operators.js). A filter value can be a literal (equality) or an
31
+ * object combining these operators.
32
+ */
33
+ export interface QueryOperators {
34
+ $eq?: any
35
+ $ne?: any
36
+ $gt?: number | string
37
+ $gte?: number | string
38
+ $lt?: number | string
39
+ $lte?: number | string
40
+ $in?: any[]
41
+ $between?: [any, any]
42
+ $exists?: boolean
43
+ $startsWith?: string
44
+ $endsWith?: string
45
+ $contains?: string
46
+ /** Full-text, accent-insensitive match on a field. */
47
+ $text?: string
48
+ $like?: string
49
+ $regex?: string | RegExp
50
+ $not?: Query
51
+ $and?: Query[]
52
+ $or?: Query[]
53
+ /** Recursive graph traversal: sub-query applied to every descendant. */
54
+ $edge?: Query
55
+ /** Geo module: proximity search (requires `geo: true`). */
56
+ $near?: { center: [number, number]; radius: number }
57
+ /** Geo module: bounding-box search (requires `geo: true`). */
58
+ $bbox?: [number, number, number, number]
59
+ }
60
+
61
+ /** MongoDB-style filter: field names to literals or operator objects. */
62
+ export type Query = { [field: string]: any } & QueryOperators
63
+
64
+ export interface QueryOptions {
65
+ /** Filter. Defaults to `{}` (all nodes). */
66
+ query?: Query
67
+ /** Sort field. */
68
+ field?: string
69
+ /** Sort order. Defaults to `'asc'`. */
70
+ order?: "asc" | "desc"
71
+ /** Limit the number of results. */
72
+ $limit?: number
73
+ /** Paginate after a specific node id. */
74
+ $after?: string
75
+ /** Paginate before a specific node id. */
76
+ $before?: string
77
+ /** Explicitly enable/disable real-time mode. */
78
+ realtime?: boolean
79
+ }
80
+
81
+ /** Event delivered to a real-time `map` callback. */
82
+ export interface MapEvent<V = any> extends NodeObject<V> {
83
+ action: "initial" | "added" | "updated" | "removed"
84
+ }
85
+
86
+ export type MapCallback<V = any> = (event: MapEvent<V>) => void
87
+
88
+ export interface MapResult<V = any> {
89
+ results: NodeObject<V>[]
90
+ /** Present when real-time mode is active. */
91
+ unsubscribe?: () => void
92
+ }
93
+
94
+ export interface GetResult<V = any> {
95
+ result: NodeObject<V> | null
96
+ /** Present when a callback was provided (reactive mode). */
97
+ unsubscribe?: () => void
98
+ }
99
+
100
+ // ── Room (GenosRTC) ────────────────────────────────────────────────
101
+
102
+ export interface RoomChannel<T = any> {
103
+ /** Send data to all peers, or to specific peer ids. */
104
+ send(data: T, targets?: string | string[]): void
105
+ on(event: "message", handler: (data: T, peerId: string) => void): void
106
+ off(event: string, handler: (...args: any[]) => void): void
107
+ }
108
+
109
+ export interface RoomEvents {
110
+ /**
111
+ * A peer joined. `type` is the peer's declared kind — `'superpeer'`
112
+ * for a Fallback Server, `undefined` for regular peers.
113
+ * Informational only: never use it for trust decisions.
114
+ */
115
+ "peer:join": (peerId: string, type?: string) => void
116
+ "peer:leave": (peerId: string) => void
117
+ "stream:add": (stream: MediaStream, peerId: string, meta?: any) => void
118
+ "track:add": (track: MediaStreamTrack, stream: MediaStream, peerId: string) => void
119
+ /** Cellular Mesh: local overlay state (cellId, isBridge, bridges…). */
120
+ "mesh:state": (state: any) => void
121
+ /** Cellular Mesh: gossiped remote peer state. */
122
+ "mesh:peer-state": (data: any) => void
123
+ }
124
+
125
+ export interface Room {
126
+ on<E extends keyof RoomEvents>(event: E, handler: RoomEvents[E]): void
127
+ on(event: string, handler: (...args: any[]) => void): void
128
+ off(event: string, handler: (...args: any[]) => void): void
129
+ /** Named data channel (identifier UTF-8, max 12 bytes). */
130
+ channel<T = any>(name: string): RoomChannel<T>
131
+ /** Connected peer ids mapped to their RTC connections. */
132
+ getPeers(): Record<string, unknown>
133
+ /** Disconnect from the room and all peers. */
134
+ leave(): void
135
+ addStream(stream: MediaStream, targets?: string | string[], meta?: any): void
136
+ removeStream(stream: MediaStream, targets?: string | string[]): void
137
+ replaceTrack(
138
+ oldTrack: MediaStreamTrack,
139
+ newTrack: MediaStreamTrack,
140
+ stream: MediaStream,
141
+ targets?: string | string[]
142
+ ): void
143
+ /** Cellular Mesh overlay handle (present with `rtc: { cells }`). */
144
+ mesh?: any
145
+ }
146
+
147
+ // ── Security Manager ───────────────────────────────────────────────
148
+
149
+ export interface CustomRole {
150
+ can: string[]
151
+ inherits?: string[]
152
+ }
153
+
154
+ export interface SMOptions {
155
+ /** Constitution: authorized superadmin addresses. */
156
+ superAdmins: string[]
157
+ /** Role → permissions map overriding the built-in ladder. */
158
+ customRoles?: Record<string, CustomRole>
159
+ /** Governance rules (`{ if: <query>, then: { assignRole } }`). */
160
+ governanceRules?: any[]
161
+ [option: string]: any
162
+ }
163
+
164
+ export interface ACLs {
165
+ set(nodeId: string, acl: any): Promise<any>
166
+ grant(nodeId: string, ethAddress: string, permissions?: any): Promise<any>
167
+ revoke(nodeId: string, ethAddress: string): Promise<any>
168
+ delete(nodeId: string): Promise<any>
169
+ }
170
+
171
+ export interface SecurityManager {
172
+ startNewUserRegistration(): Promise<any>
173
+ loginCurrentUserWithWebAuthn(): Promise<any>
174
+ loginOrRecoverUserWithMnemonic(mnemonic: string): Promise<any>
175
+ protectCurrentIdentityWithWebAuthn(ethPrivateKeyForProtection?: string): Promise<any>
176
+ hasExistingWebAuthnRegistration(): boolean | Promise<boolean>
177
+ isSecurityActive(): boolean
178
+ getActiveEthAddress(): string | null
179
+ clearSecurity(): Promise<void>
180
+ setSecurityStateChangeCallback(
181
+ callback: (state: { isActive: boolean; activeAddress: string | null }) => void
182
+ ): void
183
+ assignRole(targetUserEthAddress: string, role: string, expiresAt?: number | string): Promise<any>
184
+ executeWithPermission(operationName: string): Promise<any>
185
+ /** Signed write (same shape as `db.put`). */
186
+ put(value: any, id?: string): Promise<string>
187
+ /** Read with security context (same shape as `db.get`). */
188
+ get(id: string, callback?: (node: NodeObject | null) => void): Promise<GetResult>
189
+ encryptDataForCurrentUser(data: any): Promise<any>
190
+ decryptDataForCurrentUser(encrypted: any): Promise<any>
191
+ /** Node-level access control lists. */
192
+ acls: ACLs
193
+ [member: string]: any
194
+ }
195
+
196
+ // ── Options ────────────────────────────────────────────────────────
197
+
198
+ export interface CellsOptions {
199
+ cellSize?: "auto" | number
200
+ bridgesPerEdge?: number
201
+ maxCellSize?: number
202
+ targetCells?: number
203
+ debug?: boolean
204
+ }
205
+
206
+ export interface RTCOptions {
207
+ /** Custom Nostr signaling relay URLs (wss://…). */
208
+ relayUrls?: string[]
209
+ /** TURN servers for NAT traversal. */
210
+ turnConfig?: RTCIceServer[]
211
+ /** Cellular Mesh overlay for large rooms. */
212
+ cells?: boolean | CellsOptions
213
+ }
214
+
215
+ export interface GDBOptions {
216
+ /** Enable P2P networking. `true` for defaults, object to customize. */
217
+ rtc?: boolean | RTCOptions
218
+ /** Enable the Security Manager (zero-trust, WebAuthn, governance). */
219
+ sm?: SMOptions
220
+ /** Load the AI module. */
221
+ ai?: boolean | object
222
+ /** Load the Natural Language Queries module. */
223
+ nlq?: boolean
224
+ /** Load the Geo module ($near / $bbox operators). */
225
+ geo?: boolean
226
+ /** Load the Audit module. */
227
+ audit?: boolean
228
+ /** Optional encryption key. */
229
+ password?: string
230
+ /** Enable internal debug logging. Defaults to `false`. */
231
+ debug?: boolean
232
+ /** Debounce (ms) for persisting the graph. Defaults to `200`. */
233
+ saveDelay?: number
234
+ /** Max operations kept for delta P2P sync. Defaults to `20`. */
235
+ oplogSize?: number
236
+ }
237
+
238
+ // ── Database ───────────────────────────────────────────────────────
239
+
240
+ export interface GDB {
241
+ /** Insert (or update, when `id` is given) a node. Resolves to its id. */
242
+ put(value: any, id?: string): Promise<string>
243
+ /** Read a node; pass a callback for reactive mode. */
244
+ get(id: string, callback?: (node: NodeObject | null) => void): Promise<GetResult>
245
+ /**
246
+ * Query nodes. Accepts an options object and/or a callback in any
247
+ * order; providing a callback enables real-time mode.
248
+ */
249
+ map(options?: QueryOptions, callback?: MapCallback): Promise<MapResult>
250
+ map(callback: MapCallback, options?: QueryOptions): Promise<MapResult>
251
+ map(...args: Array<QueryOptions | MapCallback>): Promise<MapResult>
252
+ /** Create a directed edge between two nodes. */
253
+ link(sourceId: string, targetId: string): Promise<void>
254
+ /** Delete a node and its references. */
255
+ remove(id: string): Promise<void>
256
+ /** Delete every node and index. */
257
+ clear(): Promise<void>
258
+ /** Middleware over incoming P2P operation batches. */
259
+ use(middleware: (operations: any[]) => Promise<any[]> | any[]): void
260
+ /** P2P room (present when `rtc` is enabled). */
261
+ room?: Room
262
+ /** This peer's id (present when `rtc` is enabled). */
263
+ selfId?: string
264
+ /** Security Manager (present when `sm` is configured). */
265
+ sm?: SecurityManager
266
+ [module: string]: any
267
+ }
268
+
269
+ /**
270
+ * Create (or open) a database.
271
+ *
272
+ * ```ts
273
+ * import { gdb } from "genosdb"
274
+ * const db = await gdb("my-app", { rtc: true })
275
+ * ```
276
+ */
277
+ export function gdb(name: string, options?: GDBOptions): Promise<GDB>
278
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genosdb",
3
- "version": "0.22.1",
3
+ "version": "0.22.2",
4
4
  "description": "GenosDB (GDB): distributed graph database in real-time, peer-to-peer, scalable storage - efficient querying of complex relationships.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",