@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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @rushdb/javascript-sdk
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f934b0f: Bump version
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - cb1e4be: Update readme, cleanups, build public image
14
+
3
15
  ## 0.1.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -2,15 +2,13 @@
2
2
 
3
3
  ![RushDB Logo](https://raw.githubusercontent.com/rush-db/rushdb/main/rushdb-logo.svg)
4
4
 
5
- # RushDB SDK
5
+ # RushDB SDK for JavaScript and TypeScript
6
6
 
7
- > The RushDB.com SDK for JavaScript and TypeScript
8
-
9
- [![NPM Version](https://img.shields.io/npm/v/%40collect.so%2Fjavascript-sdk)](https://www.npmjs.com/package/@rushdb/javascript-sdk)
7
+ [![NPM Version](https://img.shields.io/npm/v/%40rushdb%2Fjavascript-sdk)](https://www.npmjs.com/package/@rushdb/javascript-sdk)
10
8
  [![License](https://img.shields.io/badge/License-MIT-blue)](#license "Go to license section")
11
9
 
12
- ![NPM Downloads](https://img.shields.io/npm/dw/%40collect.so%2Fjavascript-sdk)
13
- ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40collect.so%2Fjavascript-sdk)
10
+ ![NPM Downloads](https://img.shields.io/npm/dw/%40rushdb%2Fjavascript-sdk)
11
+ ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40rushdb%2Fjavascript-sdk)
14
12
 
15
13
 
16
14
  [![Made with Node](https://img.shields.io/badge/dynamic/json?label=node&query=%24.engines%5B%22node%22%5D&url=https%3A%2F%2Fraw.githubusercontent.com%2Fcollect-so%2Fcollect%2Fmaster%2Fpackage.json)](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
- ## Features
20
+ ## Highlights
23
21
 
24
22
  ---
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 and efficient with no external dependencies.
28
- - **No Configuration Needed**: Plug-and-play design requires no setup or configuration.
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 RushDB API Token**: Grab your API token from the [Dashboard](https://app.rushdb.com).
55
- 2. **Setup RushDB Instance**: Initialize your RushDB instance with obtained token.
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 RushDB instance
66
- const db = new RushDB("API_TOKEN")
67
-
68
- // Optionaly define Model
69
- export const UserRepo = new Model(
70
- 'USER',
71
- {
72
- name: { type: 'string' },
73
- email: { type: 'string', uniq: true },
74
- verified: { type: 'boolean', default: false },
75
- hobbies: { type: 'string', multiple: true, requiered: false },
76
- rating: { type: 'number', default: 1 },
77
- created: { type: 'datetime', default: () => new Date().toISOString() },
78
- password: { type: 'string' }
79
- },
80
- db
81
- )
82
-
83
- // Create new Record
84
- const newUser = await UserRepo.create({
85
- name: "John Galt",
86
- email: 'john.g@example.com',
87
- hobbies: ['Programming', 'Hiking'],
88
- password: '********'
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 matchedUsers = await UserRepo.find({
93
- where: {
94
- email: { $ne: 'john.g@example.com' },
95
- hobbies: { $in: ['Hiking'] },
96
- rating: { $gte: 1.5 }
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 || protocol === 'http' ? '80'
135
- : protocol === 'https' ? '443'
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 || protocol === 'http' ? '80'
120
- : protocol === 'https' ? '443'
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.0",
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 {