aipexbase-js 1.0.0 → 1.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.
Files changed (2) hide show
  1. package/README.md +398 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,398 @@
1
+ # AipexBase JS SDK
2
+
3
+ 一个简洁易用的 BaaS (Backend as a Service) JavaScript SDK,提供认证、数据库操作和自定义 API 调用功能。
4
+
5
+ ## 特性
6
+
7
+ - 🔐 **用户认证** - 登录、注册、登出和用户信息管理
8
+ - 📊 **数据库操作** - 支持链式调用的 CRUD 操作
9
+ - 🔌 **自定义 API** - 灵活的 API 调用接口
10
+ - 🎯 **链式调用** - 优雅的 API 设计,支持流式编程
11
+ - 🔑 **自动 Token 管理** - 自动存储和管理用户认证 Token
12
+ - 📦 **多格式支持** - 同时支持 CommonJS 和 ES Module
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm install aipexbase-js
18
+ ```
19
+
20
+ ## 快速开始
21
+
22
+ ### 初始化客户端
23
+
24
+ ```javascript
25
+ import { createClient } from 'aipexbase-js';
26
+
27
+ const client = createClient({
28
+ baseUrl: 'https://your-api-endpoint.com',
29
+ apiKey: 'your-api-key'
30
+ });
31
+ ```
32
+
33
+ ## API 文档
34
+
35
+ ### 认证模块 (Auth)
36
+
37
+ #### 登录
38
+
39
+ 支持用户名、手机号或邮箱登录:
40
+
41
+ ```javascript
42
+ // 使用手机号登录
43
+ const result = await client.auth.login({
44
+ phone: '13800138000',
45
+ password: 'your-password'
46
+ });
47
+
48
+ // 使用邮箱登录
49
+ const result = await client.auth.login({
50
+ email: 'user@example.com',
51
+ password: 'your-password'
52
+ });
53
+
54
+ // 使用用户名登录
55
+ const result = await client.auth.login({
56
+ user_name: 'username',
57
+ password: 'your-password'
58
+ });
59
+ ```
60
+
61
+ #### 注册
62
+
63
+ ```javascript
64
+ const result = await client.auth.register({
65
+ user_name: 'newuser',
66
+ phone: '13800138000',
67
+ email: 'user@example.com',
68
+ password: 'your-password',
69
+ // 其他自定义字段.这里与AipexBase管理后台是否开发登录有关联。
70
+ });
71
+ ```
72
+
73
+ #### 获取用户信息
74
+
75
+ ```javascript
76
+ const user = await client.auth.getUser();
77
+ ```
78
+
79
+ #### 登出
80
+
81
+ ```javascript
82
+ await client.auth.logout();
83
+ ```
84
+
85
+ #### 手动设置 Token
86
+
87
+ ```javascript
88
+ client.setToken('your-auth-token');
89
+ ```
90
+
91
+ ### 数据库模块 (DB)
92
+
93
+ 数据库模块提供了丰富的链式查询接口。
94
+
95
+ #### 查询数据
96
+
97
+ ##### 列表查询
98
+
99
+ ```javascript
100
+ // 简单查询
101
+ const result = await client.db
102
+ .from('users')
103
+ .list();
104
+
105
+ // 带过滤条件
106
+ const result = await client.db
107
+ .from('users')
108
+ .list()
109
+ .eq('status', 'active')
110
+ .gt('age', 18);
111
+
112
+ // 排序
113
+ const result = await client.db
114
+ .from('users')
115
+ .list()
116
+ .order('created_at', 'desc');
117
+ ```
118
+
119
+ ##### 分页查询
120
+
121
+ ```javascript
122
+ const result = await client.db
123
+ .from('users')
124
+ .page()
125
+ .page(1, 20) // 页码,每页数量
126
+ .eq('status', 'active');
127
+ ```
128
+
129
+ ##### 获取单条数据
130
+
131
+ ```javascript
132
+ const result = await client.db
133
+ .from('users')
134
+ .get()
135
+ .eq('id', 123);
136
+ ```
137
+
138
+ #### 过滤条件
139
+
140
+ 支持多种过滤操作符:
141
+
142
+ ```javascript
143
+ // 等于
144
+ .eq('field', value)
145
+
146
+ // 不等于
147
+ .neq('field', value)
148
+
149
+ // 大于
150
+ .gt('field', value)
151
+
152
+ // 大于等于
153
+ .gte('field', value)
154
+
155
+ // 小于
156
+ .lt('field', value)
157
+
158
+ // 小于等于
159
+ .lte('field', value)
160
+
161
+ // 在范围内
162
+ .in('field', [value1, value2, value3])
163
+
164
+ // 在区间内
165
+ .between('field', [min, max])
166
+ ```
167
+
168
+ #### OR 条件查询
169
+
170
+ ```javascript
171
+ const result = await client.db
172
+ .from('users')
173
+ .list()
174
+ .eq('status', 'active')
175
+ .or((q) => {
176
+ q.eq('role', 'admin')
177
+ .eq('role', 'moderator');
178
+ });
179
+ ```
180
+
181
+ #### 排序
182
+
183
+ ```javascript
184
+ // 升序
185
+ .order('created_at', 'asc')
186
+
187
+ // 降序
188
+ .order('created_at', 'desc')
189
+
190
+ // 对象形式
191
+ .order('created_at', { ascending: true })
192
+ .order('created_at', { direction: 'desc' })
193
+ ```
194
+
195
+ #### 插入数据
196
+
197
+ ```javascript
198
+ const result = await client.db
199
+ .from('users')
200
+ .insert()
201
+ .values({
202
+ name: 'John Doe',
203
+ email: 'john@example.com',
204
+ age: 25
205
+ });
206
+ ```
207
+
208
+ #### 更新数据
209
+
210
+ ```javascript
211
+ const result = await client.db
212
+ .from('users')
213
+ .update()
214
+ .set({
215
+ status: 'inactive'
216
+ })
217
+ .eq('id', 123);
218
+ ```
219
+
220
+ #### 删除数据
221
+
222
+ ```javascript
223
+ const result = await client.db
224
+ .from('users')
225
+ .delete()
226
+ .eq('id', 123);
227
+ ```
228
+
229
+ ### API 模块
230
+
231
+ 用于调用自定义 API 接口。
232
+
233
+ #### 基本调用
234
+
235
+ ```javascript
236
+ const result = await client.api
237
+ .call('yourApiName')
238
+ .param('key1', 'value1')
239
+ .param('key2', 'value2');
240
+ ```
241
+
242
+ #### 批量设置参数
243
+
244
+ ```javascript
245
+ const result = await client.api
246
+ .call('yourApiName')
247
+ .params({
248
+ key1: 'value1',
249
+ key2: 'value2',
250
+ key3: 'value3'
251
+ });
252
+ ```
253
+
254
+ #### 自定义请求头
255
+
256
+ ```javascript
257
+ const result = await client.api
258
+ .call('yourApiName')
259
+ .header('X-Custom-Header', 'value')
260
+ .params({ data: 'value' });
261
+
262
+ // 批量设置请求头
263
+ const result = await client.api
264
+ .call('yourApiName')
265
+ .headers({
266
+ 'X-Custom-Header-1': 'value1',
267
+ 'X-Custom-Header-2': 'value2'
268
+ })
269
+ .params({ data: 'value' });
270
+ ```
271
+
272
+ ## 完整示例
273
+
274
+ ```javascript
275
+ import { createClient } from 'aipexbase-js';
276
+
277
+ // 初始化客户端
278
+ const client = createClient({
279
+ baseUrl: 'https://your-api-endpoint.com',
280
+ apiKey: 'your-api-key'
281
+ });
282
+
283
+ // 用户登录
284
+ async function login() {
285
+ try {
286
+ const result = await client.auth.login({
287
+ phone: '13800138000',
288
+ password: 'password123'
289
+ });
290
+
291
+ if (result.success) {
292
+ console.log('登录成功!');
293
+ }
294
+ } catch (error) {
295
+ console.error('登录失败:', error);
296
+ }
297
+ }
298
+
299
+ // 查询用户列表
300
+ async function getUserList() {
301
+ try {
302
+ const result = await client.db
303
+ .from('users')
304
+ .page()
305
+ .page(1, 20)
306
+ .eq('status', 'active')
307
+ .gte('age', 18)
308
+ .order('created_at', 'desc');
309
+
310
+ console.log('用户列表:', result);
311
+ } catch (error) {
312
+ console.error('查询失败:', error);
313
+ }
314
+ }
315
+
316
+ // 创建新用户
317
+ async function createUser() {
318
+ try {
319
+ const result = await client.db
320
+ .from('users')
321
+ .insert()
322
+ .values({
323
+ name: 'John Doe',
324
+ email: 'john@example.com',
325
+ age: 25,
326
+ status: 'active'
327
+ });
328
+
329
+ console.log('用户创建成功:', result);
330
+ } catch (error) {
331
+ console.error('创建失败:', error);
332
+ }
333
+ }
334
+
335
+ // 调用自定义 API
336
+ async function callCustomApi() {
337
+ try {
338
+ const result = await client.api
339
+ .call('sendEmail')
340
+ .params({
341
+ to: 'user@example.com',
342
+ subject: 'Hello',
343
+ body: 'Welcome to our service!'
344
+ });
345
+
346
+ console.log('API 调用成功:', result);
347
+ } catch (error) {
348
+ console.error('API 调用失败:', error);
349
+ }
350
+ }
351
+ ```
352
+
353
+ ## 开发
354
+
355
+ ### 本地开发
356
+
357
+ ```bash
358
+ # 安装依赖
359
+ npm install
360
+
361
+ # 构建项目
362
+ npm run build
363
+ ```
364
+
365
+ ### 项目结构
366
+
367
+ ```
368
+ aipexbase-js/
369
+ ├── src/
370
+ │ ├── client.js # 核心客户端
371
+ │ ├── index.js # 入口文件
372
+ │ └── modules/
373
+ │ ├── auth.js # 认证模块
374
+ │ ├── db.js # 数据库模块
375
+ │ ├── api.js # API 模块
376
+ │ └── ai.js # AI 模块(开发中)
377
+ ├── dist/ # 构建输出
378
+ │ ├── index.cjs.js # CommonJS 格式
379
+ │ └── index.esm.js # ES Module 格式
380
+ ├── package.json
381
+ ├── rollup.config.mjs
382
+ └── README.md
383
+ ```
384
+
385
+ ## 技术栈
386
+
387
+ - **构建工具**: Rollup
388
+ - **模块格式**: CommonJS & ES Module
389
+ - **代码压缩**: Terser
390
+
391
+ ## License
392
+
393
+ ISC
394
+
395
+ ## 贡献
396
+
397
+ 欢迎提交 Issue 和 Pull Request!
398
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aipexbase-js",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",