New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dexie-relay

Package Overview
Dependencies
Maintainers
0
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dexie-relay - npm Package Compare versions

Comparing version 6.0.3 to 6.0.4

198

index.js
import {Client} from 'relay-to-relay'
import {Dexie} from 'dexie'
import {EventEmitter} from 'events'
import "dexie-export-import"

@@ -124,96 +125,3 @@ export default class Base extends EventEmitter {

} else if(datas.session){
if(datas.session === 'request'){
const count = datas.count || 25
const stamps = await dataTab.where('stamp').notEqual(0).toArray()
while(stamps.length){
datas.session = 'response'
datas.edits = null
datas.stamps = stamps.splice(stamps.length - count, count)
const test = JSON.stringify(datas)
if(test.length < 16000){
this.client.onSend(test, nick)
} else {
const useID = crypto.randomUUID()
const pieces = Math.ceil(test.length / 15000)
let used = 0
for(let i = 1;i < (pieces + 1);i++){
const slicing = i * 15000
this.client.onSend(JSON.stringify({name: datas.name, piecing: 'response', pieces, piece: i, iden: useID, stamps: test.slice(used, slicing)}), nick)
used = slicing
}
}
}
const edits = await dataTab.where('edit').notEqual(0).toArray()
while(edits.length){
datas.session = 'response'
datas.stamps = null
datas.edits = edits.splice(edits.length - count, count)
const test = JSON.stringify(datas)
if(test.length < 16000){
this.client.onSend(test, nick)
} else {
const useID = crypto.randomUUID()
const pieces = Math.ceil(test.length / 15000)
let used = 0
for(let i = 1;i < (pieces + 1);i++){
const slicing = i * 15000
this.client.onSend(JSON.stringify({name: datas.name, piecing: 'response', pieces, piece: i, iden: useID, edits: test.slice(used, slicing)}), nick)
used = slicing
}
}
}
} else if(datas.session === 'response'){
if(datas.stamps){
if(!datas.stamps.length){
return
}
const arr = []
for(const data of datas.stamps){
try {
const got = await dataTab.get(data.iden)
if(got){
if(got.edit < data.edit){
await dataTab.put(data)
arr.push(data.iden)
}
} else {
await dataTab.add(data)
arr.push(data.iden)
}
} catch (err) {
if(this._debug){
console.error(err)
}
continue
}
}
this.emit('bulk', arr)
}
if(datas.edits){
if(!datas.edits.length){
return
}
const arr = []
for(const data of datas.edits){
try {
const got = await dataTab.get(data.iden)
if(got){
if(got.edit < data.edit){
await dataTab.put(data)
arr.push(data.iden)
}
} else {
await dataTab.add(data)
arr.push(data.iden)
}
} catch (err) {
if(this._debug){
console.error(err)
}
continue
}
}
this.emit('bulk', arr)
}
} else if(datas.session === 'stamp'){
if(datas.session === 'stamp'){
let stamps

@@ -230,3 +138,3 @@ if(datas.between){

} else {
return
stamps = await dataTab.where('stamp').notEqual(0).toArray()
}

@@ -289,3 +197,3 @@ const count = datas.count || 25

} else {
return
edits = await dataTab.where('edit').notEqual(0).toArray()
}

@@ -431,73 +339,2 @@ const count = datas.count || 25

}
} else if(datas.piecing === 'response'){
if(this._piecing.has(datas.iden)){
const obj = this._piecing.get(datas.iden)
if(!obj.arr[datas.piece - 1]){
obj.arr[datas.piece - 1] = datas.data
obj.stamp = Date.now()
if(obj.arr.every(Boolean)){
const useData = JSON.parse(obj.arr.join(''))
if(useData.stamps){
if(!useData.stamps.length){
return
}
const arr = []
for(const data of useData.stamps){
try {
const got = await dataTab.get(data.iden)
if(got){
if(got.edit < data.edit){
await dataTab.put(data)
arr.push(data.iden)
}
} else {
await dataTab.add(data)
arr.push(data.iden)
}
} catch (err) {
if(this._debug){
console.error(err)
}
continue
}
}
this.emit('bulk', arr)
}
if(useData.edits){
if(!useData.edits.length){
return
}
const arr = []
for(const data of useData.edits){
try {
const got = await dataTab.get(data.iden)
if(got){
if(got.edit < data.edit){
await dataTab.put(data)
arr.push(data.iden)
}
} else {
await dataTab.add(data)
arr.push(data.iden)
}
} catch (err) {
if(this._debug){
console.error(err)
}
continue
}
}
this.emit('bulk', arr)
}
this._piecing.delete(datas.iden)
}
}
} else {
const obj = {stamp: Date.now(), arr: new Array(datas.pieces).fill(null)}
this._piecing.set(datas.iden, obj)
if(!obj.arr[datas.piece - 1]){
obj.arr[datas.piece - 1] = datas.data
obj.stamp = Date.now()
}
}
} else if(datas.piecing === 'stamps'){

@@ -608,3 +445,3 @@ if(this._piecing.has(datas.iden)){

}
this._connect = (chan) => {
this._connect = async (chan) => {
console.log('connected: ' + chan)

@@ -614,5 +451,5 @@

if(this._sync === true){
this.client.onSend(JSON.stringify({name: table.name, session: 'request'}), chan)
}
if(this._sync === false){
this.client.onSend(JSON.stringify({name: table.name, session: 'stamp'}), chan)
this.client.onSend(JSON.stringify({name: table.name, session: 'edit'}), chan)
} else if(this._sync === null){
if(this._span){

@@ -625,2 +462,13 @@ this.client.onSend(JSON.stringify({between: {from: this._span, to: Date.now()}, name: table.name, session: 'stamp'}), chan)

}
} else if(this._sync === false){
const s = await table.where('stamp').notEqual(0).last()
const e = await table.where('edit').notEqual(0).last()
if(s){
this.client.onSend(JSON.stringify({from: s.stamp - 43200000, name: table.name, session: 'stamp'}), chan)
}
if(e){
this.client.onSend(JSON.stringify({from: e.edit - 43200000, name: table.name, session: 'edit'}), chan)
}
} else {
continue
}

@@ -732,2 +580,10 @@ }

async getDB(blob, opts){
return await this.db.import(blob, opts)
}
async postDB(opts){
return await this.db.export(opts)
}
quit(){

@@ -734,0 +590,0 @@ clearInterval(this._routine)

3

package.json
{
"name": "dexie-relay",
"version": "6.0.3",
"version": "6.0.4",
"main": "index.js",

@@ -14,2 +14,3 @@ "scripts": {

"dexie": "^4.0.9",
"dexie-export-import": "^4.1.4",
"events": "^3.3.0",

@@ -16,0 +17,0 @@ "relay-to-relay": "^2.0.2"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc