Comparing version 0.0.4-beta to 0.0.5-beta
@@ -11,21 +11,32 @@ import { EventEmitter } from 'events'; | ||
private connected; | ||
private authenticated; | ||
private sessionToken; | ||
private requestQueue; | ||
private requestTimeout; | ||
private connectionPromise; | ||
connect(url: string): Promise<void>; | ||
private credentials; | ||
connect(url: string, credentials: { | ||
username: string; | ||
password: string; | ||
}): Promise<void>; | ||
private authenticate; | ||
private setupHeartbeat; | ||
sendRequest(type: string, data: any): Promise<any>; | ||
private sendRequestUnencrypted; | ||
sendRequest<T>(type: string, data: any): Promise<T>; | ||
model(collectionName: string, schema?: Schema): { | ||
find(query?: Record<string, any>): Promise<any>; | ||
findOne(query?: Record<string, any>): Promise<any>; | ||
insertOne(document: Record<string, any>): Promise<any>; | ||
insertMany(documents: Record<string, any>[]): Promise<any>; | ||
updateOne(query: Record<string, any>, updateFields: Record<string, any>): Promise<any>; | ||
updateMany(query: Record<string, any>, updateFields: Record<string, any>): Promise<any>; | ||
deleteOne(query: Record<string, any>): Promise<any>; | ||
deleteMany(query: Record<string, any>): Promise<any>; | ||
find(query?: Record<string, any>): Promise<unknown>; | ||
findOne(query?: Record<string, any>): Promise<unknown>; | ||
insertOne(document: Record<string, any>): Promise<unknown>; | ||
insertMany(documents: Record<string, any>[]): Promise<unknown>; | ||
updateOne(query: Record<string, any>, updateFields: Record<string, any>): Promise<unknown>; | ||
updateMany(query: Record<string, any>, updateFields: Record<string, any>): Promise<unknown>; | ||
deleteOne(query: Record<string, any>): Promise<unknown>; | ||
deleteMany(query: Record<string, any>): Promise<unknown>; | ||
}; | ||
} | ||
export interface Pyx { | ||
connect: (url: string) => Promise<void>; | ||
connect: (url: string, credentials: { | ||
username: string; | ||
password: string; | ||
}) => Promise<void>; | ||
Schema: new (definition: Record<string, any>, collectionName: string) => Schema; | ||
@@ -32,0 +43,0 @@ model: (collectionName: string, schema?: Schema) => ReturnType<PyxisDB['model']>; |
@@ -9,2 +9,4 @@ "use strict"; | ||
const events_1 = require("events"); | ||
const ENCRYPTION_ALGORITHM = 'aes-256-cbc'; | ||
// Schema class remains unchanged | ||
class Schema { | ||
@@ -41,7 +43,11 @@ constructor(definition, collectionName) { | ||
this.connected = false; | ||
this.authenticated = false; | ||
this.sessionToken = null; | ||
this.requestQueue = new Map(); | ||
this.requestTimeout = 30000; // 30 seconds | ||
this.connectionPromise = null; | ||
this.credentials = null; | ||
} | ||
async connect(url) { | ||
async connect(url, credentials) { | ||
this.credentials = credentials; | ||
if (this.connectionPromise) { | ||
@@ -53,7 +59,13 @@ return this.connectionPromise; | ||
this.ws = new ws_1.default(wsUrl, 'pyxisdb-protocol'); | ||
this.ws.on('open', () => { | ||
this.ws.on('open', async () => { | ||
this.connected = true; | ||
this.setupHeartbeat(); | ||
this.emit('connected'); | ||
resolve(); | ||
try { | ||
await this.authenticate(); | ||
this.emit('connected'); | ||
resolve(); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
@@ -65,3 +77,4 @@ this.ws.on('message', (data) => { | ||
if (this.requestQueue.has(requestId)) { | ||
const { resolve, reject } = this.requestQueue.get(requestId); | ||
const { resolve, reject, timeout } = this.requestQueue.get(requestId); | ||
clearTimeout(timeout); | ||
this.requestQueue.delete(requestId); | ||
@@ -78,2 +91,3 @@ if (status === 'success') { | ||
console.error('Error processing message:', error); | ||
this.emit('error', error); | ||
} | ||
@@ -83,2 +97,4 @@ }); | ||
this.connected = false; | ||
this.authenticated = false; | ||
this.sessionToken = null; | ||
this.connectionPromise = null; | ||
@@ -88,3 +104,6 @@ this.emit('disconnected'); | ||
this.ws.on('error', (error) => { | ||
console.error('WebSocket error:', error); | ||
this.connected = false; | ||
this.authenticated = false; | ||
this.sessionToken = null; | ||
this.connectionPromise = null; | ||
@@ -96,2 +115,20 @@ reject(error); | ||
} | ||
async authenticate() { | ||
if (!this.credentials) { | ||
throw new Error('Credentials not provided'); | ||
} | ||
try { | ||
const response = await this.sendRequestUnencrypted('Authenticate', this.credentials); | ||
if (typeof response.sessionToken !== 'string' || response.sessionToken.length === 0) { | ||
throw new Error('Server did not provide a valid session token'); | ||
} | ||
this.sessionToken = response.sessionToken; | ||
this.authenticated = true; | ||
} | ||
catch (error) { | ||
this.authenticated = false; | ||
this.sessionToken = null; | ||
throw error; | ||
} | ||
} | ||
setupHeartbeat() { | ||
@@ -104,3 +141,3 @@ if (this.ws) { | ||
} | ||
async sendRequest(type, data) { | ||
async sendRequestUnencrypted(type, data) { | ||
if (!this.connected) { | ||
@@ -126,2 +163,28 @@ throw new Error('Not connected to server'); | ||
} | ||
async sendRequest(type, data) { | ||
if (!this.connected) { | ||
throw new Error('Not connected to server'); | ||
} | ||
if (!this.authenticated) { | ||
throw new Error('Not authenticated'); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const requestId = Math.random().toString(36).substring(7); | ||
const request = { | ||
type, | ||
data, | ||
requestId, | ||
sessionToken: this.sessionToken | ||
}; | ||
const timeout = setTimeout(() => { | ||
if (this.requestQueue.has(requestId)) { | ||
this.requestQueue.delete(requestId); | ||
reject(new Error('Request timeout')); | ||
} | ||
}, this.requestTimeout); | ||
this.requestQueue.set(requestId, { resolve, reject, timeout }); | ||
this.ws?.send(JSON.stringify(request)); | ||
}); | ||
} | ||
// model method remains unchanged | ||
model(collectionName, schema) { | ||
@@ -196,3 +259,3 @@ const self = this; | ||
exports.pyx = { | ||
connect: (url) => pyxisdb.connect(url), | ||
connect: (url, credentials) => pyxisdb.connect(url, credentials), | ||
Schema: Schema, | ||
@@ -199,0 +262,0 @@ model: (collectionName, schema) => pyxisdb.model(collectionName, schema) |
{ | ||
"name": "pyxisdb", | ||
"version": "0.0.4-beta", | ||
"version": "0.0.5-beta", | ||
"description": "A real-time database package for communicating with Pyxiscloud server using WebSockets", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"events": "^3.3.0", | ||
"ws": "^8.0.0" | ||
"ws": "^8.18.0" | ||
}, | ||
@@ -15,0 +15,0 @@ "keywords": [ |
169
readme.md
# PyxisDB | ||
*PyxisDB* is a real-time database package for communicating with Pyxiscloud server. It provides a simple and efficient way to interact with your database using WebSocket connections. | ||
*PyxisDB* is a real-time database package for communicating with PyxiCloud server. It provides a secure and efficient way to interact with your database using WebSocket connections. | ||
## Documents | ||
## Documentation | ||
*https://docs.pyxisdb.letz.dev/* | ||
## Installation | ||
First you need to install, Check [PyxiCloud](https://github.com/Darknessking13/PyxiCloud) | ||
First, you need to install and set up [PyxiCloud](https://github.com/Darknessking13/PyxiCloud). | ||
To install PyxisDB, use npm: | ||
```bash | ||
@@ -17,7 +15,4 @@ npm install pyxisdb@latest | ||
## Usage | ||
## Quick Start | ||
PyxisDB now supports both JavaScript and TypeScript. Here's how to import and use it: | ||
### JavaScript | ||
```javascript | ||
@@ -27,40 +22,30 @@ const pyx = require('pyxisdb').default; | ||
### TypeScript | ||
```typescript | ||
import pyx from "pyxisdb"; | ||
``` | ||
Here's a basic example of how to use PyxisDB: | ||
// Connect with authentication | ||
pyx.connect('pyx://<hostname/ip>:<port>', { | ||
username: 'your_username', | ||
password: 'your_password' | ||
}) | ||
.then(() => { | ||
console.log('Connected and authenticated'); | ||
// Define a schema | ||
const userSchema = new pyx.Schema({ | ||
name: { type: 'string', required: true }, | ||
email: { type: 'string', required: true, unique: true } | ||
}, 'users'); | ||
```typescript | ||
// Connect to the Pyxiscloud server | ||
pyx.connect('pyx://<hostname/ip>:<port>') | ||
.then(() => { | ||
console.log('Connected to PyxisCloud'); | ||
// Define a schema | ||
const userSchema = new pyx.Schema({ | ||
name: { type: 'string', required: true }, | ||
age: { type: 'number' }, | ||
email: { type: 'string', required: true } | ||
}, 'users'); | ||
// Create a model | ||
const User = pyx.model('users', userSchema); | ||
// Insert a document | ||
User.insertOne({ | ||
name: 'John Doe', | ||
age: 30, | ||
email: 'john@example.com' | ||
}) | ||
.then(result => console.log('Inserted:', result)) | ||
.catch(error => console.error('Insert error:', error)); | ||
// Find documents | ||
User.find({ age: { $gte: 18 } }) | ||
.then(users => console.log('Adult users:', users)) | ||
.catch(error => console.error('Find error:', error)); | ||
// Create and use model | ||
const User = pyx.model('users', userSchema); | ||
// Insert data | ||
User.insertOne({ | ||
name: 'John Doe', | ||
email: 'john@example.com' | ||
}) | ||
.catch(error => console.error('Connection error:', error)); | ||
.then(result => console.log('User created:', result)); | ||
}) | ||
.catch(error => console.error('Connection error:', error)); | ||
``` | ||
@@ -70,11 +55,10 @@ | ||
- Real-time database operations using WebSocket protocol | ||
- Full TypeScript support with type definitions | ||
- Schema validation and management | ||
- Automatic reconnection handling | ||
- Support for complex queries and operations | ||
- Event-based communication | ||
- Heartbeat mechanism for connection stability | ||
- Request timeout handling | ||
- Comprehensive error handling | ||
- 🔐 Secure authentication system | ||
- 📦 Automatic backup management | ||
- 🔄 Robust connection handling with auto-reconnect | ||
- ✨ Schema validation | ||
- 🚀 Real-time operations | ||
- 💪 TypeScript support | ||
- ⚡ High-performance WebSocket protocol | ||
- 🛡️ Rate limiting protection | ||
@@ -84,42 +68,71 @@ ## API Reference | ||
### Connection | ||
```typescript | ||
pyx.connect(url: string, auth: { | ||
username: string; | ||
password: string; | ||
}): Promise<void> | ||
``` | ||
- `pyx.connect(url: string): Promise<void>`: Connects to the Pyxiscloud server | ||
### Schema Definition | ||
```typescript | ||
new pyx.Schema({ | ||
field: { | ||
type: string; | ||
required?: boolean; | ||
unique?: boolean; | ||
default?: any; | ||
} | ||
}, collectionName: string) | ||
``` | ||
### Schema | ||
### Model Operations | ||
- `new pyx.Schema(definition: Record<string, any>, collectionName: string)`: Creates a new schema | ||
#### Query Operations | ||
```typescript | ||
// Find documents | ||
Model.find(query?: Record<string, any>) | ||
Model.findOne(query?: Record<string, any>) | ||
### Model Methods | ||
// Insert documents | ||
Model.insertOne(document: Record<string, any>) | ||
Model.insertMany(documents: Record<string, any>[]) | ||
All model methods return Promises and support TypeScript types: | ||
// Update documents | ||
Model.updateOne(query: Record<string, any>, update: Record<string, any>) | ||
Model.updateMany(query: Record<string, any>, update: Record<string, any>) | ||
#### Query Operations | ||
- `find(query?: Record<string, any>)`: Finds all documents matching the query | ||
- `findOne(query?: Record<string, any>)`: Finds the first document matching the query | ||
// Delete documents | ||
Model.deleteOne(query: Record<string, any>) | ||
Model.deleteMany(query: Record<string, any>) | ||
``` | ||
#### Insert Operations | ||
- `insertOne(document: Record<string, any>)`: Inserts a single document | ||
- `insertMany(documents: Record<string, any>[])`: Inserts multiple documents | ||
## Query Operators | ||
#### Update Operations | ||
- `updateOne(query: Record<string, any>, updateFields: Record<string, any>)`: Updates the first matching document | ||
- `updateMany(query: Record<string, any>, updateFields: Record<string, any>)`: Updates all matching documents | ||
```typescript | ||
// Comparison | ||
{ field: { $eq: value } } // equals | ||
{ field: { $ne: value } } // not equals | ||
{ field: { $gt: value } } // greater than | ||
{ field: { $gte: value } } // greater than or equal | ||
{ field: { $lt: value } } // less than | ||
{ field: { $lte: value } } // less than or equal | ||
{ field: { $in: [values] } } // in array | ||
{ field: { $nin: [values] }} // not in array | ||
``` | ||
#### Delete Operations | ||
- `deleteOne(query: Record<string, any>)`: Deletes the first matching document | ||
- `deleteMany(query: Record<string, any>)`: Deletes all matching documents | ||
## Changelog | ||
### Version 0.0.4-beta | ||
- Added full TypeScript support with type definitions | ||
- Introduced new query methods: findOne, insertMany, updateMany, deleteOne, deleteMany | ||
- Improved WebSocket connection handling with heartbeat mechanism | ||
- Added request timeout handling | ||
- Enhanced error handling and type safety | ||
- Updated documentation and examples | ||
- Added TypeScript configuration and build setup | ||
### Version 0.0.5-beta (Latest) | ||
- 🔐 Added authentication system with secure token management | ||
- 🔐 Added encryption/decryption for data | ||
- 💾 Implemented automatic backup system with configurable intervals | ||
- 🔄 Enhanced connection stability with improved reconnection logic | ||
- 🛡️ Added IP whitelist/blacklist support | ||
- ⚡ Improved WebSocket protocol handling | ||
- 🔒 Added rate limiting protection | ||
- 📝 Updated documentation and examples | ||
## License | ||
``This project is licensed under the MIT License.`` | ||
This project is licensed under the MIT License. | ||
``` |
376
src/index.ts
@@ -1,5 +0,8 @@ | ||
// src/index.ts | ||
import WebSocket from 'ws'; | ||
import { EventEmitter } from 'events'; | ||
import crypto from 'crypto'; | ||
const ENCRYPTION_ALGORITHM = 'aes-256-cbc'; | ||
// Schema class remains unchanged | ||
export class Schema { | ||
@@ -32,170 +35,240 @@ constructor( | ||
class PyxisDB extends EventEmitter { | ||
private ws: WebSocket | null = null; | ||
private connected = false; | ||
private requestQueue = new Map<string, { resolve: Function, reject: Function, timeout: NodeJS.Timeout }>(); | ||
private requestTimeout = 30000; // 30 seconds | ||
private connectionPromise: Promise<void> | null = null; | ||
async connect(url: string): Promise<void> { | ||
if (this.connectionPromise) { | ||
return this.connectionPromise; | ||
} | ||
this.connectionPromise = new Promise((resolve, reject) => { | ||
const wsUrl = url.replace('pyx://', 'ws://'); | ||
private ws: WebSocket | null = null; | ||
private connected = false; | ||
private authenticated = false; | ||
private sessionToken: string | null = null; | ||
private requestQueue = new Map<string, { resolve: Function, reject: Function, timeout: NodeJS.Timeout }>(); | ||
private requestTimeout = 30000; // 30 seconds | ||
private connectionPromise: Promise<void> | null = null; | ||
private credentials: { username: string; password: string } | null = null; | ||
async connect(url: string, credentials: { username: string; password: string }): Promise<void> { | ||
this.credentials = credentials; | ||
this.ws = new WebSocket(wsUrl, 'pyxisdb-protocol'); | ||
this.ws.on('open', () => { | ||
this.connected = true; | ||
this.setupHeartbeat(); | ||
this.emit('connected'); | ||
resolve(); | ||
}); | ||
this.ws.on('message', (data: WebSocket.Data) => { | ||
try { | ||
const response = JSON.parse(data.toString()); | ||
const { requestId, status, data: responseData, message } = response; | ||
if (this.connectionPromise) { | ||
return this.connectionPromise; | ||
} | ||
this.connectionPromise = new Promise((resolve, reject) => { | ||
const wsUrl = url.replace('pyx://', 'ws://'); | ||
this.ws = new WebSocket(wsUrl, 'pyxisdb-protocol'); | ||
this.ws.on('open', async () => { | ||
this.connected = true; | ||
this.setupHeartbeat(); | ||
if (this.requestQueue.has(requestId)) { | ||
const { resolve, reject } = this.requestQueue.get(requestId)!; | ||
this.requestQueue.delete(requestId); | ||
try { | ||
await this.authenticate(); | ||
this.emit('connected'); | ||
resolve(); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
this.ws.on('message', (data: WebSocket.Data) => { | ||
try { | ||
const response = JSON.parse(data.toString()); | ||
const { requestId, status, data: responseData, message } = response; | ||
if (status === 'success') { | ||
resolve(responseData); | ||
} else { | ||
reject(new Error(message)); | ||
if (this.requestQueue.has(requestId)) { | ||
const { resolve, reject, timeout } = this.requestQueue.get(requestId)!; | ||
clearTimeout(timeout); | ||
this.requestQueue.delete(requestId); | ||
if (status === 'success') { | ||
resolve(responseData); | ||
} else { | ||
reject(new Error(message)); | ||
} | ||
} | ||
} catch (error) { | ||
console.error('Error processing message:', error); | ||
this.emit('error', error); | ||
} | ||
}); | ||
this.ws.on('close', () => { | ||
this.connected = false; | ||
this.authenticated = false; | ||
this.sessionToken = null; | ||
this.connectionPromise = null; | ||
this.emit('disconnected'); | ||
}); | ||
this.ws.on('error', (error) => { | ||
console.error('WebSocket error:', error); | ||
this.connected = false; | ||
this.authenticated = false; | ||
this.sessionToken = null; | ||
this.connectionPromise = null; | ||
reject(error); | ||
}); | ||
}); | ||
return this.connectionPromise; | ||
} | ||
private async authenticate(): Promise<void> { | ||
if (!this.credentials) { | ||
throw new Error('Credentials not provided'); | ||
} | ||
try { | ||
const response = await this.sendRequestUnencrypted<{ sessionToken: string }>('Authenticate', this.credentials); | ||
if (typeof response.sessionToken !== 'string' || response.sessionToken.length === 0) { | ||
throw new Error('Server did not provide a valid session token'); | ||
} | ||
this.sessionToken = response.sessionToken; | ||
this.authenticated = true; | ||
} catch (error) { | ||
console.error('Error processing message:', error); | ||
this.authenticated = false; | ||
this.sessionToken = null; | ||
throw error; | ||
} | ||
}); | ||
this.ws.on('close', () => { | ||
this.connected = false; | ||
this.connectionPromise = null; | ||
this.emit('disconnected'); | ||
}); | ||
this.ws.on('error', (error) => { | ||
this.connected = false; | ||
this.connectionPromise = null; | ||
reject(error); | ||
}); | ||
}); | ||
return this.connectionPromise; | ||
} | ||
private setupHeartbeat(): void { | ||
if (this.ws) { | ||
this.ws.on('ping', () => { | ||
this.ws?.pong(); | ||
}); | ||
} | ||
} | ||
private setupHeartbeat(): void { | ||
if (this.ws) { | ||
this.ws.on('ping', () => { | ||
this.ws?.pong(); | ||
}); | ||
} | ||
} | ||
async sendRequest(type: string, data: any): Promise<any> { | ||
if (!this.connected) { | ||
throw new Error('Not connected to server'); | ||
private async sendRequestUnencrypted<T>(type: string, data: any): Promise<T> { | ||
if (!this.connected) { | ||
throw new Error('Not connected to server'); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const requestId = Math.random().toString(36).substring(7); | ||
const request = { | ||
type, | ||
data, | ||
requestId | ||
}; | ||
const timeout = setTimeout(() => { | ||
if (this.requestQueue.has(requestId)) { | ||
this.requestQueue.delete(requestId); | ||
reject(new Error('Request timeout')); | ||
} | ||
}, this.requestTimeout); | ||
this.requestQueue.set(requestId, { resolve, reject, timeout }); | ||
this.ws?.send(JSON.stringify(request)); | ||
}); | ||
} | ||
async sendRequest<T>(type: string, data: any): Promise<T> { | ||
if (!this.connected) { | ||
throw new Error('Not connected to server'); | ||
} | ||
if (!this.authenticated) { | ||
throw new Error('Not authenticated'); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const requestId = Math.random().toString(36).substring(7); | ||
const request = { | ||
type, | ||
data, | ||
requestId, | ||
sessionToken: this.sessionToken | ||
}; | ||
const timeout = setTimeout(() => { | ||
if (this.requestQueue.has(requestId)) { | ||
this.requestQueue.delete(requestId); | ||
reject(new Error('Request timeout')); | ||
} | ||
}, this.requestTimeout); | ||
this.requestQueue.set(requestId, { resolve, reject, timeout }); | ||
this.ws?.send(JSON.stringify(request)); | ||
}); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const requestId = Math.random().toString(36).substring(7); | ||
const request = { | ||
type, | ||
data, | ||
requestId | ||
}; | ||
const timeout = setTimeout(() => { | ||
if (this.requestQueue.has(requestId)) { | ||
this.requestQueue.delete(requestId); | ||
reject(new Error('Request timeout')); | ||
// model method remains unchanged | ||
model(collectionName: string, schema?: Schema) { | ||
const self = this; | ||
if (schema) { | ||
schema.save(this).catch(console.error); | ||
} | ||
}, this.requestTimeout); | ||
this.requestQueue.set(requestId, { resolve, reject, timeout }); | ||
return { | ||
async find(query: Record<string, any> = {}) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'find', | ||
query | ||
}); | ||
}, | ||
this.ws?.send(JSON.stringify(request)); | ||
}); | ||
} | ||
async findOne(query: Record<string, any> = {}) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'findOne', | ||
query | ||
}); | ||
}, | ||
model(collectionName: string, schema?: Schema) { | ||
const self = this; | ||
if (schema) { | ||
schema.save(this).catch(console.error); | ||
} | ||
async insertOne(document: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'insertOne', | ||
document | ||
}); | ||
}, | ||
return { | ||
async find(query: Record<string, any> = {}) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'find', | ||
query | ||
}); | ||
}, | ||
async insertMany(documents: Record<string, any>[]) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'insertMany', | ||
documents | ||
}); | ||
}, | ||
async findOne(query: Record<string, any> = {}) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'findOne', | ||
query | ||
}); | ||
}, | ||
async updateOne(query: Record<string, any>, updateFields: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'updateOne', | ||
query, | ||
updateFields | ||
}); | ||
}, | ||
async insertOne(document: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'insertOne', | ||
document | ||
}); | ||
}, | ||
async updateMany(query: Record<string, any>, updateFields: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'updateMany', | ||
query, | ||
updateFields | ||
}); | ||
}, | ||
async insertMany(documents: Record<string, any>[]) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'insertMany', | ||
documents | ||
}); | ||
}, | ||
async deleteOne(query: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'deleteOne', | ||
query | ||
}); | ||
}, | ||
async updateOne(query: Record<string, any>, updateFields: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'updateOne', | ||
query, | ||
updateFields | ||
}); | ||
}, | ||
async updateMany(query: Record<string, any>, updateFields: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'updateMany', | ||
query, | ||
updateFields | ||
}); | ||
}, | ||
async deleteOne(query: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'deleteOne', | ||
query | ||
}); | ||
}, | ||
async deleteMany(query: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'deleteMany', | ||
query | ||
}); | ||
} | ||
}; | ||
} | ||
async deleteMany(query: Record<string, any>) { | ||
return self.sendRequest('Query', { | ||
collectionName, | ||
operation: 'deleteMany', | ||
query | ||
}); | ||
} | ||
}; | ||
} | ||
} | ||
@@ -206,3 +279,3 @@ | ||
export interface Pyx { | ||
connect: (url: string) => Promise<void>; | ||
connect: (url: string, credentials: { username: string; password: string }) => Promise<void>; | ||
Schema: new (definition: Record<string, any>, collectionName: string) => Schema; | ||
@@ -213,3 +286,4 @@ model: (collectionName: string, schema?: Schema) => ReturnType<PyxisDB['model']>; | ||
export const pyx: Pyx = { | ||
connect: (url: string) => pyxisdb.connect(url), | ||
connect: (url: string, credentials: { username: string; password: string }) => | ||
pyxisdb.connect(url, credentials), | ||
Schema: Schema, | ||
@@ -216,0 +290,0 @@ model: (collectionName: string, schema?: Schema) => pyxisdb.model(collectionName, schema) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25571
6
542
134
0
Updatedws@^8.18.0