Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@conduitplatform/grpc-sdk

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@conduitplatform/grpc-sdk - npm Package Compare versions

Comparing version 0.16.0-alpha.29 to 0.16.0-rc.0

9

dist/utilities/StateManager.d.ts
import { RedisManager } from './RedisManager';
import { Lock } from 'redlock';
import { Indexable } from '../interfaces';
export declare enum KNOWN_LOCKS {
STATE_MODIFICATION = "state_modification"
}
export declare class StateManager {
private readonly redisClient;
private readonly redLock;
constructor(redisManager: RedisManager, name: string);
acquireLock(resource: string, ttl?: number): Promise<Lock>;
releaseLock(lock: Lock): Promise<void>;
modifyState(modifier: (state: Indexable) => Promise<Indexable>): Promise<void>;
setState(stateObj: any): Promise<"OK">;

@@ -6,0 +15,0 @@ getState(): Promise<string | null>;

46

dist/utilities/StateManager.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StateManager = void 0;
exports.StateManager = exports.KNOWN_LOCKS = void 0;
const redlock_1 = __importDefault(require("redlock"));
var KNOWN_LOCKS;
(function (KNOWN_LOCKS) {
KNOWN_LOCKS["STATE_MODIFICATION"] = "state_modification";
})(KNOWN_LOCKS = exports.KNOWN_LOCKS || (exports.KNOWN_LOCKS = {}));
class StateManager {
constructor(redisManager, name) {
this.redisClient = redisManager.getClient({ keyPrefix: name + '_' });
this.redLock = new redlock_1.default([this.redisClient], {
// The expected clock drift; for more details see:
// http://redis.io/topics/distlock
driftFactor: 0.01,
// The max number of times Redlock will attempt to lock a resource
// before error.
retryCount: 10,
// the time in ms between attempts
retryDelay: 100,
// the max time in ms randomly added to retries
// to improve performance under high contention
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
retryJitter: 200,
// The minimum remaining time on a lock before an extension is automatically
// attempted with the `using` API.
automaticExtensionThreshold: 500, // time in ms
});
}
async acquireLock(resource, ttl = 5000) {
return await this.redLock.acquire([resource], ttl);
}
async releaseLock(lock) {
await lock.release();
}
async modifyState(modifier) {
var _a;
const lock = await this.acquireLock(KNOWN_LOCKS.STATE_MODIFICATION);
try {
const retrievedState = (_a = (await this.getState())) !== null && _a !== void 0 ? _a : '{}';
const currentState = JSON.parse(retrievedState);
const newState = await modifier(currentState);
await this.setState(JSON.stringify(newState));
}
finally {
await this.releaseLock(lock);
}
}
setState(stateObj) {

@@ -9,0 +53,0 @@ return this.setKey('state', stateObj);

7

package.json
{
"name": "@conduitplatform/grpc-sdk",
"version": "0.16.0-alpha.29",
"version": "0.16.0-rc.0",
"main": "dist/index.js",

@@ -25,3 +25,3 @@ "types": "dist/index.d.ts",

"express": "^4.18.2",
"fast-jwt": "^3.3.0",
"fast-jwt": "^3.3.2",
"fs-extra": "^11.1.1",

@@ -32,4 +32,5 @@ "ioredis": "^5.3.2",

"nice-grpc-client-middleware-retry": "^3",
"prom-client": "^14.2.0",
"prom-client": "^15.0.0",
"protobufjs": "^7.2.4",
"redlock": "^5.0.0-beta.2",
"winston": "^3.8.2",

@@ -36,0 +37,0 @@ "winston-loki": "^6.0.7"

Sorry, the diff of this file is not supported yet

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