@m4rctr3y/reutjs 0.1.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/LICENSE +22 -0
- package/README.md +483 -0
- package/dist/client.d.ts +29 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +48 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/query-builder.d.ts +91 -0
- package/dist/query-builder.d.ts.map +1 -0
- package/dist/query-builder.js +160 -0
- package/dist/query-builder.js.map +1 -0
- package/dist/table.d.ts +56 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +234 -0
- package/dist/table.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +115 -0
- package/dist/utils.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Reut
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
# @reut/reutjs
|
|
2
|
+
|
|
3
|
+
TypeScript/JavaScript client library for Reut backend API. Provides a type-safe, fluent API similar to Supabase's JavaScript client but tailored for the Reut API structure.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **Type Safety**: Full TypeScript support with generics
|
|
8
|
+
- 🔗 **Fluent API**: Chainable query builder methods
|
|
9
|
+
- 🔄 **Relationship Loading**: Easy eager loading with `.with()`
|
|
10
|
+
- 🔍 **Advanced Filtering**: Support for relationship filters and operators
|
|
11
|
+
- 📄 **Pagination**: Built-in pagination support
|
|
12
|
+
- 🌐 **Framework Agnostic**: Works in Node.js, React, Vue, Angular, etc.
|
|
13
|
+
- 🚀 **Axios-based**: Reliable HTTP client with interceptors support
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @reut/reutjs axios
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
or
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @reut/reutjs axios
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
or
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @reut/reutjs axios
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { ReutClient } from '@reut/reutjs';
|
|
37
|
+
|
|
38
|
+
// Initialize client
|
|
39
|
+
const client = new ReutClient({
|
|
40
|
+
url: 'http://localhost:9000'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Define your types
|
|
44
|
+
interface Post {
|
|
45
|
+
id: number;
|
|
46
|
+
title: string;
|
|
47
|
+
content: string;
|
|
48
|
+
user_id: number;
|
|
49
|
+
created_at: string;
|
|
50
|
+
updated_at: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Query data
|
|
54
|
+
const posts = await client.from<Post>('posts')
|
|
55
|
+
.select(['title', 'user_id'])
|
|
56
|
+
.where('user_id', 1)
|
|
57
|
+
.with(['user_id'])
|
|
58
|
+
.page(1)
|
|
59
|
+
.limit(10)
|
|
60
|
+
.all();
|
|
61
|
+
|
|
62
|
+
console.log(posts.results);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API Reference
|
|
66
|
+
|
|
67
|
+
### ReutClient
|
|
68
|
+
|
|
69
|
+
The main client class for interacting with the Reut API.
|
|
70
|
+
|
|
71
|
+
#### Constructor
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
new ReutClient(config: ReutClientConfig)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Config Options:**
|
|
78
|
+
- `url` (string, required): Base URL of the Reut API server
|
|
79
|
+
- `token` (string, optional): Authentication token
|
|
80
|
+
- `axiosConfig` (AxiosRequestConfig, optional): Additional axios configuration
|
|
81
|
+
|
|
82
|
+
**Example:**
|
|
83
|
+
```typescript
|
|
84
|
+
const client = new ReutClient({
|
|
85
|
+
url: 'http://localhost:9000',
|
|
86
|
+
token: 'your-auth-token',
|
|
87
|
+
axiosConfig: {
|
|
88
|
+
timeout: 5000
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Methods
|
|
94
|
+
|
|
95
|
+
##### `from<T>(tableName: string): Table<T>`
|
|
96
|
+
|
|
97
|
+
Get a table instance for querying.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const postsTable = client.from<Post>('posts');
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
##### `setToken(token: string): void`
|
|
104
|
+
|
|
105
|
+
Set authentication token.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
client.setToken('new-token');
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
##### `removeToken(): void`
|
|
112
|
+
|
|
113
|
+
Remove authentication token.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
client.removeToken();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Table
|
|
120
|
+
|
|
121
|
+
Represents a database table and provides CRUD operations.
|
|
122
|
+
|
|
123
|
+
#### Query Methods (Chainable)
|
|
124
|
+
|
|
125
|
+
All query methods return the Table instance for chaining.
|
|
126
|
+
|
|
127
|
+
##### `select(columns: string[]): Table<T>`
|
|
128
|
+
|
|
129
|
+
Select specific columns.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
.select(['title', 'user_id'])
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
##### `where(column: string, operatorOrValue: WhereOperator | WhereValue, value?: WhereValue): Table<T>`
|
|
136
|
+
|
|
137
|
+
Add a where condition.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Simple equality
|
|
141
|
+
.where('user_id', 1)
|
|
142
|
+
|
|
143
|
+
// With operator
|
|
144
|
+
.where('age', 'gt', 18)
|
|
145
|
+
.where('name', 'like', 'John')
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
##### `whereIn(column: string, values: (string | number)[]): Table<T>`
|
|
149
|
+
|
|
150
|
+
Filter where column value is in array.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
.whereIn('user_id', [1, 2, 3])
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
##### `whereNotIn(column: string, values: (string | number)[]): Table<T>`
|
|
157
|
+
|
|
158
|
+
Filter where column value is not in array.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
.whereNotIn('status', ['deleted', 'archived'])
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
##### `whereLike(column: string, value: string): Table<T>`
|
|
165
|
+
|
|
166
|
+
Filter with LIKE operator (contains).
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
.whereLike('title', 'test')
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
##### `whereGt(column: string, value: number): Table<T>`
|
|
173
|
+
|
|
174
|
+
Filter where column is greater than value.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
.whereGt('age', 18)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
##### `whereGte(column: string, value: number): Table<T>`
|
|
181
|
+
|
|
182
|
+
Filter where column is greater than or equal to value.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
.whereGte('price', 100)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
##### `whereLt(column: string, value: number): Table<T>`
|
|
189
|
+
|
|
190
|
+
Filter where column is less than value.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
.whereLt('age', 65)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
##### `whereLte(column: string, value: number): Table<T>`
|
|
197
|
+
|
|
198
|
+
Filter where column is less than or equal to value.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
.whereLte('price', 1000)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
##### `whereNe(column: string, value: WhereValue): Table<T>`
|
|
205
|
+
|
|
206
|
+
Filter where column is not equal to value.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
.whereNe('status', 'deleted')
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
##### `whereIsNull(column: string): Table<T>`
|
|
213
|
+
|
|
214
|
+
Filter where column is null.
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
.whereIsNull('deleted_at')
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
##### `whereIsNotNull(column: string): Table<T>`
|
|
221
|
+
|
|
222
|
+
Filter where column is not null.
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
.whereIsNotNull('email')
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
##### `with(relationships: string[]): Table<T>`
|
|
229
|
+
|
|
230
|
+
Eager load relationships.
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
.with(['user_id', 'comments'])
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
##### `join(joinConfig: JoinConfig): Table<T>`
|
|
237
|
+
|
|
238
|
+
Add a manual join.
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
.join({
|
|
242
|
+
table: 'Users',
|
|
243
|
+
localColumn: 'user_id',
|
|
244
|
+
refColumn: 'id',
|
|
245
|
+
type: 'INNER',
|
|
246
|
+
alias: 'user'
|
|
247
|
+
})
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
##### `page(page: number): Table<T>`
|
|
251
|
+
|
|
252
|
+
Set page number for pagination.
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
.page(1)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
##### `limit(limit: number): Table<T>`
|
|
259
|
+
|
|
260
|
+
Set limit for pagination.
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
.limit(10)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
##### `offset(offset: number): Table<T>`
|
|
267
|
+
|
|
268
|
+
Set offset for pagination.
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
.offset(20)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
##### `orderBy(column: string, direction: 'asc' | 'desc' = 'asc'): Table<T>`
|
|
275
|
+
|
|
276
|
+
Order results by column.
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
.orderBy('created_at', 'desc')
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
#### CRUD Methods
|
|
283
|
+
|
|
284
|
+
##### `all(options?: QueryOptions): Promise<PaginatedResponse<T>>`
|
|
285
|
+
|
|
286
|
+
Get all records with optional query options.
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
const result = await client.from<Post>('posts')
|
|
290
|
+
.select(['title'])
|
|
291
|
+
.where('user_id', 1)
|
|
292
|
+
.page(1)
|
|
293
|
+
.limit(10)
|
|
294
|
+
.all();
|
|
295
|
+
|
|
296
|
+
console.log(result.results); // Array of posts
|
|
297
|
+
console.log(result.totalPages); // Total pages
|
|
298
|
+
console.log(result.page); // Current page
|
|
299
|
+
console.log(result.limit); // Items per page
|
|
300
|
+
console.log(result.totalItems); // Total items
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
##### `find(id: string | number, options?: { with?: string[] }): Promise<SingleResponse<T>>`
|
|
304
|
+
|
|
305
|
+
Find a single record by ID.
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
const post = await client.from<Post>('posts')
|
|
309
|
+
.find(1, { with: ['user_id'] });
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
##### `add(data: Partial<T>): Promise<SingleResponse<T>>`
|
|
313
|
+
|
|
314
|
+
Create a new record.
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
const newPost = await client.from<Post>('posts')
|
|
318
|
+
.add({
|
|
319
|
+
title: 'New Post',
|
|
320
|
+
content: 'Post content',
|
|
321
|
+
user_id: 1
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
##### `update(id: string | number, data: Partial<T>): Promise<SingleResponse<T>>`
|
|
326
|
+
|
|
327
|
+
Update a record by ID.
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
const updatedPost = await client.from<Post>('posts')
|
|
331
|
+
.update(1, {
|
|
332
|
+
title: 'Updated Title'
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
##### `delete(id: string | number): Promise<void>`
|
|
337
|
+
|
|
338
|
+
Delete a record by ID.
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
await client.from<Post>('posts').delete(1);
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Examples
|
|
345
|
+
|
|
346
|
+
### Basic Query
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
const posts = await client.from<Post>('posts')
|
|
350
|
+
.page(1)
|
|
351
|
+
.limit(10)
|
|
352
|
+
.all();
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Select Specific Columns
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
const posts = await client.from<Post>('posts')
|
|
359
|
+
.select(['title', 'user_id'])
|
|
360
|
+
.all();
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Eager Load Relationships
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
const posts = await client.from<Post>('posts')
|
|
367
|
+
.with(['user_id'])
|
|
368
|
+
.all();
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Filter by Column
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
const posts = await client.from<Post>('posts')
|
|
375
|
+
.where('user_id', 1)
|
|
376
|
+
.all();
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Filter by Relationship
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
const posts = await client.from<Post>('posts')
|
|
383
|
+
.where('user.name', 'John Doe')
|
|
384
|
+
.all();
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Complex Query
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
const posts = await client.from<Post>('posts')
|
|
391
|
+
.select(['id', 'title', 'user_id'])
|
|
392
|
+
.where('user_id', 1)
|
|
393
|
+
.whereGt('created_at', '2024-01-01')
|
|
394
|
+
.with(['user_id'])
|
|
395
|
+
.page(1)
|
|
396
|
+
.limit(10)
|
|
397
|
+
.orderBy('created_at', 'desc')
|
|
398
|
+
.all();
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Create Record
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
const newPost = await client.from<Post>('posts')
|
|
405
|
+
.add({
|
|
406
|
+
title: 'New Post',
|
|
407
|
+
content: 'Content here',
|
|
408
|
+
user_id: 1
|
|
409
|
+
});
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Update Record
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
const updated = await client.from<Post>('posts')
|
|
416
|
+
.update(1, {
|
|
417
|
+
title: 'Updated Title'
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### Delete Record
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
await client.from<Post>('posts').delete(1);
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
## Type Definitions
|
|
428
|
+
|
|
429
|
+
### PaginatedResponse<T>
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
interface PaginatedResponse<T> {
|
|
433
|
+
results: T[];
|
|
434
|
+
totalPages: number;
|
|
435
|
+
page: number;
|
|
436
|
+
limit: number;
|
|
437
|
+
totalItems: number;
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### SingleResponse<T>
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
type SingleResponse<T> = T;
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### WhereOperator
|
|
448
|
+
|
|
449
|
+
```typescript
|
|
450
|
+
type WhereOperator =
|
|
451
|
+
| 'eq' // equals
|
|
452
|
+
| 'ne' // not equals
|
|
453
|
+
| 'gt' // greater than
|
|
454
|
+
| 'gte' // greater than or equal
|
|
455
|
+
| 'lt' // less than
|
|
456
|
+
| 'lte' // less than or equal
|
|
457
|
+
| 'like' // like (contains)
|
|
458
|
+
| 'in' // in array
|
|
459
|
+
| 'nin' // not in array
|
|
460
|
+
| 'is' // is null
|
|
461
|
+
| 'isn'; // is not null
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
## Error Handling
|
|
465
|
+
|
|
466
|
+
The library throws errors for failed requests. Always wrap API calls in try-catch blocks:
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
try {
|
|
470
|
+
const posts = await client.from<Post>('posts').all();
|
|
471
|
+
} catch (error) {
|
|
472
|
+
console.error('Error fetching posts:', error.message);
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
## License
|
|
477
|
+
|
|
478
|
+
MIT
|
|
479
|
+
|
|
480
|
+
## Contributing
|
|
481
|
+
|
|
482
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
483
|
+
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type AxiosInstance } from 'axios';
|
|
2
|
+
import { Table } from './table.js';
|
|
3
|
+
import type { ReutClientConfig } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Main Reut client class
|
|
6
|
+
*/
|
|
7
|
+
export declare class ReutClient {
|
|
8
|
+
private axiosInstance;
|
|
9
|
+
private baseUrl;
|
|
10
|
+
constructor(config: ReutClientConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Get a table instance for querying
|
|
13
|
+
* @param tableName Name of the table (will be lowercased)
|
|
14
|
+
*/
|
|
15
|
+
from<T = any>(tableName: string): Table<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Get the underlying axios instance for advanced usage
|
|
18
|
+
*/
|
|
19
|
+
getAxiosInstance(): AxiosInstance;
|
|
20
|
+
/**
|
|
21
|
+
* Set authentication token
|
|
22
|
+
*/
|
|
23
|
+
setToken(token: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Remove authentication token
|
|
26
|
+
*/
|
|
27
|
+
removeToken(): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,aAAa,EAA2B,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,gBAAgB;IAiBpC;;;OAGG;IACH,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC;IAK1C;;OAEG;IACH,gBAAgB,IAAI,aAAa;IAIjC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B;;OAEG;IACH,WAAW,IAAI,IAAI;CAGpB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { Table } from './table.js';
|
|
3
|
+
/**
|
|
4
|
+
* Main Reut client class
|
|
5
|
+
*/
|
|
6
|
+
export class ReutClient {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.baseUrl = config.url.replace(/\/$/, ''); // Remove trailing slash
|
|
9
|
+
// Create axios instance
|
|
10
|
+
const axiosConfig = {
|
|
11
|
+
baseURL: this.baseUrl,
|
|
12
|
+
headers: {
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
...(config.token && { Authorization: `Bearer ${config.token}` }),
|
|
15
|
+
...config.axiosConfig?.headers,
|
|
16
|
+
},
|
|
17
|
+
...config.axiosConfig,
|
|
18
|
+
};
|
|
19
|
+
this.axiosInstance = axios.create(axiosConfig);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get a table instance for querying
|
|
23
|
+
* @param tableName Name of the table (will be lowercased)
|
|
24
|
+
*/
|
|
25
|
+
from(tableName) {
|
|
26
|
+
const normalizedTableName = tableName.toLowerCase();
|
|
27
|
+
return new Table(this.axiosInstance, normalizedTableName);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the underlying axios instance for advanced usage
|
|
31
|
+
*/
|
|
32
|
+
getAxiosInstance() {
|
|
33
|
+
return this.axiosInstance;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Set authentication token
|
|
37
|
+
*/
|
|
38
|
+
setToken(token) {
|
|
39
|
+
this.axiosInstance.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Remove authentication token
|
|
43
|
+
*/
|
|
44
|
+
removeToken() {
|
|
45
|
+
delete this.axiosInstance.defaults.headers.common['Authorization'];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsD,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC;;GAEG;AACH,MAAM,OAAO,UAAU;IAIrB,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,wBAAwB;QAEtE,wBAAwB;QACxB,MAAM,WAAW,GAAuB;YACtC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,aAAa,EAAE,UAAU,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;gBAChE,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO;aAC/B;YACD,GAAG,MAAM,CAAC,WAAW;SACtB,CAAC;QAEF,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAU,SAAiB;QAC7B,MAAM,mBAAmB,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QACpD,OAAO,IAAI,KAAK,CAAI,IAAI,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,UAAU,KAAK,EAAE,CAAC;IAClF,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACrE,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reut/reutjs - TypeScript/JavaScript client library for Reut backend API
|
|
3
|
+
*/
|
|
4
|
+
export { ReutClient } from './client.js';
|
|
5
|
+
export { Table } from './table.js';
|
|
6
|
+
export { QueryBuilder } from './query-builder.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reut/reutjs - TypeScript/JavaScript client library for Reut backend API
|
|
3
|
+
*/
|
|
4
|
+
export { ReutClient } from './client.js';
|
|
5
|
+
export { Table } from './table.js';
|
|
6
|
+
export { QueryBuilder } from './query-builder.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { QueryOptions, JoinConfig, WhereOperator, WhereValue } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Query builder for constructing complex queries
|
|
4
|
+
*/
|
|
5
|
+
export declare class QueryBuilder {
|
|
6
|
+
private options;
|
|
7
|
+
/**
|
|
8
|
+
* Select specific columns
|
|
9
|
+
*/
|
|
10
|
+
select(columns: string[]): this;
|
|
11
|
+
/**
|
|
12
|
+
* Add a where condition
|
|
13
|
+
* @param column Column name or relationship path (e.g., 'user.name')
|
|
14
|
+
* @param operatorOrValue Operator (if three params) or value (if two params)
|
|
15
|
+
* @param value Value (if operator provided)
|
|
16
|
+
*/
|
|
17
|
+
where(column: string, operatorOrValue: WhereOperator | WhereValue, value?: WhereValue): this;
|
|
18
|
+
/**
|
|
19
|
+
* Add multiple where conditions
|
|
20
|
+
*/
|
|
21
|
+
whereIn(column: string, values: (string | number)[]): this;
|
|
22
|
+
/**
|
|
23
|
+
* Add a 'not in' condition
|
|
24
|
+
*/
|
|
25
|
+
whereNotIn(column: string, values: (string | number)[]): this;
|
|
26
|
+
/**
|
|
27
|
+
* Add a 'like' condition (contains)
|
|
28
|
+
*/
|
|
29
|
+
whereLike(column: string, value: string): this;
|
|
30
|
+
/**
|
|
31
|
+
* Add a 'greater than' condition
|
|
32
|
+
*/
|
|
33
|
+
whereGt(column: string, value: number): this;
|
|
34
|
+
/**
|
|
35
|
+
* Add a 'greater than or equal' condition
|
|
36
|
+
*/
|
|
37
|
+
whereGte(column: string, value: number): this;
|
|
38
|
+
/**
|
|
39
|
+
* Add a 'less than' condition
|
|
40
|
+
*/
|
|
41
|
+
whereLt(column: string, value: number): this;
|
|
42
|
+
/**
|
|
43
|
+
* Add a 'less than or equal' condition
|
|
44
|
+
*/
|
|
45
|
+
whereLte(column: string, value: number): this;
|
|
46
|
+
/**
|
|
47
|
+
* Add a 'not equal' condition
|
|
48
|
+
*/
|
|
49
|
+
whereNe(column: string, value: WhereValue): this;
|
|
50
|
+
/**
|
|
51
|
+
* Add an 'is null' condition
|
|
52
|
+
*/
|
|
53
|
+
whereIsNull(column: string): this;
|
|
54
|
+
/**
|
|
55
|
+
* Add an 'is not null' condition
|
|
56
|
+
*/
|
|
57
|
+
whereIsNotNull(column: string): this;
|
|
58
|
+
/**
|
|
59
|
+
* Eager load relationships
|
|
60
|
+
*/
|
|
61
|
+
with(relationships: string[]): this;
|
|
62
|
+
/**
|
|
63
|
+
* Add a manual join
|
|
64
|
+
*/
|
|
65
|
+
join(joinConfig: JoinConfig): this;
|
|
66
|
+
/**
|
|
67
|
+
* Set page number for pagination
|
|
68
|
+
*/
|
|
69
|
+
page(page: number): this;
|
|
70
|
+
/**
|
|
71
|
+
* Set limit for pagination
|
|
72
|
+
*/
|
|
73
|
+
limit(limit: number): this;
|
|
74
|
+
/**
|
|
75
|
+
* Set offset for pagination
|
|
76
|
+
*/
|
|
77
|
+
offset(offset: number): this;
|
|
78
|
+
/**
|
|
79
|
+
* Order by column
|
|
80
|
+
*/
|
|
81
|
+
orderBy(column: string, direction?: 'asc' | 'desc'): this;
|
|
82
|
+
/**
|
|
83
|
+
* Get the built query options
|
|
84
|
+
*/
|
|
85
|
+
getOptions(): QueryOptions;
|
|
86
|
+
/**
|
|
87
|
+
* Reset the query builder
|
|
88
|
+
*/
|
|
89
|
+
reset(): this;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=query-builder.d.ts.map
|