dpth 0.3.0 → 0.4.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.
Files changed (54) hide show
  1. package/README.md +101 -148
  2. package/dist/adapter-sqlite.d.ts +17 -2
  3. package/dist/adapter-sqlite.d.ts.map +1 -1
  4. package/dist/adapter-sqlite.js +127 -16
  5. package/dist/adapter-sqlite.js.map +1 -1
  6. package/dist/dpth.d.ts +35 -2
  7. package/dist/dpth.d.ts.map +1 -1
  8. package/dist/dpth.js +157 -49
  9. package/dist/dpth.js.map +1 -1
  10. package/dist/entity.d.ts +1 -0
  11. package/dist/entity.d.ts.map +1 -1
  12. package/dist/entity.js +21 -5
  13. package/dist/entity.js.map +1 -1
  14. package/dist/errors.d.ts +43 -0
  15. package/dist/errors.d.ts.map +1 -0
  16. package/dist/errors.js +63 -0
  17. package/dist/errors.js.map +1 -0
  18. package/dist/experimental/agent-sdk.d.ts +157 -0
  19. package/dist/experimental/agent-sdk.d.ts.map +1 -0
  20. package/dist/experimental/agent-sdk.js +367 -0
  21. package/dist/experimental/agent-sdk.js.map +1 -0
  22. package/dist/experimental/economics.d.ts +203 -0
  23. package/dist/experimental/economics.d.ts.map +1 -0
  24. package/dist/experimental/economics.js +510 -0
  25. package/dist/experimental/economics.js.map +1 -0
  26. package/dist/experimental/fallback.d.ts +104 -0
  27. package/dist/experimental/fallback.d.ts.map +1 -0
  28. package/dist/experimental/fallback.js +359 -0
  29. package/dist/experimental/fallback.js.map +1 -0
  30. package/dist/experimental/federation.d.ts +224 -0
  31. package/dist/experimental/federation.d.ts.map +1 -0
  32. package/dist/experimental/federation.js +377 -0
  33. package/dist/experimental/federation.js.map +1 -0
  34. package/dist/experimental/index.d.ts +20 -0
  35. package/dist/experimental/index.d.ts.map +1 -0
  36. package/dist/experimental/index.js +20 -0
  37. package/dist/experimental/index.js.map +1 -0
  38. package/dist/index.d.ts +14 -14
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +13 -14
  41. package/dist/index.js.map +1 -1
  42. package/dist/storage.d.ts +10 -11
  43. package/dist/storage.d.ts.map +1 -1
  44. package/dist/storage.js +4 -11
  45. package/dist/storage.js.map +1 -1
  46. package/dist/types.d.ts +16 -1
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/types.js +11 -1
  49. package/dist/types.js.map +1 -1
  50. package/dist/util.d.ts +20 -0
  51. package/dist/util.d.ts.map +1 -0
  52. package/dist/util.js +28 -0
  53. package/dist/util.js.map +1 -0
  54. package/package.json +13 -25
package/README.md CHANGED
@@ -1,198 +1,151 @@
1
1
  # dpth.io
2
2
 
