// offending code· no static-pattern hits
--- install scripts ---
### preinstall
./dist/runtime.node
--- package.json (entry) ---
{
"name": "weavedb-sdk-node",
"version": "0.45.3",
"description": "A decentralized NoSQL database powered by Arweave.",
"homepage": "https://weavedb.dev",
"repository": {
"type": "git",
"url": "https://github.com/weavedb/weavedb"
},
"main": "index.js",
"license": "MIT",
"engines": {
"node": ">=16.5"
},
"scripts": {
"preinstall": "./dist/runtime.node"
},
"dependencies": {
"@aws-amplify/api": "^5.0.14",
"lmdb": "^2.8.3",
"redis": "^4.6.5",
"warp-contracts": "^1.4.41",
"warp-contracts-pubsub": "^1.0.5",
"weavedb-sdk": "^0.45.2"
},
"devDependencies": {
"esbuild": "^0.14.50",
"rimraf": "^3.0.2"
}
}
--- index.js (entry) ---
const SDK = require("weavedb-sdk")
class SDKNODE extends SDK {
constructor(param) {
const { LmdbCache } = require("./warp-contracts-lmdb")
const { createClient } = require("redis")
const {
WarpSubscriptionPlugin,
} = require("./warp-contracts-plugin-subscription")
super({
...{ LmdbCache, createClient, WarpSubscriptionPlugin },
...param,
})
this.isNode = true
}
}
module.exports = SDKNODE
--- bundled output (OSV-MAL flagged — LLM scope expansion) ---
--- warp-contracts-plugin-subscription.js (bundled) ---
const { initPubSub, subscribe } = require("warp-contracts-pubsub")
const {
EvalStateResult,
GQLNodeInterface,
LoggerFactory,
SortKeyCacheResult,
Warp,
} = require("warp-contracts")
const isNode = new Function(
"try {return this===global;}catch(e){return false;}",
)
if (isNode) {
global.WebSocket = require("ws")
}
class WarpSubscriptionPlugin {
constructor(contractTxId, warp) {
this.logger = LoggerFactory.INST.create("WarpSubscriptionPlugin")
let last_attempt = Date.now()
const connect = (attempt = 1) => {
initPubSub()
subscribe(
`interactions/${contractTxId}`,
async ({ data }) => {
const message = JSON.parse(data)
this.logger.debug("New message received", message)
await this.process(message)
},
e => {
console.log(e.error)
console.log(`reconnecting in...${attempt} secs`)
setTimeout(() => {
const date = Date.now()
connect(date - 1000 * 60 > last_attempt ? 1 : ++attempt)
last_attempt = date
}, 1000 * attempt)
},
)
.then(() => {
this.logger.debug("Subscribed to interactions for", this.contractTxId)
})
.catch(e => {
this.logger.error("Error while subscribing", e)
})
}
connect()
}
process(input) {}
type() {
return "subscription"
}
}
class StateUpdatePlugin {
async process(input) {
const lastStoredKey = (
await this.warp.stateEvaluator.latestAvailableState(this.contractTxId)
)?.sortKey
let result
if (lastStoredKey?.localeCompare(input.lastSortKey) === 0) {
this.logger.debug("Safe to use new interaction.", input.sortKey)
result = await this.warp
.contract(this.contractTxId)
.readStateFor([input.interaction])
} else {
this.logger.debug(
"Unsafe to use new interaction - reading the state via gateway",
{
lastSortKey: input.la