dpth 0.1.0 → 0.3.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/dist/adapter-sqlite.d.ts +56 -0
- package/dist/adapter-sqlite.d.ts.map +1 -0
- package/dist/adapter-sqlite.js +234 -0
- package/dist/adapter-sqlite.js.map +1 -0
- package/dist/adapter-vector.d.ts +59 -0
- package/dist/adapter-vector.d.ts.map +1 -0
- package/dist/adapter-vector.js +168 -0
- package/dist/adapter-vector.js.map +1 -0
- package/dist/dpth.d.ts +178 -0
- package/dist/dpth.d.ts.map +1 -0
- package/dist/dpth.js +557 -0
- package/dist/dpth.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/storage.d.ts +107 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +136 -0
- package/dist/storage.js.map +1 -0
- package/package.json +26 -2
package/dist/dpth.d.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dpth.io — Unified Database API
|
|
3
|
+
*
|
|
4
|
+
* The main entry point. One line to get a persistent, intelligent database
|
|
5
|
+
* with entity resolution, temporal history, correlation detection, and
|
|
6
|
+
* optional vector search.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { dpth } from 'dpth/dpth';
|
|
10
|
+
* const db = await dpth('./myapp.db');
|
|
11
|
+
*
|
|
12
|
+
* // Entity resolution
|
|
13
|
+
* const john = db.entity.resolve('person', 'John Smith', 'stripe', 'cus_123');
|
|
14
|
+
* db.entity.resolve('person', 'jsmith', 'github', 'jsmith'); // auto-merged
|
|
15
|
+
*
|
|
16
|
+
* // Temporal history
|
|
17
|
+
* db.temporal.snapshot('dashboard', { revenue: 50000, users: 200 });
|
|
18
|
+
* db.temporal.history('dashboard'); // all snapshots over time
|
|
19
|
+
*
|
|
20
|
+
* // Correlation
|
|
21
|
+
* db.correlation.track('mrr', 50000);
|
|
22
|
+
* db.correlation.track('deploys', 12);
|
|
23
|
+
* db.correlation.find('mrr'); // what correlates with MRR?
|
|
24
|
+
*
|
|
25
|
+
* // Clean up
|
|
26
|
+
* await db.close();
|
|
27
|
+
*/
|
|
28
|
+
import type { StorageAdapter, VectorResult } from './storage.js';
|
|
29
|
+
import type { Entity, EntityId, EntityType, SourceId, Metric } from './types.js';
|
|
30
|
+
export interface DpthOptions {
|
|
31
|
+
/** Storage adapter (default: MemoryAdapter) */
|
|
32
|
+
adapter?: StorageAdapter;
|
|
33
|
+
/** Path to SQLite database (convenience — creates SQLiteAdapter) */
|
|
34
|
+
path?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ResolveResult {
|
|
37
|
+
entity: Entity;
|
|
38
|
+
isNew: boolean;
|
|
39
|
+
confidence: number;
|
|
40
|
+
}
|
|
41
|
+
export interface SnapshotRecord<T = Record<string, unknown>> {
|
|
42
|
+
id: string;
|
|
43
|
+
key: string;
|
|
44
|
+
timestamp: Date;
|
|
45
|
+
data: T;
|
|
46
|
+
source: string;
|
|
47
|
+
}
|
|
48
|
+
export interface DiffResult {
|
|
49
|
+
added: string[];
|
|
50
|
+
removed: string[];
|
|
51
|
+
changed: Array<{
|
|
52
|
+
key: string;
|
|
53
|
+
from: unknown;
|
|
54
|
+
to: unknown;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
export interface CorrelationHit {
|
|
58
|
+
metricId: string;
|
|
59
|
+
correlation: number;
|
|
60
|
+
lagDays: number;
|
|
61
|
+
direction: 'positive' | 'negative';
|
|
62
|
+
sampleSize: number;
|
|
63
|
+
}
|
|
64
|
+
export declare class Dpth {
|
|
65
|
+
private adapter;
|
|
66
|
+
private _ready;
|
|
67
|
+
/** Entity resolution and management */
|
|
68
|
+
entity: EntityAPI;
|
|
69
|
+
/** Temporal history and snapshots */
|
|
70
|
+
temporal: TemporalAPI;
|
|
71
|
+
/** Correlation detection across metrics */
|
|
72
|
+
correlation: CorrelationAPI;
|
|
73
|
+
/** Vector search (if adapter supports it) */
|
|
74
|
+
vector: VectorAPI;
|
|
75
|
+
constructor(options?: DpthOptions);
|
|
76
|
+
private init;
|
|
77
|
+
/** Wait for initialization to complete */
|
|
78
|
+
ready(): Promise<this>;
|
|
79
|
+
/** Close the database and flush any pending writes */
|
|
80
|
+
close(): Promise<void>;
|
|
81
|
+
/** Get database stats */
|
|
82
|
+
stats(): Promise<{
|
|
83
|
+
entities: number;
|
|
84
|
+
snapshots: number;
|
|
85
|
+
metrics: number;
|
|
86
|
+
vectors: number;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
declare class EntityAPI {
|
|
90
|
+
private adapter;
|
|
91
|
+
constructor(adapter: StorageAdapter);
|
|
92
|
+
/** Resolve an entity — find existing match or create new */
|
|
93
|
+
resolve(type: EntityType, name: string, sourceId: SourceId, externalId: string, options?: {
|
|
94
|
+
email?: string;
|
|
95
|
+
aliases?: string[];
|
|
96
|
+
attributes?: Record<string, unknown>;
|
|
97
|
+
minConfidence?: number;
|
|
98
|
+
}): Promise<ResolveResult>;
|
|
99
|
+
/** Get entity by ID */
|
|
100
|
+
get(id: EntityId): Promise<Entity | undefined>;
|
|
101
|
+
/** Find entity by source reference */
|
|
102
|
+
findBySource(sourceId: SourceId, externalId: string): Promise<Entity | undefined>;
|
|
103
|
+
/** Get all entities of a type */
|
|
104
|
+
list(type?: EntityType): Promise<Entity[]>;
|
|
105
|
+
/** Update an entity attribute (temporal) */
|
|
106
|
+
setAttribute(entityId: EntityId, key: string, value: unknown, sourceId: SourceId): Promise<Entity | undefined>;
|
|
107
|
+
/** Merge two entities */
|
|
108
|
+
merge(keepId: EntityId, mergeId: EntityId): Promise<Entity | undefined>;
|
|
109
|
+
/** Count entities */
|
|
110
|
+
count(type?: EntityType): Promise<number>;
|
|
111
|
+
private findBestMatch;
|
|
112
|
+
private fuzzyScore;
|
|
113
|
+
}
|
|
114
|
+
declare class TemporalAPI {
|
|
115
|
+
private adapter;
|
|
116
|
+
constructor(adapter: StorageAdapter);
|
|
117
|
+
/** Take a snapshot of any data */
|
|
118
|
+
snapshot<T = Record<string, unknown>>(key: string, data: T, source?: SourceId): Promise<SnapshotRecord<T>>;
|
|
119
|
+
/** Get all snapshots for a key (ordered by time) */
|
|
120
|
+
history<T = Record<string, unknown>>(key: string): Promise<SnapshotRecord<T>[]>;
|
|
121
|
+
/** Get the latest snapshot for a key */
|
|
122
|
+
latest<T = Record<string, unknown>>(key: string): Promise<SnapshotRecord<T> | undefined>;
|
|
123
|
+
/** Get snapshot closest to a specific time */
|
|
124
|
+
at<T = Record<string, unknown>>(key: string, time: Date): Promise<SnapshotRecord<T> | undefined>;
|
|
125
|
+
/** Diff two snapshots */
|
|
126
|
+
diff<T extends Record<string, unknown>>(older: SnapshotRecord<T>, newer: SnapshotRecord<T>): DiffResult;
|
|
127
|
+
}
|
|
128
|
+
declare class CorrelationAPI {
|
|
129
|
+
private adapter;
|
|
130
|
+
constructor(adapter: StorageAdapter);
|
|
131
|
+
/** Track a metric value */
|
|
132
|
+
track(metricId: string, value: number, options?: {
|
|
133
|
+
source?: SourceId;
|
|
134
|
+
entityId?: EntityId;
|
|
135
|
+
name?: string;
|
|
136
|
+
unit?: string;
|
|
137
|
+
}): Promise<void>;
|
|
138
|
+
/** Find correlations for a metric */
|
|
139
|
+
find(metricId: string, options?: {
|
|
140
|
+
minCorrelation?: number;
|
|
141
|
+
maxLagDays?: number;
|
|
142
|
+
}): Promise<CorrelationHit[]>;
|
|
143
|
+
/** Get a metric's history */
|
|
144
|
+
get(metricId: string): Promise<Metric | undefined>;
|
|
145
|
+
/** List all tracked metrics */
|
|
146
|
+
list(): Promise<Metric[]>;
|
|
147
|
+
private pearson;
|
|
148
|
+
}
|
|
149
|
+
declare class VectorAPI {
|
|
150
|
+
private adapter;
|
|
151
|
+
constructor(adapter: StorageAdapter);
|
|
152
|
+
private get vec();
|
|
153
|
+
/** Check if vector search is available */
|
|
154
|
+
get available(): boolean;
|
|
155
|
+
/** Store a vector */
|
|
156
|
+
store(collection: string, key: string, vector: number[], metadata?: Record<string, unknown>): Promise<void>;
|
|
157
|
+
/** Search by vector similarity */
|
|
158
|
+
search(collection: string, vector: number[], topK?: number, minScore?: number): Promise<VectorResult[]>;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a dpth database instance.
|
|
162
|
+
*
|
|
163
|
+
* @param pathOrOptions — SQLite path string, or options object
|
|
164
|
+
* @returns Initialized Dpth instance (call .ready() if you need to await init)
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* // In-memory (default)
|
|
168
|
+
* const db = dpth();
|
|
169
|
+
*
|
|
170
|
+
* // Persistent (SQLite)
|
|
171
|
+
* const db = await dpth('./myapp.db').ready();
|
|
172
|
+
*
|
|
173
|
+
* // Custom adapter
|
|
174
|
+
* const db = dpth({ adapter: new MemoryVectorAdapter() });
|
|
175
|
+
*/
|
|
176
|
+
export declare function dpth(pathOrOptions?: string | DpthOptions): Dpth;
|
|
177
|
+
export {};
|
|
178
|
+
//# sourceMappingURL=dpth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dpth.d.ts","sourceRoot":"","sources":["../src/dpth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAiB,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EACV,MAAM,EACN,QAAQ,EACR,UAAU,EACV,QAAQ,EAER,MAAM,EAEP,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,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