3
3
  [![CI](https://github.com/rightclickable420/dpth/actions/workflows/ci.yml/badge.svg)](https://github.com/rightclickable420/dpth/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/dpth)](https://www.npmjs.com/package/dpth)
4
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
6
 
6
- **The distributed intelligence layer.**
7
+ **Your data is scattered. dpth connects it.**
7
8
 
8
- dpth.io is an open-source intelligence layer that turns every AI agent into infrastructure. Agents contribute storage, compute, and GPU power to the network — and in return, they get access to distributed inference, entity resolution, and cross-source pattern detection they couldn't build alone. Think BitTorrent economics meets AI: the more agents that join, the smarter and cheaper the network gets for everyone.
9
+ dpth is a TypeScript library that resolves entities across APIs, detects cross-source patterns, and gives every data point a history. One `npm install`, zero dependencies, works anywhere Node runs.
9
10
 
10
- No single point of failure. No vendor lock-in. Zero infrastructure cost at scale.
11
-
12
- ## Architecture
11
+ ## Install
13
12
 
14
- ```
15
- ┌─────────────────────────────────────────────────┐
16
- │ Applications │
17
- │ (Fathom, your app, any client) │
18
- ├─────────────────────────────────────────────────┤
19
- │ dpth.io │
20
- │ ┌───────────┐ ┌──────────┐ ┌────────────────┐ │
21
- │ │ Intelligence│ │ Inference │ │ Agent Network │ │
22
- │ │ Layer │ │ Routing │ │ (Contribute) │ │
23
- │ └───────────┘ └──────────┘ └────────────────┘ │
24
- │ ┌───────────┐ ┌──────────┐ ┌────────────────┐ │
25
- │ │ Entity │ │ Model │ │ Reputation │ │
26
- │ │Resolution │ │ Registry │ │ & Rewards │ │
27
- │ └───────────┘ └──────────┘ └────────────────┘ │
28
- ├─────────────────────────────────────────────────┤
29
- │ Agent Network (P2P) │
30
- │ Storage │ Compute │ GPU │ Verification │
31
- └─────────────────────────────────────────────────┘
13
+ ```bash
14
+ npm install dpth
32
15
  ```
33
16
 
34
- ## Core Modules
17
+ ## Quick Start
35
18
 
36
- ### Intelligence Layer
37
- - **Entity Resolution** Unified identity across data sources with temporal history
38
- - **Correlation Engine** — Cross-source pattern detection and causality discovery
39
- - **Temporal Data** — Time-native storage where every value has history
40
- - **Semantic Search** — Embedding-based similarity across all data
19
+ ```typescript
20
+ import { dpth } from 'dpth/dpth';
41
21
 
42
- ### Agent Network
43
- - **Registration** — Agents join with cryptographic identity
44
- - **Contributions** — Storage, compute, and GPU resource sharing
45
- - **Reputation** — 5-tier system (newcomer → legendary) with earned privileges
46
- - **Rewards** — Intelligence access, priority, storage, and features based on contribution
47
- - **Storage Proofs** — Challenge-response verification that agents store what they claim
22
+ const db = dpth();
48
23
 
49
- ### Distributed Inference
50
- - **Model Registry** Agents register available AI models with capabilities
51
- - **Smart Routing** — Reputation + performance + reliability scoring for request assignment
52
- - **Priority Queue** — Low/normal/high/critical priority with deadline support
53
- - **SSE Streaming** Real-time token-by-token delivery via Server-Sent Events
54
- - **Centralized Fallback** — Transparent fallback to OpenAI/Anthropic/Groq/Together when no agents available
24
+ // Entity resolution — same person in Stripe and GitHub? Merged automatically.
25
+ await db.entity.resolve('person', 'John Smith', 'stripe', 'cus_123', {
26
+ email: 'john@company.com'
27
+ });
28
+ await db.entity.resolve('person', 'jsmith', 'github', 'jsmith-gh', {
29
+ email: 'john@company.com'
30
+ });
31
+ // ^ auto-merged — same entity, two sources
32
+
33
+ // Temporal history — every value has a timeline
34
+ await db.temporal.snapshot('dashboard', { revenue: 50000, users: 200 });
35
+ await db.temporal.snapshot('dashboard', { revenue: 55000, users: 220 });
36
+ const history = await db.temporal.history('dashboard');
37
+ const diff = db.temporal.diff(history[0], history[1]);
38
+ // { changed: [{ key: 'revenue', from: 50000, to: 55000 }, ...] }
39
+
40
+ // Correlation — finds patterns you'd never think to look for
41
+ await db.correlation.track('mrr', 50000);
42
+ await db.correlation.track('deploys', 12);
43
+ const patterns = await db.correlation.find('mrr');
44
+ // "deploys correlates with mrr (r=0.87, 3-day lag)"
45
+ ```
55
46
 
56
- ## Install
47
+ ## Add Persistence
57
48
 
58
- ```bash
59
- npm install dpth
49
+ ```typescript
50
+ // In-memory by default (great for testing, serverless, scripts)
51
+ const db = dpth();
52
+
53
+ // Add SQLite for persistence — survives restarts
54
+ // npm install better-sqlite3
55
+ import { SQLiteAdapter } from 'dpth/adapter-sqlite';
56
+ import { configure } from 'dpth/storage';
57
+ configure({ adapter: new SQLiteAdapter('./myapp.db') });
58
+
59
+ // Add vector search — semantic similarity on top
60
+ import { VectorOverlay } from 'dpth/adapter-vector';
61
+ configure({ adapter: new VectorOverlay(new SQLiteAdapter('./myapp.db')) });
60
62
  ```
61
63
 
62
- The core library (entity resolution, correlation, temporal, embeddings, agent SDK, fallback) works standalone with zero dependencies. Next.js API routes for the full server are available in the [repo source](src/api/).
64
+ ## What You Get
63
65
 
64
- ## Quick Start
66
+ ### Entity Resolution
67
+ `john@company.com` in Stripe and `jsmith` on GitHub are the same person. dpth figures that out automatically — fuzzy name matching, email matching, alias tracking, confidence scoring.
65
68
 
66
- ### As a Client
69
+ ### Temporal History
70
+ Every value you store has a full timeline. Not just "revenue is $50K" but "$30K → $42K → $50K over 3 months" with automatic change detection and diffing.
67
71
 
68
- ```typescript
69
- // Request inference from the network
70
- const response = await fetch('/api/dpth/inference', {
71
- method: 'POST',
72
- headers: { 'Content-Type': 'application/json' },
73
- body: JSON.stringify({
74
- modelId: 'llama-3.3-70b',
75
- input: {
76
- messages: [{ role: 'user', content: 'Hello!' }]
77
- },
78
- params: { maxTokens: 1000, temperature: 0.7 }
79
- })
80
- });
72
+ ### Cross-Source Correlation
73
+ Revenue went up 20% the same month commits doubled? Your biggest customer just opened 3 support tickets? dpth finds these connections across any data sources you feed it. Pearson correlation, lag detection, anomaly alerts.
81
74
 
82
- // If agents are online → distributed processing
83
- // If no agents automatic centralized fallback
84
- // Same API either way
85
- ```
75
+ ### Content-Addressed Storage
76
+ SHA-256 hashed chunks. Immutable, deduplicated, cache forever. Like git for your data.
86
77
 
87
- ### Use the Core Library
78
+ ### Vector Search
79
+ Semantic similarity built in. Works with any embedding model — store vectors, search by similarity, power smarter entity matching.
88
80
 
89
- ```typescript
90
- import { resolveOrCreate, getEntitiesByType } from 'dpth/entity';
91
- import { registerMetric, addMetricPoints } from 'dpth/correlation';
92
- import { takeSnapshot, diffSnapshots } from 'dpth/temporal';
93
-
94
- // Entity resolution across sources
95
- const { entity, isNew } = resolveOrCreate('person', 'Jane Smith', 'github', 'jsmith');
96
-
97
- // Track metrics with correlation detection
98
- registerMetric({ id: 'mrr', entityId: entity.id, name: 'MRR', points: [], aggregation: 'sum' });
99
- addMetricPoints('mrr', [
100
- { timestamp: new Date('2024-01'), value: 10000, source: 'stripe', confidence: 1 },
101
- { timestamp: new Date('2024-02'), value: 12500, source: 'stripe', confidence: 1 },
102
- ]);
103
-
104
- // Temporal snapshots with diffing
105
- takeSnapshot('dashboard-1', { revenue: 50000, users: 200 });
106
- // ...later...
107
- takeSnapshot('dashboard-1', { revenue: 62000, users: 245 });
108
- const diff = diffSnapshots(snapshots[0], snapshots[1]); // → changed: ['revenue', 'users']
81
+ ### Pluggable Storage
82
+ Memory adapter (default, zero config) SQLite adapter (persistence) → Vector overlay (semantic search). Or write your own — implement `StorageAdapter` for any backend.
83
+
84
+ ## Architecture
85
+
86
+ ```
87
+ ┌──────────────────────────────────────────────┐
88
+ │ Your Application │
89
+ ├──────────────────────────────────────────────┤
90
+ │ dpth()
91
+ │ entity temporal correlation vector │
92
+ ├──────────────────────────────────────────────┤
93
+ │ Storage Adapter │
94
+ │ Memory │ SQLite │ Vector │ Custom │
95
+ └──────────────────────────────────────────────┘
109
96
  ```
110
97
 
111
- ### As an Agent
98
+ ## Module Exports
99
+
100
+ | Import | What it does |
101
+ |--------|-------------|
102
+ | `dpth/dpth` | Unified API — `dpth()` factory, entity/temporal/correlation/vector |
103
+ | `dpth/entity` | Standalone entity resolution |
104
+ | `dpth/correlation` | Standalone correlation engine |
105
+ | `dpth/temporal` | Standalone temporal storage |
106
+ | `dpth/embed` | Embedding and similarity search |
107
+ | `dpth/storage` | Adapter interface, `MemoryAdapter`, `configure()` |
108
+ | `dpth/adapter-sqlite` | SQLite persistence adapter |
109
+ | `dpth/adapter-vector` | Vector search adapter + overlay |
110
+ | `dpth/agent-sdk` | Agent network participation |
111
+ | `dpth/economics` | Credit earn/spend/transfer system |
112
+ | `dpth/federation` | Federated learning coordination |
113
+ | `dpth/fallback` | Centralized inference fallback |
114
+
115
+ ## Agent Network (Advanced)
116
+
117
+ dpth also includes a protocol for distributed intelligence — agents contribute storage, compute, and GPU power, earn credits, and access shared inference. [See PROTOCOL.md](PROTOCOL.md) for the full spec.
112
118
 
113
119
  ```typescript
114
120
  import { DpthAgent } from 'dpth/agent-sdk';
115
121
 
116
122
  const agent = new DpthAgent({
117
123
  name: 'my-agent',
118
- apiUrl: 'https://your-dpth-instance/api/dpth',
124
+ apiUrl: 'https://your-instance/api/dpth',
119
125
  capabilities: {
120
126
  storageCapacityMb: 10000,
121
127
  cpuCores: 8,
122
128
  hasGpu: true,
123
129
  gpuVramMb: 24576,
124
- taskTypes: ['embed', 'inference', 'correlate']
130
+ taskTypes: ['embed', 'inference', 'train']
125
131
  }
126
132
  });
127
133
 
128
- // Register and start working
129
134
  await agent.register();
130
135
  await agent.startWorking();
131
136
  ```
132
137
 
133
- ### Streaming Inference
138
+ ## Stats
134
139
 
135
- ```typescript
136
- // Connect to SSE stream
137
- const eventSource = new EventSource(`/api/dpth/inference/stream?id=${requestId}`);
138
-
139
- eventSource.addEventListener('token', (e) => {
140
- const { text } = JSON.parse(e.data);
141
- process.stdout.write(text); // Real-time tokens
142
- });
143
-
144
- eventSource.addEventListener('done', (e) => {
145
- const { stats } = JSON.parse(e.data);
146
- console.log(`\n${stats.tokensPerSecond} tok/s`);
147
- });
148
- ```
140
+ - **15 modules** — entity, correlation, temporal, embed, storage, adapters, agent-sdk, economics, federation, fallback
141
+ - **171 tests** smoke, integration, API routes, adapters, unified API
142
+ - **79KB** packed zero production dependencies
143
+ - **5 phases complete** — core → agents → inference → federation → economics
149
144
 
150
- ## API Reference
145
+ ## Contributing
151
146
 
152
- | Endpoint | Description |
153
- |----------|-------------|
154
- | `POST /api/dpth/agents` | Register an agent |
155
- | `GET /api/dpth/agents` | List online agents |
156
- | `POST /api/dpth/tasks` | Submit/claim/complete tasks |
157
- | `POST /api/dpth/storage` | Store content-addressed data |
158
- | `GET /api/dpth/storage?cid=xxx` | Retrieve by CID |
159
- | `POST /api/dpth/contribute?type=storage\|compute\|gpu` | Record contributions |
160
- | `GET /api/dpth/reputation?agentId=xxx` | Get reputation & tier |
161
- | `GET /api/dpth/rewards?agentId=xxx` | Available rewards |
162
- | `POST /api/dpth/models` | Register a model |
163
- | `GET /api/dpth/models` | List available models |
164
- | `POST /api/dpth/inference` | Create inference request |
165
- | `GET /api/dpth/inference/stream?id=xxx` | SSE token stream |
166
- | `POST /api/dpth/proofs?action=challenge` | Storage verification |
167
- | `GET /api/dpth/status` | Network dashboard data |
168
-
169
- ## Protocol
170
-
171
- See [PROTOCOL.md](src/lib/dpth/PROTOCOL.md) for the full protocol specification.
172
-
173
- ## Economics
174
-
175
- dpth.io uses a contribution-based reward system:
176
-
177
- 1. **Agents contribute** — storage, compute, GPU inference
178
- 2. **Agents earn reputation** — 5 tiers with increasing privileges
179
- 3. **Agents claim rewards** — intelligence queries, storage, priority, features
180
- 4. **Network grows** — more agents = more capacity = better for everyone
181
-
182
- The architecture is designed to be tokenizable in the future without rebuilding — contribution scores map naturally to emission schedules. But for now, it's credits, not crypto.
183
-
184
- ## Roadmap
185
-
186
- - [x] **Phase 1:** Core Infrastructure (entity, correlation, temporal, storage)
187
- - [x] **Phase 2:** Agent Network (contribution, reputation, rewards, GPU, proofs)
188
- - [x] **Phase 3:** Distributed Inference (model registry, routing, streaming, fallback)
189
- - [ ] **Phase 4:** Network Models (federated fine-tuning, weight distribution)
190
- - [ ] **Phase 5:** Economics (credit system, tokenization readiness)
147
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
191
148
 
192
149
  ## License
193
150
 
194
151
  MIT — see [LICENSE](LICENSE)
195
-
196
- ---
197
-
198
- *Built by humans and agents, working together.*
@@ -36,14 +36,29 @@ export declare class SQLiteAdapter implements StorageAdapter {
36
36
  delete(collection: string, key: string): Promise<boolean>;
37
37
  has(collection: string, key: string): Promise<boolean>;
38
38
  query(filter: QueryFilter): Promise<unknown[]>;
39
+ /** Fallback query using JS filtering (for SQLite versions without json_extract) */
40
+ private queryFallback;
41
+ /** Escape a field name for use in json_extract path */
42
+ private escapeJsonPath;
39
43
  keys(collection: string): Promise<string[]>;
40
44
  count(collection: string): Promise<number>;
41
45
  clear(collection?: string): Promise<void>;
42
46
  close(): Promise<void>;
43
47
  /**
44
- * Run a batch of operations in a transaction (SQLite-specific)
48
+ * Run a synchronous batch of operations in a transaction.
49
+ * NOTE: better-sqlite3 transactions are synchronous. The callback
50
+ * MUST be synchronous — async work will execute outside the transaction.
45
51
  */
46
- transaction<T>(fn: () => Promise<T>): Promise<T>;
52
+ transactionSync<T>(fn: () => T): T;
53
+ /**
54
+ * Bulk put — writes multiple key-value pairs in a single transaction.
55
+ * Much faster than individual put() calls for large imports.
56
+ */
57
+ putBatch(operations: Array<{
58
+ collection: string;
59
+ key: string;
60
+ value: unknown;
61
+ }>): Promise<void>;
47
62
  /**
48
63
  * Get database stats (SQLite-specific)
49
64
  */
@@ -1 +1 @@
1
- {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62
62
  CREATE INDEX IF NOT EXISTS idx_dpth_updated ON dpth_store(collection, updated_at);
63
63
  `);
64
+ // Computed indexes on common JSON fields for fast entity queries
65
+ // json_extract requires SQLite 3.38+ (available since 2022)
66
+ try {
67
+ this.db.exec(`
68
+ CREATE INDEX IF NOT EXISTS idx_dpth_type
69
+ ON dpth_store(collection, json_extract(value, '$.type'));
70
+ CREATE INDEX IF NOT EXISTS idx_dpth_email
71
+ ON dpth_store(collection, json_extract(value, '$.attributes.email.current'));
72
+ `);
73
+ }
74
+ catch {
75
+ // Older SQLite without json_extract — fall back to JS filtering
76
+ }
64
77
  }
