@antfly/sdk 0.0.7 → 0.0.8

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/index.js CHANGED
@@ -106,14 +106,87 @@ var AntflyClient = class {
106
106
  },
107
107
  /**
108
108
  * Lookup a specific key in a table
109
+ * @param tableName - Name of the table
110
+ * @param key - Key of the record to lookup
111
+ * @param options - Optional parameters
112
+ * @param options.fields - Comma-separated list of fields to include (e.g., "title,author,metadata.tags")
109
113
  */
110
- lookup: async (tableName, key) => {
114
+ lookup: async (tableName, key, options) => {
111
115
  const { data, error } = await this.client.GET("/tables/{tableName}/lookup/{key}", {
112
- params: { path: { tableName, key } }
116
+ params: {
117
+ path: { tableName, key },
118
+ query: options?.fields ? { fields: options.fields } : void 0
119
+ }
113
120
  });
114
121
  if (error) throw new Error(`Key lookup failed: ${error.error}`);
115
122
  return data;
116
123
  },
124
+ /**
125
+ * Scan keys in a table within a key range
126
+ * Returns documents as an async iterable, streaming results as NDJSON.
127
+ * @param tableName - Name of the table
128
+ * @param request - Scan request with optional key range, field projection, and filtering
129
+ * @returns AsyncGenerator yielding documents with their keys
130
+ */
131
+ scan: (tableName, request) => {
132
+ const config = this.config;
133
+ async function* scanGenerator() {
134
+ const headers = {
135
+ "Content-Type": "application/json",
136
+ Accept: "application/x-ndjson"
137
+ };
138
+ if (config.auth) {
139
+ const auth = btoa(`${config.auth.username}:${config.auth.password}`);
140
+ headers["Authorization"] = `Basic ${auth}`;
141
+ }
142
+ Object.assign(headers, config.headers);
143
+ const response = await fetch(`${config.baseUrl}/tables/${tableName}/lookup`, {
144
+ method: "POST",
145
+ headers,
146
+ body: JSON.stringify(request || {})
147
+ });
148
+ if (!response.ok) {
149
+ const errorText = await response.text();
150
+ throw new Error(`Scan failed: ${response.status} ${errorText}`);
151
+ }
152
+ if (!response.body) {
153
+ throw new Error("Response body is null");
154
+ }
155
+ const reader = response.body.getReader();
156
+ const decoder = new TextDecoder();
157
+ let buffer = "";
158
+ while (true) {
159
+ const { done, value } = await reader.read();
160
+ if (done) break;
161
+ buffer += decoder.decode(value, { stream: true });
162
+ const lines = buffer.split("\n");
163
+ buffer = lines.pop() || "";
164
+ for (const line of lines) {
165
+ if (line.trim()) {
166
+ yield JSON.parse(line);
167
+ }
168
+ }
169
+ }
170
+ if (buffer.trim()) {
171
+ yield JSON.parse(buffer);
172
+ }
173
+ }
174
+ return scanGenerator();
175
+ },
176
+ /**
177
+ * Scan keys in a table and collect all results into an array
178
+ * Convenience method that consumes the scan AsyncGenerator
179
+ * @param tableName - Name of the table
180
+ * @param request - Scan request with optional key range, field projection, and filtering
181
+ * @returns Promise with array of all matching documents
182
+ */
183
+ scanAll: async (tableName, request) => {
184
+ const results = [];
185
+ for await (const doc of this.tables.scan(tableName, request)) {
186
+ results.push(doc);
187
+ }
188
+ return results;
189
+ },
117
190
  /**
118
191
  * RAG (Retrieval-Augmented Generation) query on a specific table with streaming or citations
119
192
  * @param tableName - Name of the table to query
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antfly/sdk",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "TypeScript SDK for Antfly API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -13,43 +13,38 @@
13
13
  "require": "./dist/index.cjs"
14
14
  }
15
15
  },
16
- "files": ["dist", "README.md", "LICENSE"],
17
- "scripts": {
18
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
19
- "prepare": "npm run build",
20
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
- "test": "vitest run",
22
- "test:watch": "vitest",
23
- "test:ui": "vitest --ui",
24
- "test:coverage": "vitest run --coverage",
25
- "test:ts": "tsc --noEmit",
26
- "typecheck": "tsc --noEmit",
27
- "lint": "biome check .",
28
- "lint:fix": "biome check . --write",
29
- "format": "biome format --write .",
30
- "generate": "npx openapi-typescript ../openapi.yaml -o ./src/antfly-api.d.ts --default-non-nullable=false && npx openapi-typescript ../bleve-query-openapi.yaml --client fetch -o ./src/bleve-query.d.ts --default-non-nullable=false",
31
- "prepublishOnly": "npm run test:ts && npm run lint && npm run test && npm run build",
32
- "example:node": "tsx examples/node-example.ts"
33
- },
34
- "keywords": ["antfly", "sdk", "typescript", "api", "client", "database", "vector", "search"],
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "keywords": [
22
+ "antfly",
23
+ "sdk",
24
+ "typescript",
25
+ "api",
26
+ "client",
27
+ "database",
28
+ "vector",
29
+ "search"
30
+ ],
35
31
  "author": "Antfly Contributors",
36
32
  "license": "Apache-2.0",
37
33
  "repository": {
38
34
  "type": "git",
39
- "url": "git+https://github.com/antflydb/antfly-ts.git"
35
+ "url": "git+https://github.com/antflydb/antfly-ts.git",
36
+ "directory": "packages/sdk"
40
37
  },
41
38
  "bugs": {
42
39
  "url": "https://github.com/antflydb/antfly-ts/issues"
43
40
  },
44
- "homepage": "https://github.com/antflydb/antfly-ts#readme",
41
+ "homepage": "https://github.com/antflydb/antfly-ts/tree/main/packages/sdk#readme",
45
42
  "devDependencies": {
46
- "@biomejs/biome": "^2.3.8",
47
- "@types/node": "^24.10.1",
43
+ "@types/node": "^25.0.2",
48
44
  "@vitest/ui": "^4.0.15",
49
45
  "openapi-typescript": "^7.10.1",
50
46
  "tsup": "^8.5.1",
51
47
  "tsx": "^4.21.0",
52
- "typescript": "^5.9.3",
53
48
  "vitest": "^4.0.15"
54
49
  },
55
50
  "dependencies": {
@@ -57,5 +52,19 @@
57
52
  },
58
53
  "engines": {
59
54
  "node": ">=18"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
58
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
59
+ "test": "vitest run",
60
+ "test:watch": "vitest",
61
+ "test:ui": "vitest --ui",
62
+ "test:coverage": "vitest run --coverage",
63
+ "typecheck": "tsc --noEmit",
64
+ "lint": "biome check . --write",
65
+ "format": "biome format --write .",
66
+ "generate": "openapi-typescript ../../../openapi.yaml -o ./src/antfly-api.d.ts --default-non-nullable=false && openapi-typescript ../../../bleve-query-openapi.yaml --client fetch -o ./src/bleve-query.d.ts --default-non-nullable=false",
67
+ "clean": "rm -rf dist",
68
+ "example:node": "tsx examples/node-example.ts"
60
69
  }
61
- }
70
+ }