@seaverse/dataservice 1.2.0 → 1.3.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/README.md +25 -7
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +14 -1
- package/dist/index.mjs +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,9 +22,9 @@ npm install @seaverse/dataservice
|
|
|
22
22
|
```typescript
|
|
23
23
|
import { createClient } from '@seaverse/dataservice';
|
|
24
24
|
|
|
25
|
-
// Create client (uses default SeaVerse API, appId auto-extracted from URL)
|
|
25
|
+
// Create client (Bearer prefix auto-added, uses default SeaVerse API, appId auto-extracted from URL)
|
|
26
26
|
const client = createClient({
|
|
27
|
-
token: '
|
|
27
|
+
token: 'your-jwt-token',
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
// Access user data table
|
|
@@ -47,8 +47,11 @@ const pending = await orders
|
|
|
47
47
|
// Update data
|
|
48
48
|
await orders.patch(order.id, { status: 'completed' });
|
|
49
49
|
|
|
50
|
-
// Delete
|
|
50
|
+
// Delete single record
|
|
51
51
|
await orders.delete(order.id);
|
|
52
|
+
|
|
53
|
+
// Or delete all records in collection
|
|
54
|
+
const deletedCount = await orders.deleteAll();
|
|
52
55
|
```
|
|
53
56
|
|
|
54
57
|
## Core Concepts
|
|
@@ -134,7 +137,7 @@ interface DataRecord<T> {
|
|
|
134
137
|
import { createClient } from '@seaverse/dataservice';
|
|
135
138
|
|
|
136
139
|
const client = createClient({
|
|
137
|
-
token: string; // JWT token (
|
|
140
|
+
token: string; // JWT token (Bearer prefix optional, auto-added if missing)
|
|
138
141
|
url?: string; // PostgREST API URL (default: https://dataservice-api.seaverse.ai)
|
|
139
142
|
options?: {
|
|
140
143
|
timeout?: number; // Request timeout in ms (default: 30000)
|
|
@@ -146,7 +149,12 @@ const client = createClient({
|
|
|
146
149
|
**Examples:**
|
|
147
150
|
|
|
148
151
|
```typescript
|
|
149
|
-
// Use default SeaVerse API
|
|
152
|
+
// Use default SeaVerse API (Bearer prefix auto-added)
|
|
153
|
+
const client = createClient({
|
|
154
|
+
token: 'your-jwt-token',
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Or with explicit Bearer prefix (both work)
|
|
150
158
|
const client = createClient({
|
|
151
159
|
token: 'Bearer your-jwt-token',
|
|
152
160
|
});
|
|
@@ -154,7 +162,7 @@ const client = createClient({
|
|
|
154
162
|
// Use custom API endpoint
|
|
155
163
|
const client = createClient({
|
|
156
164
|
url: 'https://your-custom-api.example.com',
|
|
157
|
-
token: '
|
|
165
|
+
token: 'your-jwt-token',
|
|
158
166
|
});
|
|
159
167
|
```
|
|
160
168
|
|
|
@@ -213,9 +221,12 @@ collection.patch(id: string, partial: Partial<T>): Promise<DataRecord<T>>
|
|
|
213
221
|
#### Delete
|
|
214
222
|
|
|
215
223
|
```typescript
|
|
216
|
-
// Hard delete (permanent)
|
|
224
|
+
// Hard delete single record (permanent)
|
|
217
225
|
collection.delete(id: string): Promise<void>
|
|
218
226
|
|
|
227
|
+
// Hard delete all records in collection (returns count of deleted records)
|
|
228
|
+
collection.deleteAll(): Promise<number>
|
|
229
|
+
|
|
219
230
|
// Soft delete (sets deleted_at timestamp)
|
|
220
231
|
collection.softDelete(id: string): Promise<boolean>
|
|
221
232
|
|
|
@@ -336,6 +347,13 @@ await orders.patch(order.id, { status: 'shipped' });
|
|
|
336
347
|
const customerOrders = await orders.search({
|
|
337
348
|
customer_email: 'customer@example.com',
|
|
338
349
|
});
|
|
350
|
+
|
|
351
|
+
// Delete a specific order
|
|
352
|
+
await orders.delete(order.id);
|
|
353
|
+
|
|
354
|
+
// Delete all orders (useful for cleanup)
|
|
355
|
+
const deletedCount = await orders.deleteAll();
|
|
356
|
+
console.log(`Deleted ${deletedCount} orders`);
|
|
339
357
|
```
|
|
340
358
|
|
|
341
359
|
### Chat Conversations
|
package/dist/index.d.mts
CHANGED
|
@@ -195,6 +195,8 @@ interface Collection<T = any> {
|
|
|
195
195
|
patch(id: string, partial: Partial<T>): Promise<DataRecord<T>>;
|
|
196
196
|
/** Hard delete a record by ID */
|
|
197
197
|
delete(id: string): Promise<void>;
|
|
198
|
+
/** Hard delete all records in this collection */
|
|
199
|
+
deleteAll(): Promise<number>;
|
|
198
200
|
/** Soft delete a record by ID (sets deleted_at) */
|
|
199
201
|
softDelete(id: string): Promise<boolean>;
|
|
200
202
|
/** Restore a soft-deleted record */
|
|
@@ -254,7 +256,12 @@ interface DataServiceClient {
|
|
|
254
256
|
*
|
|
255
257
|
* @example
|
|
256
258
|
* ```typescript
|
|
257
|
-
* // Use default SeaVerse API endpoint
|
|
259
|
+
* // Use default SeaVerse API endpoint (Bearer prefix auto-added)
|
|
260
|
+
* const client = createClient({
|
|
261
|
+
* token: 'your-jwt-token-here',
|
|
262
|
+
* });
|
|
263
|
+
*
|
|
264
|
+
* // Or with explicit Bearer prefix (both work)
|
|
258
265
|
* const client = createClient({
|
|
259
266
|
* token: 'Bearer your-jwt-token-here',
|
|
260
267
|
* });
|
|
@@ -262,7 +269,7 @@ interface DataServiceClient {
|
|
|
262
269
|
* // Or specify custom endpoint
|
|
263
270
|
* const client = createClient({
|
|
264
271
|
* url: 'https://your-postgrest-api.example.com',
|
|
265
|
-
* token: '
|
|
272
|
+
* token: 'your-jwt-token-here',
|
|
266
273
|
* });
|
|
267
274
|
*
|
|
268
275
|
* // appId is automatically extracted from current URL
|
|
@@ -284,9 +291,9 @@ declare function createClient(config: ClientConfig): DataServiceClient;
|
|
|
284
291
|
* ```typescript
|
|
285
292
|
* import { createClient } from '@seaverse/dataservice';
|
|
286
293
|
*
|
|
287
|
-
* // Create client (uses default SeaVerse API)
|
|
294
|
+
* // Create client (Bearer prefix auto-added, uses default SeaVerse API)
|
|
288
295
|
* const client = createClient({
|
|
289
|
-
* token: '
|
|
296
|
+
* token: 'your-jwt-token',
|
|
290
297
|
* });
|
|
291
298
|
*
|
|
292
299
|
* // appId is automatically extracted from current URL
|
package/dist/index.d.ts
CHANGED
|
@@ -195,6 +195,8 @@ interface Collection<T = any> {
|
|
|
195
195
|
patch(id: string, partial: Partial<T>): Promise<DataRecord<T>>;
|
|
196
196
|
/** Hard delete a record by ID */
|
|
197
197
|
delete(id: string): Promise<void>;
|
|
198
|
+
/** Hard delete all records in this collection */
|
|
199
|
+
deleteAll(): Promise<number>;
|
|
198
200
|
/** Soft delete a record by ID (sets deleted_at) */
|
|
199
201
|
softDelete(id: string): Promise<boolean>;
|
|
200
202
|
/** Restore a soft-deleted record */
|
|
@@ -254,7 +256,12 @@ interface DataServiceClient {
|
|
|
254
256
|
*
|
|
255
257
|
* @example
|
|
256
258
|
* ```typescript
|
|
257
|
-
* // Use default SeaVerse API endpoint
|
|
259
|
+
* // Use default SeaVerse API endpoint (Bearer prefix auto-added)
|
|
260
|
+
* const client = createClient({
|
|
261
|
+
* token: 'your-jwt-token-here',
|
|
262
|
+
* });
|
|
263
|
+
*
|
|
264
|
+
* // Or with explicit Bearer prefix (both work)
|
|
258
265
|
* const client = createClient({
|
|
259
266
|
* token: 'Bearer your-jwt-token-here',
|
|
260
267
|
* });
|
|
@@ -262,7 +269,7 @@ interface DataServiceClient {
|
|
|
262
269
|
* // Or specify custom endpoint
|
|
263
270
|
* const client = createClient({
|
|
264
271
|
* url: 'https://your-postgrest-api.example.com',
|
|
265
|
-
* token: '
|
|
272
|
+
* token: 'your-jwt-token-here',
|
|
266
273
|
* });
|
|
267
274
|
*
|
|
268
275
|
* // appId is automatically extracted from current URL
|
|
@@ -284,9 +291,9 @@ declare function createClient(config: ClientConfig): DataServiceClient;
|
|
|
284
291
|
* ```typescript
|
|
285
292
|
* import { createClient } from '@seaverse/dataservice';
|
|
286
293
|
*
|
|
287
|
-
* // Create client (uses default SeaVerse API)
|
|
294
|
+
* // Create client (Bearer prefix auto-added, uses default SeaVerse API)
|
|
288
295
|
* const client = createClient({
|
|
289
|
-
* token: '
|
|
296
|
+
* token: 'your-jwt-token',
|
|
290
297
|
* });
|
|
291
298
|
*
|
|
292
299
|
* // appId is automatically extracted from current URL
|
package/dist/index.js
CHANGED
|
@@ -60,8 +60,9 @@ var HTTPClient = class {
|
|
|
60
60
|
this.baseUrl = (config.url || "https://dataservice-api.seaverse.ai").replace(/\/$/, "");
|
|
61
61
|
this.fetchFn = config.options?.fetch || globalThis.fetch;
|
|
62
62
|
this.timeout = config.options?.timeout || 3e4;
|
|
63
|
+
const token = config.token.startsWith("Bearer ") ? config.token : `Bearer ${config.token}`;
|
|
63
64
|
this.headers = {
|
|
64
|
-
"Authorization":
|
|
65
|
+
"Authorization": token,
|
|
65
66
|
"Content-Type": "application/json",
|
|
66
67
|
"Prefer": "return=representation",
|
|
67
68
|
...config.options?.headers
|
|
@@ -285,6 +286,18 @@ var CollectionImpl = class {
|
|
|
285
286
|
`/user_data?id=eq.${id}&app_id=eq.${this.appId}&collection_name=eq.${this.collectionName}`
|
|
286
287
|
);
|
|
287
288
|
}
|
|
289
|
+
async deleteAll() {
|
|
290
|
+
const records = await this.client.get(
|
|
291
|
+
`/user_data?app_id=eq.${this.appId}&collection_name=eq.${this.collectionName}`
|
|
292
|
+
);
|
|
293
|
+
const count = records.length;
|
|
294
|
+
if (count > 0) {
|
|
295
|
+
await this.client.delete(
|
|
296
|
+
`/user_data?app_id=eq.${this.appId}&collection_name=eq.${this.collectionName}`
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
return count;
|
|
300
|
+
}
|
|
288
301
|
async softDelete(id) {
|
|
289
302
|
const response = await this.client.post("/rpc/soft_delete_user_data", {
|
|
290
303
|
p_id: id
|
package/dist/index.mjs
CHANGED
|
@@ -32,8 +32,9 @@ var HTTPClient = class {
|
|
|
32
32
|
this.baseUrl = (config.url || "https://dataservice-api.seaverse.ai").replace(/\/$/, "");
|
|
33
33
|
this.fetchFn = config.options?.fetch || globalThis.fetch;
|
|
34
34
|
this.timeout = config.options?.timeout || 3e4;
|
|
35
|
+
const token = config.token.startsWith("Bearer ") ? config.token : `Bearer ${config.token}`;
|
|
35
36
|
this.headers = {
|
|
36
|
-
"Authorization":
|
|
37
|
+
"Authorization": token,
|
|
37
38
|
"Content-Type": "application/json",
|
|
38
39
|
"Prefer": "return=representation",
|
|
39
40
|
...config.options?.headers
|
|
@@ -257,6 +258,18 @@ var CollectionImpl = class {
|
|
|
257
258
|
`/user_data?id=eq.${id}&app_id=eq.${this.appId}&collection_name=eq.${this.collectionName}`
|
|
258
259
|
);
|
|
259
260
|
}
|
|
261
|
+
async deleteAll() {
|
|
262
|
+
const records = await this.client.get(
|
|
263
|
+
`/user_data?app_id=eq.${this.appId}&collection_name=eq.${this.collectionName}`
|
|
264
|
+
);
|
|
265
|
+
const count = records.length;
|
|
266
|
+
if (count > 0) {
|
|
267
|
+
await this.client.delete(
|
|
268
|
+
`/user_data?app_id=eq.${this.appId}&collection_name=eq.${this.collectionName}`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return count;
|
|
272
|
+
}
|
|
260
273
|
async softDelete(id) {
|
|
261
274
|
const response = await this.client.post("/rpc/soft_delete_user_data", {
|
|
262
275
|
p_id: id
|