@taruvi/sdk 1.2.0 → 1.2.2
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/.claude/settings.local.json +4 -1
- package/README.md +4 -11
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/lib/Database/DatabaseClient.ts +66 -25
- package/src/lib/Database/types.ts +20 -0
- package/src/lib-internal/routes/StorageRoutes.ts +1 -1
- package/src/types.ts +5 -2
package/README.md
CHANGED
|
@@ -564,7 +564,6 @@ const storage = new Storage(taruviClient)
|
|
|
564
564
|
await storage
|
|
565
565
|
.from("documents")
|
|
566
566
|
.update("path/to/file.pdf", {
|
|
567
|
-
filename: "newname.pdf",
|
|
568
567
|
visibility: "public",
|
|
569
568
|
metadata: { category: "reports" }
|
|
570
569
|
})
|
|
@@ -893,14 +892,7 @@ console.log(secret) // Secret object with value
|
|
|
893
892
|
const secrets = new Secrets(taruviClient)
|
|
894
893
|
|
|
895
894
|
await secrets.update("MY_SECRET", {
|
|
896
|
-
value:
|
|
897
|
-
hostname: "db.example.com",
|
|
898
|
-
port_number: 3306,
|
|
899
|
-
username: "admin",
|
|
900
|
-
password: "secret123"
|
|
901
|
-
},
|
|
902
|
-
tags: ["mysql", "production"],
|
|
903
|
-
secret_type: "Mysql"
|
|
895
|
+
value: "my-secret-value"
|
|
904
896
|
}).execute()
|
|
905
897
|
```
|
|
906
898
|
|
|
@@ -1162,7 +1154,8 @@ const userData: UserCreateRequest = {
|
|
|
1162
1154
|
first_name: "John",
|
|
1163
1155
|
last_name: "Doe",
|
|
1164
1156
|
is_active: true,
|
|
1165
|
-
is_staff: false
|
|
1157
|
+
is_staff: false,
|
|
1158
|
+
attributes: ""
|
|
1166
1159
|
}
|
|
1167
1160
|
|
|
1168
1161
|
// Database filters with operators
|
|
@@ -1325,4 +1318,4 @@ const client = new Client({
|
|
|
1325
1318
|
|
|
1326
1319
|
---
|
|
1327
1320
|
|
|
1328
|
-
**Generated from production code examples • Last updated: 2026-01-
|
|
1321
|
+
**Generated from production code examples • Last updated: 2026-01-12**
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type { UserCreateRequest, UserCreateResponse as UserResponse, UserDataRes
|
|
|
20
20
|
export type { Principal, Resource, Resources } from "./lib/Policy/types.js"
|
|
21
21
|
export type { RoleResponse } from "./lib/App/types.js"
|
|
22
22
|
export type { FunctionRequest, FunctionResponse, FunctionInvocation } from "./lib/Function/types.js"
|
|
23
|
-
export type { DatabaseRequest, DatabaseResponse } from "./lib/Database/types.js"
|
|
23
|
+
export type { DatabaseRequest, DatabaseResponse, FilterOperator, SortOrder } from "./lib/Database/types.js"
|
|
24
24
|
export type { StorageRequest, StorageUpdateRequest, StorageResponse } from "./lib/Storage/types.js"
|
|
25
25
|
export type { SettingsResponse } from "./lib/Settings/types.js"
|
|
26
26
|
export type { SecretRequest, SecretResponse } from "./lib/Secrets/types.js"
|
|
@@ -2,11 +2,11 @@ import type { Client } from "../../client.js";
|
|
|
2
2
|
import { DatabaseRoutes, type DatabaseRouteKey } from "../../lib-internal/routes/DatabaseRoutes.js";
|
|
3
3
|
import { HttpMethod } from "../../lib-internal/http/types.js";
|
|
4
4
|
import type { TaruviConfig, DatabaseFilters } from "../../types.js";
|
|
5
|
-
import type { UrlParams } from "./types.js";
|
|
5
|
+
import type { UrlParams, FilterOperator, SortOrder } from "./types.js";
|
|
6
6
|
import { buildQueryString } from "../../utils/utils.js";
|
|
7
7
|
|
|
8
8
|
// Used to access app data
|
|
9
|
-
export class Database {
|
|
9
|
+
export class Database<T = Record<string, unknown>> {
|
|
10
10
|
private client: Client
|
|
11
11
|
private urlParams: UrlParams
|
|
12
12
|
private config: TaruviConfig
|
|
@@ -21,35 +21,83 @@ export class Database {
|
|
|
21
21
|
this.body = body
|
|
22
22
|
this.config = this.client.getConfig()
|
|
23
23
|
this.queryParams = queryParams
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
from<U = Record<string, unknown>>(dataTables: string): Database<U> {
|
|
27
|
+
return new Database<U>(this.client, { ...this.urlParams, dataTables }, undefined, undefined)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
filter(field: string, operator: FilterOperator, value: string | number | boolean | (string | number)[]): Database<T> {
|
|
31
|
+
const filterKey = operator === 'eq' ? field : `${field}__${operator}`
|
|
32
|
+
// For 'in' and 'nin' operators, join array values with comma
|
|
33
|
+
const filterValue = Array.isArray(value) ? value.join(',') : value
|
|
34
|
+
return new Database<T>(this.client, { ...this.urlParams }, undefined, undefined, {
|
|
35
|
+
...this.queryParams,
|
|
36
|
+
[filterKey]: filterValue
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
sort(field: string, order: SortOrder = 'asc'): Database<T> {
|
|
41
|
+
const ordering = order === 'desc' ? `-${field}` : field
|
|
42
|
+
return new Database<T>(this.client, { ...this.urlParams }, undefined, undefined, {
|
|
43
|
+
...this.queryParams,
|
|
44
|
+
ordering
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
pageSize(size: number): Database<T> {
|
|
49
|
+
return new Database<T>(this.client, { ...this.urlParams }, undefined, undefined, {
|
|
50
|
+
...this.queryParams,
|
|
51
|
+
page_size: size
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
page(num: number): Database<T> {
|
|
56
|
+
return new Database<T>(this.client, { ...this.urlParams }, undefined, undefined, {
|
|
57
|
+
...this.queryParams,
|
|
58
|
+
page: num
|
|
59
|
+
})
|
|
60
|
+
}
|
|
25
61
|
|
|
26
|
-
|
|
27
|
-
return new Database(this.client, { ...this.urlParams
|
|
62
|
+
populate(populate: string[]): Database<T> {
|
|
63
|
+
return new Database<T>(this.client, { ...this.urlParams }, undefined, undefined, {
|
|
64
|
+
...this.queryParams,
|
|
65
|
+
populate: populate.join(',')
|
|
66
|
+
})
|
|
28
67
|
}
|
|
29
68
|
|
|
30
|
-
|
|
31
|
-
return new Database(this.client, { ...this.urlParams
|
|
69
|
+
get(recordId: string): Database<T> {
|
|
70
|
+
return new Database<T>(this.client, { ...this.urlParams, recordId }, HttpMethod.GET)
|
|
32
71
|
}
|
|
33
72
|
|
|
34
|
-
|
|
35
|
-
return new Database(this.client, { ...this.urlParams
|
|
73
|
+
create(body: Partial<T> | Partial<T>[]): Database<T> {
|
|
74
|
+
return new Database<T>(this.client, { ...this.urlParams }, HttpMethod.POST, body as object)
|
|
36
75
|
}
|
|
37
76
|
|
|
38
|
-
|
|
39
|
-
return new Database(this.client,
|
|
77
|
+
update(body: Partial<T> | Partial<T>[]): Database<T> {
|
|
78
|
+
return new Database<T>(this.client, { ...this.urlParams }, HttpMethod.PATCH, body as object)
|
|
40
79
|
}
|
|
41
80
|
|
|
42
|
-
|
|
43
|
-
return new Database(this.client,
|
|
81
|
+
delete(recordId: string): Database<T> {
|
|
82
|
+
return new Database<T>(this.client, { ...this.urlParams, recordId }, HttpMethod.DELETE)
|
|
44
83
|
}
|
|
45
84
|
|
|
46
|
-
|
|
47
|
-
|
|
85
|
+
async first(): Promise<T | null> {
|
|
86
|
+
const results = await this.execute()
|
|
87
|
+
if (Array.isArray(results)) {
|
|
88
|
+
return results[0] ?? null
|
|
89
|
+
}
|
|
90
|
+
return results ?? null
|
|
48
91
|
}
|
|
49
92
|
|
|
50
|
-
|
|
51
|
-
|
|
93
|
+
async count(): Promise<number> {
|
|
94
|
+
const results = await this.execute()
|
|
95
|
+
if (Array.isArray(results)) {
|
|
96
|
+
return results.length
|
|
97
|
+
}
|
|
98
|
+
return 0
|
|
52
99
|
}
|
|
100
|
+
|
|
53
101
|
private buildRoute(): string {
|
|
54
102
|
return (
|
|
55
103
|
DatabaseRoutes.baseUrl(this.config.appSlug) +
|
|
@@ -68,7 +116,7 @@ export class Database {
|
|
|
68
116
|
)
|
|
69
117
|
}
|
|
70
118
|
|
|
71
|
-
async execute() {
|
|
119
|
+
async execute(): Promise<T | T[]> {
|
|
72
120
|
// Build the API URL
|
|
73
121
|
const url = this.buildRoute()
|
|
74
122
|
|
|
@@ -93,10 +141,3 @@ export class Database {
|
|
|
93
141
|
}
|
|
94
142
|
}
|
|
95
143
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// TODO: Implement storage operations
|
|
99
|
-
// - upload files
|
|
100
|
-
// - download files
|
|
101
|
-
// - delete files
|
|
102
|
-
// - list files
|
|
@@ -3,6 +3,26 @@ import { HttpMethod } from "../../lib-internal/http/types.js"
|
|
|
3
3
|
|
|
4
4
|
export type DatabaseOperation = HttpMethod
|
|
5
5
|
|
|
6
|
+
// Filter operators matching Python SDK
|
|
7
|
+
export type FilterOperator =
|
|
8
|
+
| 'eq' // Equal
|
|
9
|
+
| 'ne' // Not equal
|
|
10
|
+
| 'gt' // Greater than
|
|
11
|
+
| 'gte' // Greater than or equal
|
|
12
|
+
| 'lt' // Less than
|
|
13
|
+
| 'lte' // Less than or equal
|
|
14
|
+
| 'in' // In array
|
|
15
|
+
| 'nin' // Not in array
|
|
16
|
+
| 'contains' // String contains (case-sensitive)
|
|
17
|
+
| 'icontains' // String contains (case-insensitive)
|
|
18
|
+
| 'startswith' // String starts with (case-sensitive)
|
|
19
|
+
| 'istartswith' // String starts with (case-insensitive)
|
|
20
|
+
| 'endswith' // String ends with (case-sensitive)
|
|
21
|
+
| 'iendswith' // String ends with (case-insensitive)
|
|
22
|
+
| 'isnull' // Is null
|
|
23
|
+
|
|
24
|
+
export type SortOrder = 'asc' | 'desc'
|
|
25
|
+
|
|
6
26
|
// Internal types
|
|
7
27
|
export interface UrlParams {
|
|
8
28
|
appSlug?: string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const StorageRoutes = {
|
|
2
2
|
baseUrl: (appslug: string, bucket: string) => `api/apps/${appslug}/storage/buckets/${bucket}/objects`,
|
|
3
|
-
path: (path: string) => "/" + path,
|
|
3
|
+
path: (path: string) => "/" + encodeURIComponent(path),
|
|
4
4
|
upload: () => "/batch-upload",
|
|
5
5
|
delete: () => "/batch-delete"
|
|
6
6
|
// bucket: (appslug: string, bucketslug: string) => `${StorageRoutesClone.baseUrl(appslug)}/${bucketslug}`
|
package/src/types.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface TaruviConfig {
|
|
|
11
11
|
export interface StorageFilters {
|
|
12
12
|
// Pagination (DRF style)
|
|
13
13
|
page?: number
|
|
14
|
-
|
|
14
|
+
page_size?: number
|
|
15
15
|
|
|
16
16
|
// Range Filters - Size (in bytes)
|
|
17
17
|
size__gte?: number
|
|
@@ -58,11 +58,14 @@ export interface StorageFilters {
|
|
|
58
58
|
export interface DatabaseFilters {
|
|
59
59
|
// Pagination (DRF style)
|
|
60
60
|
page?: number
|
|
61
|
-
|
|
61
|
+
page_size?: number
|
|
62
62
|
|
|
63
63
|
// Sorting (DRF style: "-field" for desc, "field" for asc)
|
|
64
64
|
ordering?: string
|
|
65
65
|
|
|
66
|
+
// Populate relations
|
|
67
|
+
populate?: string
|
|
68
|
+
|
|
66
69
|
// Dynamic filters - allows any field with operators
|
|
67
70
|
[key: string]: string | number | boolean | undefined
|
|
68
71
|
}
|