@rushdb/javascript-sdk 0.1.0 → 0.2.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.
- package/CHANGELOG.md +12 -0
- package/README.md +68 -46
- package/cjs/api/utils.js +5 -4
- package/esm/api/utils.js +5 -4
- package/package.json +1 -2
- package/types/index.d.ts +3 -15
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
# RushDB SDK
|
|
5
|
+
# RushDB SDK for JavaScript and TypeScript
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[](https://www.npmjs.com/package/@rushdb/javascript-sdk)
|
|
7
|
+
[](https://www.npmjs.com/package/@rushdb/javascript-sdk)
|
|
10
8
|
[](#license "Go to license section")
|
|
11
9
|
|
|
12
|
-

|
|
11
|
+

|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
[](https://nodejs.org "Go to Node.js homepage")
|
|
@@ -19,13 +17,17 @@
|
|
|
19
17
|
[Homepage](https://rushdb.com) — [Blog](https://rushdb.com/blog) — [Platform](https://app.rushdb.com) — [Docs](https://docs.rushdb.com) — [Examples](https://github.com/rush-db/rushdb/examples)
|
|
20
18
|
</div>
|
|
21
19
|
|
|
22
|
-
##
|
|
20
|
+
## Highlights
|
|
23
21
|
|
|
24
22
|
---
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
+
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
## Installation
|
|
@@ -51,51 +53,71 @@ pnmp add @rushdb/javascript-sdk
|
|
|
51
53
|
|
|
52
54
|
---
|
|
53
55
|
|
|
54
|
-
1. **Obtain
|
|
55
|
-
2. **
|
|
56
|
-
3. **(Optional) Define Data Models**: Tailor your data models to fit your needs.
|
|
57
|
-
4. **Manage Your Data**: Push, link, fetch, and manage your data effortlessly.
|
|
56
|
+
1. **Obtain API Token**: Grab one from the [Dashboard](https://app.rushdb.com).
|
|
57
|
+
2. **Build anything**: Easily push, search, and manage relationships within your data.
|
|
58
58
|
|
|
59
59
|
### TLDR;
|
|
60
60
|
```ts
|
|
61
|
-
/* ./your-app/src/db.ts */
|
|
62
|
-
|
|
63
61
|
import RushDB, { Model } from '@rushdb/javascript-sdk'
|
|
64
62
|
|
|
65
|
-
// Setup
|
|
66
|
-
const db = new RushDB("API_TOKEN"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
63
|
+
// Setup SDK
|
|
64
|
+
const db = new RushDB("API_TOKEN", {
|
|
65
|
+
// This is the default URL; no need to provide it unless overriding.
|
|
66
|
+
url: "https://api.rushdb.com",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Push any data, and RushDB will automatically flatten it into Records
|
|
70
|
+
// and establish relationships between them accordingly.
|
|
71
|
+
await db.records.createMany("COMPANY", {
|
|
72
|
+
name: 'Google LLC',
|
|
73
|
+
address: '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA',
|
|
74
|
+
foundedAt: '1998-09-04T00:00:00.000Z',
|
|
75
|
+
rating: 4.9,
|
|
76
|
+
DEPARTMENT: [{
|
|
77
|
+
name: 'Research & Development',
|
|
78
|
+
description:
|
|
79
|
+
'Innovating and creating advanced technologies for AI, cloud computing, and consumer devices.',
|
|
80
|
+
PROJECT: [{
|
|
81
|
+
name: 'Bard AI',
|
|
82
|
+
description:
|
|
83
|
+
'A state-of-the-art generative AI model designed for natural language understanding and creation.',
|
|
84
|
+
active: true,
|
|
85
|
+
budget: 1200000000,
|
|
86
|
+
EMPLOYEE: [{
|
|
87
|
+
name: 'Jeff Dean',
|
|
88
|
+
position: 'Head of AI Research',
|
|
89
|
+
email: 'jeff@google.com',
|
|
90
|
+
dob: '1968-07-16T00:00:00.000Z',
|
|
91
|
+
salary: 3000000
|
|
92
|
+
}]
|
|
93
|
+
}]
|
|
94
|
+
}]
|
|
89
95
|
})
|
|
90
96
|
|
|
97
|
+
|
|
91
98
|
// Find Records by specific criteria
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
const matchedEmployees = await db.records.find({
|
|
100
|
+
labels: ['EMPLOYEE'],
|
|
101
|
+
where: {
|
|
102
|
+
position: { $contains: 'AI' },
|
|
103
|
+
PROJECT: {
|
|
104
|
+
DEPARTMENT: {
|
|
105
|
+
COMPANY: {
|
|
106
|
+
rating: { $gte: 4 }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
97
109
|
}
|
|
110
|
+
}
|
|
98
111
|
})
|
|
112
|
+
|
|
113
|
+
const company = await db.records.findUniq('COMPANY', {
|
|
114
|
+
where: {
|
|
115
|
+
name: 'Google LLC'
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Manage relationships
|
|
120
|
+
await company.attach(matchedEmployees, { type: "WORKING_AT" })
|
|
99
121
|
```
|
|
100
122
|
|
|
101
123
|
<div align="center">
|
package/cjs/api/utils.js
CHANGED
|
@@ -128,12 +128,13 @@ const buildUrl = (props) => {
|
|
|
128
128
|
let port = constants_js_2.DEFAULT_PORT;
|
|
129
129
|
let basePath = constants_js_2.DEFAULT_BASE_PATH;
|
|
130
130
|
if ('url' in props) {
|
|
131
|
-
const url = new URL(props.url);
|
|
131
|
+
const url = new URL(props.url || (document === null || document === void 0 ? void 0 : document.URL));
|
|
132
132
|
protocol = url.protocol.replace(':', '');
|
|
133
133
|
host = url.hostname;
|
|
134
|
-
port = parseInt(url.port ||
|
|
135
|
-
|
|
136
|
-
: ''
|
|
134
|
+
port = parseInt(url.port ||
|
|
135
|
+
(protocol === 'http' ? '80'
|
|
136
|
+
: protocol === 'https' ? '443'
|
|
137
|
+
: ''));
|
|
137
138
|
}
|
|
138
139
|
if ('host' in props && 'port' in props && 'protocol' in props) {
|
|
139
140
|
protocol = props.protocol.replace(':', '');
|
package/esm/api/utils.js
CHANGED
|
@@ -113,12 +113,13 @@ export const buildUrl = (props) => {
|
|
|
113
113
|
let port = DEFAULT_PORT;
|
|
114
114
|
let basePath = DEFAULT_BASE_PATH;
|
|
115
115
|
if ('url' in props) {
|
|
116
|
-
const url = new URL(props.url);
|
|
116
|
+
const url = new URL(props.url || (document === null || document === void 0 ? void 0 : document.URL));
|
|
117
117
|
protocol = url.protocol.replace(':', '');
|
|
118
118
|
host = url.hostname;
|
|
119
|
-
port = parseInt(url.port ||
|
|
120
|
-
|
|
121
|
-
: ''
|
|
119
|
+
port = parseInt(url.port ||
|
|
120
|
+
(protocol === 'http' ? '80'
|
|
121
|
+
: protocol === 'https' ? '443'
|
|
122
|
+
: ''));
|
|
122
123
|
}
|
|
123
124
|
if ('host' in props && 'port' in props && 'protocol' in props) {
|
|
124
125
|
protocol = props.protocol.replace(':', '');
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@rushdb/javascript-sdk",
|
|
3
3
|
"description": "RushDB Javascript SDK",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.1
|
|
5
|
+
"version": "0.2.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "cjs/index.cjs.node.js",
|
|
8
8
|
"types": "types/index.d.ts",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"build-esm": "mkdir -p esm && tsc -p tsconfig.esm.json",
|
|
50
50
|
"build-cjs": "mkdir -p cjs && tsc -p tsconfig.cjs.json",
|
|
51
51
|
"postbuild": "node scripts/post-build.js",
|
|
52
|
-
"dev": "tsup --watch",
|
|
53
52
|
"types:check": "tsc --noEmit",
|
|
54
53
|
"clean": "rm -rf ./dist ./node_modules/.cache ./coverage ./esm ./cjs ./types",
|
|
55
54
|
"flush": "rm -rf node_modules",
|
package/types/index.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
InferType,
|
|
3
|
-
DBRecord,
|
|
4
|
-
UserProvidedConfig,
|
|
5
|
-
Relation
|
|
6
|
-
} from './sdk'
|
|
1
|
+
import type { InferType, DBRecord, UserProvidedConfig, Relation } from './sdk'
|
|
7
2
|
|
|
8
|
-
import {
|
|
9
|
-
DBRecordsBatchDraft,
|
|
10
|
-
DBRecordDraft,
|
|
11
|
-
RestAPI,
|
|
12
|
-
ApiResponse
|
|
13
|
-
} from './api'
|
|
3
|
+
import { DBRecordsBatchDraft, DBRecordDraft, RestAPI, ApiResponse } from './api'
|
|
14
4
|
import { HttpClient, HttpClientResponse } from './network/HttpClient'
|
|
15
5
|
import {
|
|
16
6
|
Model,
|
|
@@ -38,9 +28,7 @@ declare module '@rushdb/javascript-sdk' {
|
|
|
38
28
|
public getModel(label: string): Model
|
|
39
29
|
public getModels(): Map<string, Model>
|
|
40
30
|
public getInstance(token: string, config?: UserProvidedConfig): RushDB
|
|
41
|
-
public toInstance<Schema extends Schema = Schema>(
|
|
42
|
-
record: DBRecord<Schema>
|
|
43
|
-
): DBRecordInstance
|
|
31
|
+
public toInstance<Schema extends Schema = Schema>(record: DBRecord<Schema>): DBRecordInstance
|
|
44
32
|
}
|
|
45
33
|
|
|
46
34
|
export {
|