@rushdb/javascript-sdk 0.17.1 → 1.0.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 +75 -59
- package/dist/api/api.d.ts +260 -19
- package/dist/api/index.d.ts +0 -1
- package/dist/api/rest-api-proxy.d.ts +1 -1
- package/dist/api/types.d.ts +0 -60
- package/dist/api/utils.d.ts +3 -33
- package/dist/common/constants.d.ts +2 -0
- package/dist/common/utils.d.ts +4 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.node.d.ts +492 -69
- package/dist/index.worker.d.ts +492 -69
- package/dist/network/HttpClient.d.ts +1 -1
- package/dist/network/types.d.ts +3 -2
- package/dist/sdk/errors.d.ts +2 -1
- package/dist/sdk/model.d.ts +160 -20
- package/dist/sdk/record.d.ts +23 -67
- package/dist/sdk/sdk.d.ts +465 -42
- package/dist/sdk/utils.d.ts +2 -2
- package/dist/types/expressions.d.ts +11 -2
- package/dist/types/query.d.ts +8 -3
- package/dist/types/schema.d.ts +6 -4
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/value.d.ts +18 -11
- package/package.json +1 -1
- package/dist/api/create-api.d.ts +0 -66
package/README.md
CHANGED
|
@@ -2,96 +2,88 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
# RushDB SDK for JavaScript and TypeScript
|
|
5
|
+
# 🚀 RushDB SDK for JavaScript and TypeScript
|
|
6
|
+
|
|
7
|
+
### The Modern Graph Database Client for Web & Node.js
|
|
6
8
|
|
|
7
9
|
[](https://www.npmjs.com/package/@rushdb/javascript-sdk)
|
|
8
10
|
[](#license "Go to license section")
|
|
9
|
-
|
|
10
|
-

|
|
12
|
-
|
|
11
|
+
[](https://www.npmjs.com/package/@rushdb/javascript-sdk)
|
|
12
|
+
[](https://bundlephobia.com/package/@rushdb/javascript-sdk)
|
|
13
13
|
|
|
14
14
|
[](https://nodejs.org "Go to Node.js homepage")
|
|
15
15
|
[](https://www.npmjs.com/package/typescript "Go to TypeScript on NPM")
|
|
16
16
|
|
|
17
|
-
[
|
|
17
|
+
[🌐 Website](https://rushdb.com) • [📖 Documentation](https://docs.rushdb.com) • [☁️ Cloud Platform](https://app.rushdb.com) • [🔍 Examples](https://github.com/rush-db/examples)
|
|
18
18
|
</div>
|
|
19
19
|
|
|
20
|
-
## Highlights
|
|
20
|
+
## ✨ Highlights
|
|
21
21
|
|
|
22
22
|
---
|
|
23
|
-
> **✨ No Configuration Needed**: Plug-and-play design requires no setup or configuration.
|
|
24
|
-
|
|
25
|
-
> **🤖 Automatic Type Inference**: Enjoy seamless type safety with automatic TypeScript inference.
|
|
26
|
-
|
|
27
|
-
> **↔️ Isomorphic Architecture**: Fully compatible with both server and browser environments.
|
|
28
|
-
|
|
29
|
-
> **🏋️ Zero Dependencies**: Lightweight and efficient with no external dependencies.
|
|
30
23
|
|
|
24
|
+
- **🔌 No Configuration Needed**: Plug-and-play design requires minimal setup to get started
|
|
25
|
+
- **🛡️ Automatic Type Inference**: Enjoy seamless type safety with automatic TypeScript inference
|
|
26
|
+
- **🔄 Isomorphic Architecture**: Fully compatible with both server and browser environments
|
|
27
|
+
- **⚡ Zero Dependencies**: Lightweight (just 6.9KB gzipped) and efficient with no external dependencies
|
|
31
28
|
|
|
32
29
|
|
|
33
|
-
## Installation
|
|
30
|
+
## 📦 Installation
|
|
34
31
|
|
|
35
32
|
---
|
|
36
|
-
NPM:
|
|
37
33
|
```bash
|
|
34
|
+
# NPM
|
|
38
35
|
npm install @rushdb/javascript-sdk
|
|
39
|
-
```
|
|
40
36
|
|
|
41
|
-
YARN
|
|
42
|
-
```bash
|
|
37
|
+
# YARN
|
|
43
38
|
yarn add @rushdb/javascript-sdk
|
|
44
|
-
```
|
|
45
39
|
|
|
46
|
-
PNPM
|
|
47
|
-
|
|
48
|
-
pnmp add @rushdb/javascript-sdk
|
|
40
|
+
# PNPM
|
|
41
|
+
pnpm add @rushdb/javascript-sdk
|
|
49
42
|
```
|
|
50
43
|
|
|
51
44
|
|
|
52
|
-
## Usage
|
|
45
|
+
## 🚀 Usage
|
|
53
46
|
|
|
54
47
|
---
|
|
55
48
|
|
|
56
|
-
1. **Obtain API Token**: Grab one from the [Dashboard](https://app.rushdb.com).
|
|
49
|
+
1. **Obtain API Token**: Grab one from the [RushDB Cloud Dashboard](https://app.rushdb.com).
|
|
57
50
|
2. **Build anything**: Easily push, search, and manage relationships within your data.
|
|
58
51
|
|
|
59
|
-
###
|
|
52
|
+
### Quick Example
|
|
60
53
|
```ts
|
|
61
|
-
import RushDB
|
|
54
|
+
import RushDB from '@rushdb/javascript-sdk';
|
|
62
55
|
|
|
63
56
|
// Setup SDK
|
|
64
|
-
const db = new RushDB("API_TOKEN"
|
|
65
|
-
|
|
66
|
-
url: "https://api.rushdb.com",
|
|
67
|
-
});
|
|
57
|
+
const db = new RushDB("API_TOKEN");
|
|
58
|
+
// Default URL is "https://api.rushdb.com". See SDK Configuration for more options.
|
|
68
59
|
|
|
69
|
-
// Push any data, and RushDB will automatically flatten it into Records
|
|
60
|
+
// Push any data, and RushDB will automatically flatten it into Records
|
|
70
61
|
// and establish relationships between them accordingly.
|
|
71
|
-
await db.records.createMany(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
62
|
+
await db.records.createMany({
|
|
63
|
+
label: "COMPANY",
|
|
64
|
+
payload: {
|
|
65
|
+
name: 'Google LLC',
|
|
66
|
+
address: '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA',
|
|
67
|
+
foundedAt: '1998-09-04T00:00:00.000Z',
|
|
68
|
+
rating: 4.9,
|
|
69
|
+
DEPARTMENT: [{
|
|
70
|
+
name: 'Research & Development',
|
|
71
|
+
description: 'Innovating and creating advanced technologies for AI, cloud computing, and consumer devices.',
|
|
72
|
+
PROJECT: [{
|
|
73
|
+
name: 'Bard AI',
|
|
74
|
+
description: 'A state-of-the-art generative AI model designed for natural language understanding and creation.',
|
|
75
|
+
active: true,
|
|
76
|
+
budget: 1200000000,
|
|
77
|
+
EMPLOYEE: [{
|
|
78
|
+
name: 'Jeff Dean',
|
|
79
|
+
position: 'Head of AI Research',
|
|
80
|
+
email: 'jeff@google.com',
|
|
81
|
+
dob: '1968-07-16T00:00:00.000Z',
|
|
82
|
+
salary: 3000000
|
|
83
|
+
}]
|
|
92
84
|
}]
|
|
93
85
|
}]
|
|
94
|
-
}
|
|
86
|
+
}
|
|
95
87
|
})
|
|
96
88
|
|
|
97
89
|
|
|
@@ -110,7 +102,8 @@ const matchedEmployees = await db.records.find({
|
|
|
110
102
|
}
|
|
111
103
|
})
|
|
112
104
|
|
|
113
|
-
const company = await db.records.findUniq(
|
|
105
|
+
const company = await db.records.findUniq({
|
|
106
|
+
labels: ['COMPANY'],
|
|
114
107
|
where: {
|
|
115
108
|
name: 'Google LLC'
|
|
116
109
|
}
|
|
@@ -120,6 +113,30 @@ const company = await db.records.findUniq('COMPANY', {
|
|
|
120
113
|
await company.attach(matchedEmployees, { type: "WORKING_AT" })
|
|
121
114
|
```
|
|
122
115
|
|
|
116
|
+
## ⚙️ SDK Configuration
|
|
117
|
+
---
|
|
118
|
+
The SDK is designed to be flexible. You can provide configuration options when initializing `RushDB` to customize its behavior, such as the API endpoint or request timeouts.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import RushDB from '@rushdb/javascript-sdk';
|
|
122
|
+
|
|
123
|
+
// Example: Initialize with a custom URL and timeout
|
|
124
|
+
const db = new RushDB('API_TOKEN', {
|
|
125
|
+
url: 'http://your-custom-rushdb-server.com', // Default is 'https://api.rushdb.com'
|
|
126
|
+
timeout: 30000 // 30 seconds
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The `RushDB` constructor accepts an optional second argument for configuration. Key options include:
|
|
131
|
+
- `url`: The complete URL to the RushDB API.
|
|
132
|
+
- Alternatively, `host`, `port`, and `protocol` can be specified individually.
|
|
133
|
+
- `timeout`: Request timeout in milliseconds (default: 10000).
|
|
134
|
+
- `httpClient`: For advanced use cases, provide a custom HTTP client implementation.
|
|
135
|
+
- `logger`: Implement a custom logger for debugging or monitoring.
|
|
136
|
+
- `options.allowForceDelete`: Set to `true` to enable deleting all records without specifying criteria (defaults to `false` for safety).
|
|
137
|
+
|
|
138
|
+
For a comprehensive guide on all available configuration options, please refer to the [SDK Configuration Documentation](https://docs.rushdb.com/typescript-sdk/introduction#sdk-configuration-options).
|
|
139
|
+
|
|
123
140
|
<div align="center">
|
|
124
141
|
<b>You're Awesome!</b> 🚀
|
|
125
142
|
</div>
|
|
@@ -128,14 +145,13 @@ await company.attach(matchedEmployees, { type: "WORKING_AT" })
|
|
|
128
145
|
|
|
129
146
|
<div align="center" style="margin-top: 20px">
|
|
130
147
|
|
|
131
|
-
> Check the [
|
|
132
|
-
|
|
148
|
+
> 📚 Check the [Complete Documentation](https://docs.rushdb.com/typescript-sdk/introduction) and [Examples Repository](https://github.com/rush-db/examples) to learn more!
|
|
133
149
|
|
|
134
150
|
</div>
|
|
135
151
|
|
|
136
152
|
|
|
137
|
-
## Contributing
|
|
153
|
+
## 🤝 Contributing
|
|
138
154
|
|
|
139
155
|
---
|
|
140
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
156
|
+
We welcome contributions! See our [CONTRIBUTING.md](CONTRIBUTING.md) guide for details.
|
|
141
157
|
|
package/dist/api/api.d.ts
CHANGED
|
@@ -1,42 +1,283 @@
|
|
|
1
1
|
import type { HttpClient } from '../network/HttpClient.js';
|
|
2
|
+
import type { DBRecordTarget, RelationDetachOptions, RelationOptions, RelationTarget, Relation, DBRecordCreationOptions } from '../sdk/record.js';
|
|
2
3
|
import type { SDKConfig } from '../sdk/types.js';
|
|
3
|
-
import type { SearchQuery, Schema, PropertyValuesOptions } from '../types/index.js';
|
|
4
|
-
import type { ApiResponse
|
|
4
|
+
import type { SearchQuery, Schema, InferSchemaTypesWrite, MaybeArray, PropertyValuesOptions, PropertyDraft, Property, PropertyValuesData, AnyObject } from '../types/index.js';
|
|
5
|
+
import type { ApiResponse } from './types.js';
|
|
5
6
|
import { createFetcher } from '../network/index.js';
|
|
7
|
+
import { DBRecordInstance, DBRecordsArrayInstance } from '../sdk/record.js';
|
|
6
8
|
import { Transaction } from '../sdk/transaction.js';
|
|
7
|
-
import { createApi } from './create-api.js';
|
|
8
9
|
export declare class RestAPI {
|
|
9
|
-
api: ReturnType<typeof createApi>;
|
|
10
10
|
fetcher: ReturnType<typeof createFetcher>;
|
|
11
|
-
|
|
11
|
+
options: SDKConfig['options'];
|
|
12
|
+
logger: SDKConfig['logger'];
|
|
12
13
|
constructor(token?: string, config?: SDKConfig & {
|
|
13
14
|
httpClient: HttpClient;
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
_extractTargetIds(target: RelationTarget, operation: string): Array<string>;
|
|
17
|
+
/**
|
|
18
|
+
* API methods for managing database records
|
|
19
|
+
*/
|
|
20
|
+
records: {
|
|
21
|
+
/**
|
|
22
|
+
* Attaches a relation between records
|
|
23
|
+
* @param source - The source record to create relation from
|
|
24
|
+
* @param target - The target record(s) to create relation to
|
|
25
|
+
* @param options - Optional relation configuration
|
|
26
|
+
* @param options.type - The type of relation to create
|
|
27
|
+
* @param options.direction - The direction of the relation
|
|
28
|
+
* @param transaction - Optional transaction for atomic operations
|
|
29
|
+
* @returns Promise with the API response
|
|
30
|
+
*/
|
|
31
|
+
attach: ({ source, target, options }: {
|
|
32
|
+
source: DBRecordTarget;
|
|
33
|
+
target: RelationTarget;
|
|
34
|
+
options?: RelationOptions;
|
|
35
|
+
}, transaction?: Transaction | string) => Promise<ApiResponse<{
|
|
36
|
+
message: string;
|
|
37
|
+
}>>;
|
|
38
|
+
/**
|
|
39
|
+
* Detaches (removes) a relation between records
|
|
40
|
+
* @param source - The source record to remove relation from
|
|
41
|
+
* @param target - The target record(s) to remove relation to
|
|
42
|
+
* @param options - Optional detach configuration
|
|
43
|
+
* @param options.typeOrTypes - The type(s) of relations to remove
|
|
44
|
+
* @param options.direction - The direction of relations to remove
|
|
45
|
+
* @param transaction - Optional transaction for atomic operations
|
|
46
|
+
* @returns Promise with the API response
|
|
47
|
+
*/
|
|
48
|
+
detach: ({ source, target, options }: {
|
|
49
|
+
source: DBRecordTarget;
|
|
50
|
+
target: RelationTarget;
|
|
51
|
+
options?: RelationDetachOptions;
|
|
52
|
+
}, transaction?: Transaction | string) => Promise<ApiResponse<{
|
|
53
|
+
message: string;
|
|
54
|
+
}>>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new record in the database
|
|
57
|
+
* @param label - The label/type of the record
|
|
58
|
+
* @param data - The record data, either as a flat object or array of property drafts
|
|
59
|
+
* @param options - Optional write configuration
|
|
60
|
+
* @param transaction - Optional transaction for atomic operations
|
|
61
|
+
* @returns Promise resolving to the created DBRecordInstance
|
|
62
|
+
* @throws Error if data is not a flat object and createMany should be used instead
|
|
63
|
+
*/
|
|
64
|
+
create: <S extends Schema = any>({ label, data, options }: {
|
|
65
|
+
label: string;
|
|
66
|
+
data: InferSchemaTypesWrite<S> | Array<PropertyDraft>;
|
|
67
|
+
options?: Omit<DBRecordCreationOptions, "returnResult" | "capitalizeLabels" | "relationshipType">;
|
|
68
|
+
}, transaction?: Transaction | string) => Promise<DBRecordInstance<S>>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates multiple records in a single operation
|
|
71
|
+
* @param data - Object containing label, options and data array or object for multiple records
|
|
72
|
+
* @param data.label - The label/type for all records
|
|
73
|
+
* @param data.options - Optional write configuration
|
|
74
|
+
* @param data.data - Array of record data to create
|
|
75
|
+
* @param transaction - Optional transaction for atomic operations
|
|
76
|
+
* @returns Promise resolving to DBRecordsArrayInstance containing created records
|
|
77
|
+
*/
|
|
78
|
+
createMany: <S extends Schema = any>(data: {
|
|
79
|
+
label: string;
|
|
80
|
+
data: MaybeArray<AnyObject>;
|
|
81
|
+
options?: DBRecordCreationOptions;
|
|
82
|
+
}, transaction?: Transaction | string) => Promise<DBRecordsArrayInstance<S>>;
|
|
83
|
+
/**
|
|
84
|
+
* Deletes records matching the search query
|
|
85
|
+
* @param searchQuery - Query to identify records to delete
|
|
86
|
+
* @param transaction - Optional transaction for atomic operations
|
|
87
|
+
* @returns Promise with the API response
|
|
88
|
+
* @throws EmptyTargetError if query is empty and force delete is not allowed
|
|
89
|
+
*/
|
|
90
|
+
delete: <S extends Schema = any>(searchQuery: SearchQuery<S>, transaction?: Transaction | string) => Promise<ApiResponse<{
|
|
91
|
+
message: string;
|
|
92
|
+
}>>;
|
|
93
|
+
/**
|
|
94
|
+
* Deletes record(s) by ID
|
|
95
|
+
* @param idOrIds - Single ID or array of IDs to delete
|
|
96
|
+
* @param transaction - Optional transaction for atomic operations
|
|
97
|
+
* @returns Promise with the API response
|
|
98
|
+
*/
|
|
99
|
+
deleteById: (idOrIds: MaybeArray<string>, transaction?: Transaction | string) => Promise<ApiResponse<{
|
|
100
|
+
message: string;
|
|
101
|
+
}>>;
|
|
102
|
+
/**
|
|
103
|
+
* Exports records matching the search query to CSV format
|
|
104
|
+
* @param searchQuery - Query to identify records to export
|
|
105
|
+
* @param transaction - Optional transaction for atomic operations
|
|
106
|
+
* @returns Promise with the API response containing CSV data
|
|
107
|
+
*/
|
|
108
|
+
export: <S extends Schema = any>(searchQuery: SearchQuery<S>, transaction?: Transaction | string) => Promise<ApiResponse<{
|
|
109
|
+
dateTime: string;
|
|
110
|
+
fileContent: string;
|
|
111
|
+
}>>;
|
|
112
|
+
/**
|
|
113
|
+
* Searches for records matching the query criteria
|
|
114
|
+
* @param searchQueryWithEntryPoint - Search query with optional entry point ID
|
|
115
|
+
* @param transaction - Optional transaction for atomic operations
|
|
116
|
+
* @returns Promise resolving to DBRecordsArrayInstance containing matched records
|
|
117
|
+
*/
|
|
118
|
+
find: <S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchQueryWithEntryPoint: Q & {
|
|
119
|
+
id?: string;
|
|
120
|
+
}, transaction?: Transaction | string) => Promise<DBRecordsArrayInstance<S, Q>>;
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves record(s) by ID
|
|
123
|
+
* @param idOrIds - Single ID or array of IDs to retrieve
|
|
124
|
+
* @param transaction - Optional transaction for atomic operations
|
|
125
|
+
* @returns Promise resolving to DBRecordInstance or DBRecordsArrayInstance depending on input
|
|
126
|
+
*/
|
|
127
|
+
findById: <S extends Schema = Schema, Arg extends MaybeArray<string> = MaybeArray<string>, Result = Arg extends string[] ? DBRecordsArrayInstance<S, SearchQuery<S>> : DBRecordInstance<S, SearchQuery<S>>>(idOrIds: Arg, transaction?: Transaction | string) => Promise<Result>;
|
|
128
|
+
/**
|
|
129
|
+
* Finds a single record matching the search query
|
|
130
|
+
* @param searchQuery - Query to identify the record
|
|
131
|
+
* @param transaction - Optional transaction for atomic operations
|
|
132
|
+
* @returns Promise resolving to DBRecordInstance
|
|
133
|
+
*/
|
|
134
|
+
findOne: <S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchQuery: Q, transaction?: Transaction | string) => Promise<DBRecordInstance<S>>;
|
|
135
|
+
/**
|
|
136
|
+
* Finds a unique record matching the search query
|
|
137
|
+
* @param searchQuery - Query to identify the record
|
|
138
|
+
* @param transaction - Optional transaction for atomic operations
|
|
139
|
+
* @returns Promise resolving to DBRecordInstance
|
|
140
|
+
* @throws NonUniqueResultError if multiple records match the query
|
|
141
|
+
*/
|
|
142
|
+
findUniq: <S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchQuery: Q, transaction?: Transaction | string) => Promise<DBRecordInstance<S, Q>>;
|
|
143
|
+
/**
|
|
144
|
+
* Sets (overwrites) record data
|
|
145
|
+
* @param target - The record to update
|
|
146
|
+
* @param label - The label/type of the record
|
|
147
|
+
* @param data - The new record data
|
|
148
|
+
* @param options - Optional write configuration
|
|
149
|
+
* @param transaction - Optional transaction for atomic operations
|
|
150
|
+
* @returns Promise resolving to updated DBRecordInstance
|
|
151
|
+
* @throws Error if data is not a flat object
|
|
152
|
+
*/
|
|
153
|
+
set: <S extends Schema = any>({ target, label, data, options }: {
|
|
154
|
+
target: DBRecordTarget;
|
|
155
|
+
label: string;
|
|
156
|
+
data: InferSchemaTypesWrite<S> | Array<PropertyDraft>;
|
|
157
|
+
options?: Omit<DBRecordCreationOptions, "returnResult" | "capitalizeLabels" | "relationshipType">;
|
|
158
|
+
}, transaction?: Transaction | string) => Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
159
|
+
/**
|
|
160
|
+
* Updates record data (partial update)
|
|
161
|
+
* @param target - The record to update
|
|
162
|
+
* @param label - The label/type of the record
|
|
163
|
+
* @param data - The partial record data to update
|
|
164
|
+
* @param options - Optional write configuration
|
|
165
|
+
* @param transaction - Optional transaction for atomic operations
|
|
166
|
+
* @returns Promise resolving to updated DBRecordInstance
|
|
167
|
+
* @throws Error if data is not a flat object
|
|
168
|
+
*/
|
|
169
|
+
update: <S extends Schema = any>({ target, label, data, options }: {
|
|
170
|
+
target: DBRecordTarget;
|
|
171
|
+
label: string;
|
|
172
|
+
data: Partial<InferSchemaTypesWrite<S>> | Array<PropertyDraft>;
|
|
173
|
+
options?: Omit<DBRecordCreationOptions, "returnResult" | "capitalizeLabels" | "relationshipType">;
|
|
174
|
+
}, transaction?: Transaction | string) => Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* API methods for managing relations between records
|
|
178
|
+
*/
|
|
179
|
+
relationships: {
|
|
180
|
+
/**
|
|
181
|
+
* Searches for relations matching the query criteria
|
|
182
|
+
* @param searchQuery - Query to identify relations
|
|
183
|
+
* @param transaction - Optional transaction for atomic operations
|
|
184
|
+
* @returns Promise with the API response containing matched relations
|
|
185
|
+
*/
|
|
186
|
+
find: <S extends Schema = any>(searchQuery: SearchQuery<S>, transaction?: Transaction | string) => Promise<ApiResponse<Relation[]>>;
|
|
21
187
|
};
|
|
188
|
+
/**
|
|
189
|
+
* API methods for managing properties in the database
|
|
190
|
+
*/
|
|
22
191
|
properties: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Deletes a property by its ID
|
|
194
|
+
* @param id - The unique identifier of the property to delete
|
|
195
|
+
* @param transaction - Optional transaction for atomic operations
|
|
196
|
+
* @returns Promise with the API response containing the deleted property
|
|
197
|
+
*/
|
|
198
|
+
delete: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property>>;
|
|
199
|
+
/**
|
|
200
|
+
* Searches for properties based on the provided query
|
|
201
|
+
* @param searchQuery - Query parameters to filter properties
|
|
202
|
+
* @param transaction - Optional transaction for atomic operations
|
|
203
|
+
* @returns Promise with the API response containing an array of matching properties
|
|
204
|
+
*/
|
|
205
|
+
find: <S extends Schema = any>(searchQuery: SearchQuery<S>, transaction?: Transaction | string) => Promise<ApiResponse<Property[]>>;
|
|
206
|
+
/**
|
|
207
|
+
* Retrieves a specific property by its ID
|
|
208
|
+
* @param id - The unique identifier of the property to retrieve
|
|
209
|
+
* @param transaction - Optional transaction for atomic operations
|
|
210
|
+
* @returns Promise with the API response containing the requested property
|
|
211
|
+
*/
|
|
212
|
+
findById: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property>>;
|
|
213
|
+
/**
|
|
214
|
+
* Retrieves values for a specific property
|
|
215
|
+
* @param id - The unique identifier of the property
|
|
216
|
+
* @param options - Optional parameters for pagination, sorting, and filtering
|
|
217
|
+
* @param options.sort - Sort direction for values ('asc' or 'desc')
|
|
218
|
+
* @param options.skip - Number of values to skip
|
|
219
|
+
* @param options.limit - Maximum number of values to return
|
|
220
|
+
* @param options.query - Filter query for values
|
|
221
|
+
* @param transaction - Optional transaction for atomic operations
|
|
222
|
+
* @returns Promise with the API response containing the property and its values
|
|
223
|
+
*/
|
|
224
|
+
values: (id: string, options?: PropertyValuesOptions, transaction?: Transaction | string) => Promise<ApiResponse<{
|
|
225
|
+
metadata?: string;
|
|
226
|
+
name: string;
|
|
227
|
+
type: import("../types/value.js").PropertyType;
|
|
228
|
+
} & {
|
|
229
|
+
id: string;
|
|
230
|
+
} & PropertyValuesData>>;
|
|
27
231
|
};
|
|
232
|
+
/**
|
|
233
|
+
* API methods for managing labels in the database
|
|
234
|
+
*/
|
|
28
235
|
labels: {
|
|
29
|
-
|
|
236
|
+
/**
|
|
237
|
+
* Searches for labels based on the provided query
|
|
238
|
+
* @param searchQuery - Query parameters to filter labels
|
|
239
|
+
* @param transaction - Optional transaction for atomic operations
|
|
240
|
+
* @returns Promise with the API response containing a record of label names and their counts
|
|
241
|
+
*/
|
|
242
|
+
find: <S extends Schema = any>(searchQuery: SearchQuery<S>, transaction?: Transaction | string) => Promise<ApiResponse<Record<string, number>>>;
|
|
30
243
|
};
|
|
244
|
+
/**
|
|
245
|
+
* API methods for managing database transactions
|
|
246
|
+
*/
|
|
31
247
|
tx: {
|
|
248
|
+
/**
|
|
249
|
+
* Begins a new database transaction
|
|
250
|
+
* @param config - Optional configuration object for the transaction
|
|
251
|
+
* @param config.ttl - Time-to-live in milliseconds for the transaction
|
|
252
|
+
* @returns A new Transaction instance that can be used for subsequent operations
|
|
253
|
+
* @throws If the transaction cannot be started
|
|
254
|
+
*/
|
|
32
255
|
begin: (config?: Partial<{
|
|
33
256
|
ttl: number;
|
|
34
257
|
}>) => Promise<Transaction>;
|
|
35
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Commits a transaction, making its changes permanent
|
|
260
|
+
* @param tx - The ID of the transaction or Transaction instance to commit
|
|
261
|
+
* @returns An ApiResponse indicating success or failure of the commit
|
|
262
|
+
* @throws If the transaction cannot be committed or doesn't exist
|
|
263
|
+
*/
|
|
264
|
+
commit: (tx: string | Transaction) => Promise<ApiResponse<{
|
|
36
265
|
message: string;
|
|
37
266
|
}>>;
|
|
38
|
-
|
|
39
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Retrieves an existing transaction by its ID
|
|
269
|
+
* @param tx - The ID of the transaction or Transaction instance to retrieve
|
|
270
|
+
* @returns A Transaction instance representing the retrieved transaction
|
|
271
|
+
* @throws If the transaction doesn't exist or cannot be retrieved
|
|
272
|
+
*/
|
|
273
|
+
get: (tx: string | Transaction) => Promise<Transaction>;
|
|
274
|
+
/**
|
|
275
|
+
* Rolls back a transaction, undoing all changes made within it
|
|
276
|
+
* @param tx - The ID of the transaction or Transaction instance to roll back
|
|
277
|
+
* @returns An ApiResponse indicating success or failure of the rollback
|
|
278
|
+
* @throws If the transaction cannot be rolled back or doesn't exist
|
|
279
|
+
*/
|
|
280
|
+
rollback: (tx: string | Transaction) => Promise<ApiResponse<{
|
|
40
281
|
message: string;
|
|
41
282
|
}>>;
|
|
42
283
|
};
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/types.d.ts
CHANGED
|
@@ -1,65 +1,5 @@
|
|
|
1
|
-
import type { DBRecordDraft, DBRecordInstance, DBRecordsArrayInstance, DBRecordsBatchDraft, DBRecordTarget, Relation, RelationDetachOptions, RelationOptions, RelationTarget } from '../sdk/record.js';
|
|
2
|
-
import type { Transaction } from '../sdk/transaction.js';
|
|
3
|
-
import type { InferSchemaTypesWrite, MaybeArray, Property, Schema, SearchQuery } from '../types/index.js';
|
|
4
1
|
export type ApiResponse<T, E = Record<string, any>> = {
|
|
5
2
|
data: T;
|
|
6
3
|
success: boolean;
|
|
7
4
|
total?: number;
|
|
8
5
|
} & E;
|
|
9
|
-
export type RecordsApi = {
|
|
10
|
-
attach(source: DBRecordTarget, target: RelationTarget, options?: RelationOptions, transaction?: Transaction | string): Promise<ApiResponse<{
|
|
11
|
-
message: string;
|
|
12
|
-
}>>;
|
|
13
|
-
create<S extends Schema = any>(label: string, data: InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
|
|
14
|
-
create<S extends Schema = any>(labelOrData: DBRecordDraft | string, maybeDataOrTransaction?: Transaction | InferSchemaTypesWrite<S> | string, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
|
|
15
|
-
createMany<S extends Schema = any>(label: string, data: InferSchemaTypesWrite<S>[], transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
|
|
16
|
-
createMany<S extends Schema = any>(labelOrData: DBRecordsBatchDraft | string, maybeDataOrTransaction?: Transaction | MaybeArray<InferSchemaTypesWrite<S>> | string, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
|
|
17
|
-
delete<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<{
|
|
18
|
-
message: string;
|
|
19
|
-
}>>;
|
|
20
|
-
deleteById(idOrIds: MaybeArray<string>, transaction?: Transaction | string): Promise<ApiResponse<{
|
|
21
|
-
message: string;
|
|
22
|
-
}>>;
|
|
23
|
-
detach(source: DBRecordTarget, target: RelationTarget, options?: RelationDetachOptions, transaction?: Transaction | string): Promise<ApiResponse<{
|
|
24
|
-
message: string;
|
|
25
|
-
}>>;
|
|
26
|
-
export<S extends Schema = any>(searchParams?: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<{
|
|
27
|
-
dateTime: string;
|
|
28
|
-
fileContent: string;
|
|
29
|
-
}>>;
|
|
30
|
-
find<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(label: string, searchParams?: Q, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S, Q>>;
|
|
31
|
-
find<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(labelOrSearchParams: Q | string, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S, Q>>;
|
|
32
|
-
find<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchParams: Q, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S, Q>>;
|
|
33
|
-
findById<S extends Schema = any>(id: string, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
|
|
34
|
-
findById<S extends Schema = any>(ids: string[], transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
|
|
35
|
-
findOne<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(label: string, searchParams: Q & {
|
|
36
|
-
labels?: never;
|
|
37
|
-
limit?: never;
|
|
38
|
-
skip?: never;
|
|
39
|
-
}, transaction?: Transaction | string): Promise<DBRecordInstance<S, Q>>;
|
|
40
|
-
findOne<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(labelOrSearchParams: (Q & {
|
|
41
|
-
limit?: never;
|
|
42
|
-
skip?: never;
|
|
43
|
-
}) | string, transaction?: Transaction | string): Promise<DBRecordInstance<S, Q>>;
|
|
44
|
-
findOne<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchParams: Q & {
|
|
45
|
-
limit?: never;
|
|
46
|
-
skip?: never;
|
|
47
|
-
}, transaction?: Transaction | string): Promise<DBRecordInstance<S, Q>>;
|
|
48
|
-
findUniq<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(label: string, searchParams: Q & {
|
|
49
|
-
labels?: never;
|
|
50
|
-
limit?: never;
|
|
51
|
-
skip?: never;
|
|
52
|
-
}, transaction?: Transaction | string): Promise<DBRecordInstance<S, Q>>;
|
|
53
|
-
findUniq<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(labelOrSearchParams: (Q & {
|
|
54
|
-
limit?: never;
|
|
55
|
-
skip?: never;
|
|
56
|
-
}) | string, transaction?: Transaction | string): Promise<DBRecordInstance<S, Q>>;
|
|
57
|
-
findUniq<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchParams: Q & {
|
|
58
|
-
limit?: never;
|
|
59
|
-
skip?: never;
|
|
60
|
-
}, transaction?: Transaction | string): Promise<DBRecordInstance<S, Q>>;
|
|
61
|
-
properties(target: DBRecordTarget, transaction?: Transaction | string): Promise<ApiResponse<Property[]>>;
|
|
62
|
-
relations(target: DBRecordTarget, transaction?: Transaction | string): Promise<ApiResponse<Array<Relation>>>;
|
|
63
|
-
set<S extends Schema = any>(target: DBRecordTarget, data: DBRecordDraft | InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
|
|
64
|
-
update<S extends Schema = any>(target: DBRecordTarget, data: DBRecordDraft | Partial<InferSchemaTypesWrite<S>>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
|
|
65
|
-
};
|
package/dist/api/utils.d.ts
CHANGED
|
@@ -1,44 +1,14 @@
|
|
|
1
1
|
import type { DBRecordTarget } from '../sdk';
|
|
2
2
|
import type { SDKConfig } from '../sdk/types.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { PropertyDraft } from '../types/index.js';
|
|
4
4
|
import { Transaction } from '../sdk/transaction.js';
|
|
5
5
|
export declare const buildTransactionHeader: (txId?: string) => {
|
|
6
6
|
"x-transaction-id": string;
|
|
7
7
|
} | undefined;
|
|
8
8
|
export declare const isTransaction: (input: any) => input is Transaction | string;
|
|
9
|
-
export declare const pickTransaction: (input: any) => string | Transaction | undefined;
|
|
10
9
|
export declare const pickTransactionId: (input: any) => string | undefined;
|
|
11
|
-
export declare const pickRecordId: (input: DBRecordTarget) => string | undefined;
|
|
12
|
-
export declare const createSearchParams: <S extends Schema = Schema>(labelOrSearchParams?: SearchQuery<S> | string, searchParamsOrTransaction?: SearchQuery<S> | Transaction | string) => {
|
|
13
|
-
id?: string;
|
|
14
|
-
searchParams: SearchQuery<S>;
|
|
15
|
-
};
|
|
16
10
|
export declare const isUUID: (value: any) => boolean;
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
19
|
-
isEmptyArray: boolean;
|
|
20
|
-
isEmptyStringsArray: boolean;
|
|
21
|
-
isInconsistentArray: boolean;
|
|
22
|
-
isEmptyString?: undefined;
|
|
23
|
-
} | {
|
|
24
|
-
isEmptyString: boolean;
|
|
25
|
-
isEmptyArray?: undefined;
|
|
26
|
-
isEmptyStringsArray?: undefined;
|
|
27
|
-
isInconsistentArray?: undefined;
|
|
28
|
-
};
|
|
29
|
-
export declare const suggestPropertyType: (value: PropertyValue) => PropertyType;
|
|
30
|
-
export declare const prepareProperties: (data: Record<string, PropertyValue>, options?: {
|
|
31
|
-
suggestTypes: boolean;
|
|
32
|
-
}) => PropertyWithValue[];
|
|
33
|
-
export declare const normalizeRecord: ({ label, options, payload }: {
|
|
34
|
-
label: string;
|
|
35
|
-
options?: {
|
|
36
|
-
suggestTypes: boolean;
|
|
37
|
-
};
|
|
38
|
-
payload: Record<string, PropertyValue>;
|
|
39
|
-
}) => {
|
|
40
|
-
label: string;
|
|
41
|
-
properties: PropertyWithValue[];
|
|
42
|
-
};
|
|
11
|
+
export declare const pickRecordId: (input: DBRecordTarget) => string | undefined;
|
|
12
|
+
export declare const isPropertyDraft: (obj: any) => obj is PropertyDraft;
|
|
43
13
|
export declare const buildUrl: (props: SDKConfig) => string;
|
|
44
14
|
export declare const generateRandomId: (size?: number) => string;
|
|
@@ -5,3 +5,5 @@ export declare const PROPERTY_TYPE_DATETIME: "datetime";
|
|
|
5
5
|
export declare const PROPERTY_TYPE_BOOLEAN: "boolean";
|
|
6
6
|
export declare const PROPERTY_TYPE_NUMBER: "number";
|
|
7
7
|
export declare const PROPERTY_TYPE_NULL: "null";
|
|
8
|
+
export declare const PROPERTY_TYPE_VECTOR: "vector";
|
|
9
|
+
export declare const PROPERTY_TYPES: ("string" | "number" | "boolean" | "datetime" | "null" | "vector")[];
|
package/dist/common/utils.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { PropertyValue } from '../types/index.js';
|
|
2
|
-
export declare const isArray: (item: any) => item is any
|
|
2
|
+
export declare const isArray: (item: any) => item is Array<any>;
|
|
3
3
|
export declare const isObject: (input: unknown) => input is object;
|
|
4
4
|
export declare const isEmptyObject: (input: unknown) => boolean;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const isPrimitive: (value: unknown) => value is string | number | boolean | null;
|
|
6
|
+
export declare const isPropertyValue: (value: any) => value is PropertyValue;
|
|
7
|
+
export declare const isFlatObject: (input: any) => input is Record<string, PropertyValue>;
|
|
6
8
|
export declare const isString: (input: any) => input is string;
|
|
7
9
|
export declare const toBoolean: (value: any) => boolean;
|