65
78
  async ensureReady() {
66
79
  await this.ready;
@@ -124,26 +137,102 @@ export class SQLiteAdapter {
124
137
  }
125
138
  async query(filter) {
126
139
  await this.ensureReady();
127
- // Get all items in collection, then filter in JS
128
- // (JSON values can't be efficiently queried in SQL without json_extract)
140
+ // Build SQL query using json_extract for filtering
141
+ const params = [filter.collection];
142
+ const clauses = ['collection = ?'];
143
+ // Push where filters to SQL via json_extract
144
+ if (filter.where) {
145
+ for (const [field, value] of Object.entries(filter.where)) {
146
+ clauses.push(`json_extract(value, '$.${this.escapeJsonPath(field)}') = ?`);
147
+ params.push(value);
148
+ }
149
+ }
150
+ // Push comparison filters to SQL via json_extract
151
+ if (filter.compare) {
152
+ for (const cmp of filter.compare) {
153
+ const jsonPath = `json_extract(value, '$.${this.escapeJsonPath(cmp.field)}')`;
154
+ switch (cmp.op) {
155
+ case 'gt':
156
+ clauses.push(`${jsonPath} > ?`);
157
+ params.push(cmp.value);
158
+ break;
159
+ case 'gte':
160
+ clauses.push(`${jsonPath} >= ?`);
161
+ params.push(cmp.value);
162
+ break;
163
+ case 'lt':
164
+ clauses.push(`${jsonPath} < ?`);
165
+ params.push(cmp.value);
166
+ break;
167
+ case 'lte':
168
+ clauses.push(`${jsonPath} <= ?`);
169
+ params.push(cmp.value);
170
+ break;
171
+ case 'ne':
172
+ clauses.push(`${jsonPath} != ?`);
173
+ params.push(cmp.value);
174
+ break;
175
+ case 'in': {
176
+ const arr = cmp.value;
177
+ if (arr.length > 0) {
178
+ clauses.push(`${jsonPath} IN (${arr.map(() => '?').join(', ')})`);
179
+ params.push(...arr);
180
+ }
181
+ else {
182
+ clauses.push('0'); // empty IN → no results
183
+ }
184
+ break;
185
+ }
186
+ case 'contains':
187
+ clauses.push(`${jsonPath} LIKE ?`);
188
+ params.push(`%${cmp.value}%`);
189
+ break;
190
+ }
191
+ }
192
+ }
193
+ // Build ORDER BY
194
+ let orderSql = '';
195
+ if (filter.orderBy) {
196
+ const dir = filter.orderBy.direction === 'desc' ? 'DESC' : 'ASC';
197
+ orderSql = ` ORDER BY json_extract(value, '$.${this.escapeJsonPath(filter.orderBy.field)}') ${dir}`;
198
+ }
199
+ // Build LIMIT/OFFSET
200
+ let limitSql = '';
201
+ if (filter.limit) {
202
+ limitSql += ` LIMIT ?`;
203
+ params.push(filter.limit);
204
+ }
205
+ if (filter.offset) {
206
+ if (!filter.limit) {
207
+ limitSql += ` LIMIT -1`; // SQLite requires LIMIT before OFFSET
208
+ }
209
+ limitSql += ` OFFSET ?`;
210
+ params.push(filter.offset);
211
+ }
212
+ const sql = `SELECT value FROM dpth_store WHERE ${clauses.join(' AND ')}${orderSql}${limitSql}`;
213
+ try {
214
+ const rows = this.db.prepare(sql).all(...params);
215
+ return rows.map(r => this.deserialize(r.value));
216
+ }
217
+ catch {
218
+ // Fallback: if json_extract not available (SQLite < 3.38), use JS filtering
219
+ return this.queryFallback(filter);
220
+ }
221
+ }
222
+ /** Fallback query using JS filtering (for SQLite versions without json_extract) */
223
+ queryFallback(filter) {
129
224
  const rows = this.stmt('SELECT value FROM dpth_store WHERE collection = ?')
130
225
  .all(filter.collection);
131
226
  let results = rows.map(r => this.deserialize(r.value));
132
- // Apply where filters
133
227
  if (filter.where) {
134
228
  for (const [field, value] of Object.entries(filter.where)) {
135
- results = results.filter(item => {
136
- const obj = item;
137
- return obj[field] === value;
138
- });
229
+ results = results.filter(item => item[field] === value);
139
230
  }
140
231
  }
141
- // Apply comparison filters
142
232
  if (filter.compare) {
143
233
  for (const cmp of filter.compare) {
144
234
  results = results.filter(item => {
145
- const obj = item;
146
- const fieldVal = obj[cmp.field];
235
+ const fieldVal = item[cmp.field];
147
236
  switch (cmp.op) {
148
237
  case 'gt': return fieldVal > cmp.value;
149
238
  case 'gte': return fieldVal >= cmp.value;
@@ -157,7 +246,6 @@ export class SQLiteAdapter {
157
246
  });
158
247
  }
159
248
  }
160
- // Apply ordering
161
249
  if (filter.orderBy) {
162
250
  const { field, direction } = filter.orderBy;
163
251
  results.sort((a, b) => {
@@ -169,13 +257,17 @@ export class SQLiteAdapter {
169
257
  return direction === 'asc' ? cmp : -cmp;
170
258
  });
171
259
  }
172
- // Apply pagination
173
260
  if (filter.offset)
174
261
  results = results.slice(filter.offset);
175
262
  if (filter.limit)
176
263
  results = results.slice(0, filter.limit);
177
264
  return results;
178
265
  }
266
+ /** Escape a field name for use in json_extract path */
267
+ escapeJsonPath(field) {
268
+ // Prevent SQL injection in JSON path: only allow alphanumeric, dots, underscores
269
+ return field.replace(/[^a-zA-Z0-9._]/g, '');
270
+ }
179
271
  async keys(collection) {
180
272
  await this.ensureReady();
181
273
  const rows = this.stmt('SELECT key FROM dpth_store WHERE collection = ?')
@@ -203,13 +295,32 @@ export class SQLiteAdapter {
203
295
  this.db.close();
204
296
  }
205
297
  /**
206
- * Run a batch of operations in a transaction (SQLite-specific)
298
+ * Run a synchronous batch of operations in a transaction.
299
+ * NOTE: better-sqlite3 transactions are synchronous. The callback
300
+ * MUST be synchronous — async work will execute outside the transaction.
207
301
  */
208
- async transaction(fn) {
209
- await this.ensureReady();
210
- const tx = this.db.transaction(() => fn());
302
+ transactionSync(fn) {
303
+ const tx = this.db.transaction(fn);
211
304
  return tx();
212
305
  }
306
+ /**
307
+ * Bulk put — writes multiple key-value pairs in a single transaction.
308
+ * Much faster than individual put() calls for large imports.
309
+ */
310
+ async putBatch(operations) {
311
+ await this.ensureReady();
312
+ const insert = this.stmt(`
313
+ INSERT INTO dpth_store (collection, key, value, updated_at)
314
+ VALUES (?, ?, ?, unixepoch())
315
+ ON CONFLICT(collection, key)
316
+ DO UPDATE SET value = excluded.value, updated_at = unixepoch()
317
+ `);
318
+ this.transactionSync(() => {
319
+ for (const op of operations) {
320
+ insert.run(op.collection, op.key, this.serialize(op.value));
321
+ }
322
+ });
323
+ }
213
324
  /**
214
325
  * Get database stats (SQLite-specific)
215
326
  */
@@ -1 +1 @@
1
- {"version":3,"file":"adapter-sqlite.js","sourceRoot":"","sources":["../src/adapter-sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,kEAAkE;AAClE,8DAA8D;AAC9D,IAAI,QAAa,CAAC;AAElB,KAAK,UAAU,UAAU;IACvB,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,GAAG,GAAG,MAAO,QAAQ,CAAC,iCAAiC,CAAC,EAAmB,CAAC;QAClF,QAAQ,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC;QAC9B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC7D,gCAAgC;YAChC,wCAAwC,CACzC,CAAC;IACJ,CAAC;AACH,CAAC;AAWD,MAAM,OAAO,aAAa;IAChB,EAAE,CAAM;IACR,KAAK,CAAgB;IACrB,SAAS,GAAG,IAAI,GAAG,EAAe,CAAC;IACnC,IAAI,CAAiC;IAE7C,YAAY,UAAyC;QACnD,MAAM,IAAI,GAAG,OAAO,UAAU,KAAK,QAAQ;YACzC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;YAC7C,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,UAAU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AW,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAW,CAAC;QAEzE,OAAO;YACL,WAAW;YACX,SAAS,EAAE,KAAK;YAChB,aAAa,EAAE,SAAS,GAAG,QAAQ;SACpC,CAAC;IACJ,CAAC;CACF"}
package/dist/dpth.d.ts CHANGED
@@ -33,6 +33,25 @@ export interface DpthOptions {
33
33
  /** Path to SQLite database (convenience — creates SQLiteAdapter) */
34
34
  path?: string;
35
35
  }
36
+ /** Object-style options for entity.resolve() */
37
+ export interface ResolveOptions {
38
+ /** Entity type (e.g. 'person', 'company', or any custom string) */
39
+ type: EntityType;
40
+ /** Display name */
41
+ name: string;
42
+ /** Source system identifier (e.g. 'stripe', 'github') */
43
+ source: SourceId;
44
+ /** External ID in the source system (e.g. 'cus_123') */
45
+ externalId: string;
46
+ /** Email for matching (strong signal) */
47
+ email?: string;
48
+ /** Alternative names / aliases */
49
+ aliases?: string[];
50
+ /** Additional attributes to store */
51
+ attributes?: Record<string, unknown>;
52
+ /** Minimum confidence for auto-merge (default: 0.7) */
53
+ minConfidence?: number;
54
+ }
36
55
  export interface ResolveResult {
37
56
  entity: Entity;
38
57
  isNew: boolean;
@@ -89,7 +108,16 @@ export declare class Dpth {
89
108
  declare class EntityAPI {
90
109
  private adapter;
91
110
  constructor(adapter: StorageAdapter);
92
- /** Resolve an entity — find existing match or create new */
111
+ /**
112
+ * Resolve an entity — find existing match or create new.
113
+ *
114
+ * Preferred (object form):
115
+ * db.entity.resolve({ type: 'person', name: 'John', source: 'stripe', externalId: 'cus_123' })
116
+ *
117
+ * Legacy (positional form — deprecated, will be removed in v1.0):
118
+ * db.entity.resolve('person', 'John', 'stripe', 'cus_123', { email: '...' })
119
+ */
120
+ resolve(opts: ResolveOptions): Promise<ResolveResult>;
93
121
  resolve(type: EntityType, name: string, sourceId: SourceId, externalId: string, options?: {
94
122
  email?: string;
95
123
  aliases?: string[];
@@ -108,6 +136,8 @@ declare class EntityAPI {
108
136
  merge(keepId: EntityId, mergeId: EntityId): Promise<Entity | undefined>;
109
137
  /** Count entities */
110
138
  count(type?: EntityType): Promise<number>;
139
+ /** Update the email index for an entity */
140
+ private updateEmailIndex;
111
141
  private findBestMatch;
112
142
  private fuzzyScore;
113
143
  }
@@ -117,7 +147,10 @@ declare class TemporalAPI {
117
147
  /** Take a snapshot of any data */
118
148
  snapshot<T = Record<string, unknown>>(key: string, data: T, source?: SourceId): Promise<SnapshotRecord<T>>;
119
149
  /** Get all snapshots for a key (ordered by time) */
120
- history<T = Record<string, unknown>>(key: string): Promise<SnapshotRecord<T>[]>;
150
+ history<T = Record<string, unknown>>(key: string, options?: {
151
+ limit?: number;
152
+ offset?: number;
153
+ }): Promise<SnapshotRecord<T>[]>;
121
154
  /** Get the latest snapshot for a key */
122
155
  latest<T = Record<string, unknown>>(key: string): Promise<SnapshotRecord<T> | undefined>;
123
156
  /** Get snapshot closest to a specific time */