@antfly/sdk 0.0.1
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/LICENSE +202 -0
- package/README.md +375 -0
- package/dist/index.cjs +321 -0
- package/dist/index.d.cts +1725 -0
- package/dist/index.d.ts +1725 -0
- package/dist/index.js +284 -0
- package/package.json +75 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import createClient from "openapi-fetch";
|
|
3
|
+
var AntflyClient = class {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
/**
|
|
6
|
+
* Table operations
|
|
7
|
+
*/
|
|
8
|
+
this.tables = {
|
|
9
|
+
/**
|
|
10
|
+
* List all tables
|
|
11
|
+
*/
|
|
12
|
+
list: async () => {
|
|
13
|
+
const { data, error } = await this.client.GET("/table", {});
|
|
14
|
+
if (error) throw new Error(`Failed to list tables: ${error.error}`);
|
|
15
|
+
return data;
|
|
16
|
+
},
|
|
17
|
+
/**
|
|
18
|
+
* Get table details and status
|
|
19
|
+
*/
|
|
20
|
+
get: async (tableName) => {
|
|
21
|
+
const { data, error } = await this.client.GET("/table/{tableName}", {
|
|
22
|
+
params: { path: { tableName } }
|
|
23
|
+
});
|
|
24
|
+
if (error) throw new Error(`Failed to get table: ${error.error}`);
|
|
25
|
+
return data;
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* Create a new table
|
|
29
|
+
*/
|
|
30
|
+
create: async (tableName, config = {}) => {
|
|
31
|
+
const { data, error } = await this.client.POST("/table/{tableName}", {
|
|
32
|
+
params: { path: { tableName } },
|
|
33
|
+
body: config
|
|
34
|
+
});
|
|
35
|
+
if (error) throw new Error(`Failed to create table: ${error.error}`);
|
|
36
|
+
return data;
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Drop a table
|
|
40
|
+
*/
|
|
41
|
+
drop: async (tableName) => {
|
|
42
|
+
const { error } = await this.client.DELETE("/table/{tableName}", {
|
|
43
|
+
params: { path: { tableName } }
|
|
44
|
+
});
|
|
45
|
+
if (error) throw new Error(`Failed to drop table: ${error.error}`);
|
|
46
|
+
return true;
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Query a specific table
|
|
50
|
+
*/
|
|
51
|
+
query: async (tableName, request) => {
|
|
52
|
+
const { data, error } = await this.client.POST("/table/{tableName}/query", {
|
|
53
|
+
params: { path: { tableName } },
|
|
54
|
+
body: request
|
|
55
|
+
});
|
|
56
|
+
if (error) throw new Error(`Table query failed: ${error.error}`);
|
|
57
|
+
return data;
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Perform batch operations on a table
|
|
61
|
+
*/
|
|
62
|
+
batch: async (tableName, request) => {
|
|
63
|
+
const { data, error } = await this.client.POST("/table/{tableName}/batch", {
|
|
64
|
+
params: { path: { tableName } },
|
|
65
|
+
// @ts-expect-error Our BatchRequest type allows any object shape for inserts
|
|
66
|
+
body: request
|
|
67
|
+
});
|
|
68
|
+
if (error) throw new Error(`Batch operation failed: ${error.error}`);
|
|
69
|
+
return data;
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Backup a table
|
|
73
|
+
*/
|
|
74
|
+
backup: async (tableName, request) => {
|
|
75
|
+
const { data, error } = await this.client.POST("/table/{tableName}/backup", {
|
|
76
|
+
params: { path: { tableName } },
|
|
77
|
+
body: request
|
|
78
|
+
});
|
|
79
|
+
if (error) throw new Error(`Backup failed: ${error.error}`);
|
|
80
|
+
return data;
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Restore a table from backup
|
|
84
|
+
*/
|
|
85
|
+
restore: async (tableName, request) => {
|
|
86
|
+
const { data, error } = await this.client.POST("/table/{tableName}/restore", {
|
|
87
|
+
params: { path: { tableName } },
|
|
88
|
+
body: request
|
|
89
|
+
});
|
|
90
|
+
if (error) throw new Error(`Restore failed: ${error.error}`);
|
|
91
|
+
return data;
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Lookup a specific key in a table
|
|
95
|
+
*/
|
|
96
|
+
lookup: async (tableName, key) => {
|
|
97
|
+
const { data, error } = await this.client.GET("/table/{tableName}/key/{key}", {
|
|
98
|
+
params: { path: { tableName, key } }
|
|
99
|
+
});
|
|
100
|
+
if (error) throw new Error(`Key lookup failed: ${error.error}`);
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Index operations
|
|
106
|
+
*/
|
|
107
|
+
this.indexes = {
|
|
108
|
+
/**
|
|
109
|
+
* List all indexes for a table
|
|
110
|
+
*/
|
|
111
|
+
list: async (tableName) => {
|
|
112
|
+
const { data, error } = await this.client.GET("/table/{tableName}/index", {
|
|
113
|
+
params: { path: { tableName } }
|
|
114
|
+
});
|
|
115
|
+
if (error) throw new Error(`Failed to list indexes: ${error.error}`);
|
|
116
|
+
return data;
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Get index details
|
|
120
|
+
*/
|
|
121
|
+
get: async (tableName, indexName) => {
|
|
122
|
+
const { data, error } = await this.client.GET("/table/{tableName}/index/{indexName}", {
|
|
123
|
+
params: { path: { tableName, indexName } }
|
|
124
|
+
});
|
|
125
|
+
if (error) throw new Error(`Failed to get index: ${error.error}`);
|
|
126
|
+
return data;
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Create a new index
|
|
130
|
+
*/
|
|
131
|
+
create: async (tableName, indexName, config) => {
|
|
132
|
+
const { error } = await this.client.POST("/table/{tableName}/index/{indexName}", {
|
|
133
|
+
params: { path: { tableName, indexName } },
|
|
134
|
+
body: config
|
|
135
|
+
});
|
|
136
|
+
if (error) throw new Error(`Failed to create index: ${error.error}`);
|
|
137
|
+
return true;
|
|
138
|
+
},
|
|
139
|
+
/**
|
|
140
|
+
* Drop an index
|
|
141
|
+
*/
|
|
142
|
+
drop: async (tableName, indexName) => {
|
|
143
|
+
const { error } = await this.client.DELETE("/table/{tableName}/index/{indexName}", {
|
|
144
|
+
params: { path: { tableName, indexName } }
|
|
145
|
+
});
|
|
146
|
+
if (error) throw new Error(`Failed to drop index: ${error.error}`);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* User management operations
|
|
152
|
+
*/
|
|
153
|
+
this.users = {
|
|
154
|
+
/**
|
|
155
|
+
* Get user details
|
|
156
|
+
*/
|
|
157
|
+
get: async (userName) => {
|
|
158
|
+
const { data, error } = await this.client.GET("/user/{userName}", {
|
|
159
|
+
params: { path: { userName } }
|
|
160
|
+
});
|
|
161
|
+
if (error) throw new Error(`Failed to get user: ${error.error}`);
|
|
162
|
+
return data;
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Create a new user
|
|
166
|
+
*/
|
|
167
|
+
create: async (userName, request) => {
|
|
168
|
+
const { data, error } = await this.client.POST("/user/{userName}", {
|
|
169
|
+
params: { path: { userName } },
|
|
170
|
+
body: request
|
|
171
|
+
});
|
|
172
|
+
if (error) throw new Error(`Failed to create user: ${error.error}`);
|
|
173
|
+
return data;
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* Delete a user
|
|
177
|
+
*/
|
|
178
|
+
delete: async (userName) => {
|
|
179
|
+
const { error } = await this.client.DELETE("/user/{userName}", {
|
|
180
|
+
params: { path: { userName } }
|
|
181
|
+
});
|
|
182
|
+
if (error) throw new Error(`Failed to delete user: ${error.error}`);
|
|
183
|
+
return true;
|
|
184
|
+
},
|
|
185
|
+
/**
|
|
186
|
+
* Update user password
|
|
187
|
+
*/
|
|
188
|
+
updatePassword: async (userName, newPassword) => {
|
|
189
|
+
const { data, error } = await this.client.PUT("/user/{userName}/password", {
|
|
190
|
+
params: { path: { userName } },
|
|
191
|
+
body: { new_password: newPassword }
|
|
192
|
+
});
|
|
193
|
+
if (error) throw new Error(`Failed to update password: ${error.error}`);
|
|
194
|
+
return data;
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
197
|
+
* Get user permissions
|
|
198
|
+
*/
|
|
199
|
+
getPermissions: async (userName) => {
|
|
200
|
+
const { data, error } = await this.client.GET("/user/{userName}/permission", {
|
|
201
|
+
params: { path: { userName } }
|
|
202
|
+
});
|
|
203
|
+
if (error) throw new Error(`Failed to get permissions: ${error.error}`);
|
|
204
|
+
return data;
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* Add permission to user
|
|
208
|
+
*/
|
|
209
|
+
addPermission: async (userName, permission) => {
|
|
210
|
+
const { data, error } = await this.client.POST("/user/{userName}/permission", {
|
|
211
|
+
params: { path: { userName } },
|
|
212
|
+
body: permission
|
|
213
|
+
});
|
|
214
|
+
if (error) throw new Error(`Failed to add permission: ${error.error}`);
|
|
215
|
+
return data;
|
|
216
|
+
},
|
|
217
|
+
/**
|
|
218
|
+
* Remove permission from user
|
|
219
|
+
*/
|
|
220
|
+
removePermission: async (userName, resource, resourceType) => {
|
|
221
|
+
const { error } = await this.client.DELETE("/user/{userName}/permission", {
|
|
222
|
+
params: {
|
|
223
|
+
path: { userName },
|
|
224
|
+
query: { resource, resourceType }
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
if (error) throw new Error(`Failed to remove permission: ${error.error}`);
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
this.config = config;
|
|
232
|
+
const headers = {
|
|
233
|
+
"Content-Type": "application/json",
|
|
234
|
+
...config.headers
|
|
235
|
+
};
|
|
236
|
+
if (config.auth) {
|
|
237
|
+
const auth = btoa(`${config.auth.username}:${config.auth.password}`);
|
|
238
|
+
headers["Authorization"] = `Basic ${auth}`;
|
|
239
|
+
}
|
|
240
|
+
this.client = createClient({
|
|
241
|
+
baseUrl: config.baseUrl,
|
|
242
|
+
headers
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Update authentication credentials
|
|
247
|
+
*/
|
|
248
|
+
setAuth(username, password) {
|
|
249
|
+
this.config.auth = { username, password };
|
|
250
|
+
const auth = btoa(`${username}:${password}`);
|
|
251
|
+
this.client = createClient({
|
|
252
|
+
baseUrl: this.config.baseUrl,
|
|
253
|
+
headers: {
|
|
254
|
+
...this.config.headers,
|
|
255
|
+
Authorization: `Basic ${auth}`
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Global query operations
|
|
261
|
+
*/
|
|
262
|
+
async query(request) {
|
|
263
|
+
const { data, error } = await this.client.POST("/query", {
|
|
264
|
+
body: request
|
|
265
|
+
});
|
|
266
|
+
if (error) {
|
|
267
|
+
throw new Error(`Query failed: ${error.error}`);
|
|
268
|
+
}
|
|
269
|
+
return data?.responses?.[0];
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get the underlying OpenAPI client for advanced use cases
|
|
273
|
+
*/
|
|
274
|
+
getRawClient() {
|
|
275
|
+
return this.client;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// src/index.ts
|
|
280
|
+
var index_default = AntflyClient;
|
|
281
|
+
export {
|
|
282
|
+
AntflyClient,
|
|
283
|
+
index_default as default
|
|
284
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@antfly/sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "TypeScript SDK for Antfly API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
23
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
24
|
+
"test": "jest",
|
|
25
|
+
"test:coverage": "jest --coverage",
|
|
26
|
+
"test:ts": "tsc --noEmit",
|
|
27
|
+
"lint": "eslint src/**/*.ts",
|
|
28
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
29
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
30
|
+
"generate": "npx openapi-typescript ../antfly/openapi.yaml -o ./src/antfly-api.d.ts",
|
|
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": [
|
|
35
|
+
"antfly",
|
|
36
|
+
"sdk",
|
|
37
|
+
"typescript",
|
|
38
|
+
"api",
|
|
39
|
+
"client",
|
|
40
|
+
"database",
|
|
41
|
+
"vector",
|
|
42
|
+
"search"
|
|
43
|
+
],
|
|
44
|
+
"author": "Antfly Contributors",
|
|
45
|
+
"license": "Apache-2.0",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/antfly/antfly-ts.git"
|
|
49
|
+
},
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/antfly/antfly-ts/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/antfly/antfly-ts#readme",
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@eslint/js": "^9.35.0",
|
|
56
|
+
"@types/jest": "^30.0.0",
|
|
57
|
+
"@types/node": "^24.3.1",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^8.42.0",
|
|
59
|
+
"@typescript-eslint/parser": "^8.42.0",
|
|
60
|
+
"eslint": "^9.35.0",
|
|
61
|
+
"jest": "^30.1.3",
|
|
62
|
+
"openapi-typescript": "^7.9.1",
|
|
63
|
+
"prettier": "^3.6.2",
|
|
64
|
+
"ts-jest": "^29.4.1",
|
|
65
|
+
"tsup": "^8.5.0",
|
|
66
|
+
"tsx": "^4.20.5",
|
|
67
|
+
"typescript": "^5.9.2"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"openapi-fetch": "^0.14.0"
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">=18"
|
|
74
|
+
}
|
|
75
|
+
}
|