taladb 0.2.3 → 0.2.5

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 (3) hide show
  1. package/dist/index.d.ts +139 -0
  2. package/package.json +11 -10
  3. package/LICENSE +0 -21
@@ -0,0 +1,139 @@
1
+ /** Similarity metric used for vector search. */
2
+ type VectorMetric = 'cosine' | 'dot' | 'euclidean';
3
+ interface VectorIndexOptions {
4
+ /** Number of dimensions in each stored vector. Enforced on insert and search. */
5
+ dimensions: number;
6
+ /** Similarity metric. Defaults to `"cosine"`. */
7
+ metric?: VectorMetric;
8
+ }
9
+ /** A single result returned by `Collection.findNearest`. */
10
+ interface VectorSearchResult<T extends Document = Document> {
11
+ /** The matched document. */
12
+ document: T;
13
+ /**
14
+ * Similarity score — higher means more similar.
15
+ * Range depends on metric: cosine ∈ [-1,1], dot ∈ ℝ, euclidean ∈ (0,1].
16
+ */
17
+ score: number;
18
+ }
19
+ type Value = null | boolean | number | string | Uint8Array | Value[] | {
20
+ [key: string]: Value;
21
+ };
22
+ type Document = {
23
+ _id?: string;
24
+ [key: string]: Value | undefined;
25
+ };
26
+ type FieldOps<T> = T extends null | undefined ? {
27
+ $exists?: boolean;
28
+ } : {
29
+ $eq?: T;
30
+ $ne?: T;
31
+ $gt?: T;
32
+ $gte?: T;
33
+ $lt?: T;
34
+ $lte?: T;
35
+ $in?: T[];
36
+ $nin?: T[];
37
+ $exists?: boolean;
38
+ /** Full-text search: matches documents where this string field contains the given token. */
39
+ $contains?: string;
40
+ };
41
+ type Filter<T extends Document = Document> = {
42
+ [K in keyof T]?: T[K] | FieldOps<T[K]>;
43
+ } & {
44
+ $and?: Filter<T>[];
45
+ $or?: Filter<T>[];
46
+ $not?: Filter<T>;
47
+ };
48
+ type Update<T extends Document = Document> = {
49
+ $set?: Partial<T>;
50
+ $unset?: {
51
+ [K in keyof T]?: true;
52
+ };
53
+ $inc?: {
54
+ [K in keyof T]?: number;
55
+ };
56
+ $push?: {
57
+ [K in keyof T]?: Value;
58
+ };
59
+ $pull?: {
60
+ [K in keyof T]?: Value;
61
+ };
62
+ };
63
+ interface Collection<T extends Document = Document> {
64
+ insert(doc: Omit<T, '_id'>): Promise<string>;
65
+ insertMany(docs: Omit<T, '_id'>[]): Promise<string[]>;
66
+ find(filter?: Filter<T>): Promise<T[]>;
67
+ findOne(filter: Filter<T>): Promise<T | null>;
68
+ updateOne(filter: Filter<T>, update: Update<T>): Promise<boolean>;
69
+ updateMany(filter: Filter<T>, update: Update<T>): Promise<number>;
70
+ deleteOne(filter: Filter<T>): Promise<boolean>;
71
+ deleteMany(filter: Filter<T>): Promise<number>;
72
+ count(filter?: Filter<T>): Promise<number>;
73
+ createIndex(field: keyof Omit<T, '_id'> & string): Promise<void>;
74
+ dropIndex(field: keyof Omit<T, '_id'> & string): Promise<void>;
75
+ /**
76
+ * Create a vector index on a numeric-array field.
77
+ *
78
+ * After creation, `findNearest` can search this field and new inserts/updates
79
+ * automatically maintain the index. Existing documents are backfilled.
80
+ *
81
+ * @example
82
+ * await articles.createVectorIndex('embedding', { dimensions: 384 });
83
+ */
84
+ createVectorIndex(field: keyof Omit<T, '_id'> & string, options: VectorIndexOptions): Promise<void>;
85
+ /** Drop a vector index. */
86
+ dropVectorIndex(field: keyof Omit<T, '_id'> & string): Promise<void>;
87
+ /**
88
+ * Find the `topK` most similar documents to `vector` using a vector index.
89
+ *
90
+ * Optionally combine with a metadata `filter` to restrict the search space
91
+ * before ranking — e.g. find the 5 most similar english-language articles.
92
+ *
93
+ * Results are ordered by descending similarity score (highest first).
94
+ *
95
+ * @example
96
+ * const results = await articles.findNearest('embedding', queryVec, 5);
97
+ * // results: Array<{ document: Article, score: number }>
98
+ *
99
+ * @example with pre-filter
100
+ * const results = await articles.findNearest('embedding', queryVec, 5, {
101
+ * locale: 'en',
102
+ * });
103
+ */
104
+ findNearest(field: keyof Omit<T, '_id'> & string, vector: number[], topK: number, filter?: Filter<T>): Promise<VectorSearchResult<T>[]>;
105
+ /**
106
+ * Subscribe to live query results. The callback receives a full snapshot of
107
+ * matching documents immediately and again after every write that could
108
+ * affect the result set.
109
+ *
110
+ * @returns An unsubscribe function. Call it to stop receiving updates.
111
+ *
112
+ * @example
113
+ * const unsub = users.subscribe({ active: true }, (docs) => {
114
+ * console.log('active users:', docs);
115
+ * });
116
+ * // later…
117
+ * unsub();
118
+ */
119
+ subscribe(filter: Filter<T>, callback: (docs: T[]) => void): () => void;
120
+ }
121
+ interface TalaDB {
122
+ collection<T extends Document = Document>(name: string): Collection<T>;
123
+ close(): Promise<void>;
124
+ }
125
+
126
+ /**
127
+ * Open a TalaDB database.
128
+ *
129
+ * @param dbName Name of the database file (used for OPFS and native file paths).
130
+ * Ignored for in-memory databases.
131
+ *
132
+ * @example
133
+ * const db = await openDB('myapp.db');
134
+ * const users = db.collection<User>('users');
135
+ * const id = await users.insert({ name: 'Alice', age: 30 });
136
+ */
137
+ declare function openDB(dbName?: string): Promise<TalaDB>;
138
+
139
+ export { type Collection, type Document, type Filter, type TalaDB, type Update, type Value, type VectorIndexOptions, type VectorMetric, type VectorSearchResult, openDB };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taladb",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Local-first document and vector database for React, React Native, and Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -16,6 +16,13 @@
16
16
  "files": [
17
17
  "dist"
18
18
  ],
19
+ "scripts": {
20
+ "prepublishOnly": "npm run build",
21
+ "build": "tsup",
22
+ "typecheck": "tsc --noEmit",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest"
25
+ },
19
26
  "keywords": [
20
27
  "database",
21
28
  "local-first",
@@ -48,13 +55,7 @@
48
55
  "vitest": "^3.2.0"
49
56
  },
50
57
  "optionalDependencies": {
51
- "@taladb/web": "0.2.3",
52
- "@taladb/node": "0.2.3"
53
- },
54
- "scripts": {
55
- "build": "tsup",
56
- "typecheck": "tsc --noEmit",
57
- "test": "vitest run",
58
- "test:watch": "vitest"
58
+ "@taladb/web": "workspace:*",
59
+ "@taladb/node": "workspace:*"
59
60
  }
60
- }
61
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 thinkgrid-labs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.