🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

deep-storage

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-storage - npm Package Compare versions

Comparing version

to
2.0.0

30

async.d.ts

@@ -8,9 +8,8 @@ import { DeepStorage, UsesDeepStorage } from "./index";

}
export interface DeepAsyncState<Request, Response> {
export interface DeepAsyncState<Response> {
status: AsyncStatus;
request?: Request;
response?: Response;
data?: Response;
error?: any;
}
export interface DeepAsync<Request, Response> extends DeepAsyncState<Request, Response>, UsesDeepStorage<DeepAsyncState<Request, Response>> {
export interface DeepAsync<Response> extends DeepAsyncState<Response>, UsesDeepStorage<DeepAsyncState<Response>> {
completed: boolean;

@@ -21,15 +20,13 @@ succeeded: boolean;

failed: boolean;
run(request: Request): Promise<DeepAsyncState<Request, Response>>;
rerun(): Promise<DeepAsyncState<Request, Response>>;
updateResponse(updater: (prevState: Response) => Response): Promise<DeepAsyncState<Request, Response>>;
run(): Promise<DeepAsyncState<Response>>;
updateResponse(updater: (prevState: Response) => Response): Promise<DeepAsyncState<Response>>;
}
export declare class AlreadyRunningError extends Error {
}
export declare class DefaultDeepAsync<Request, Response> implements DeepAsync<Request, Response> {
storage: DeepStorage<DeepAsyncState<Request, Response>>;
process: (request: Request) => Promise<Response>;
constructor(storage: DeepStorage<DeepAsyncState<Request, Response>>, process: (request: Request) => Promise<Response>);
run: (request: Request) => Promise<DeepAsyncState<Request, Response>>;
rerun: () => Promise<DeepAsyncState<Request, Response>>;
updateResponse: (updater: (prevState: Response) => Response) => Promise<DeepAsyncState<Request, Response>>;
export declare class DefaultDeepAsync<Response> implements DeepAsync<Response> {
storage: DeepStorage<DeepAsyncState<Response>>;
process: () => Promise<Response>;
constructor(storage: DeepStorage<DeepAsyncState<Response>>, process: () => Promise<Response>);
run: () => Promise<DeepAsyncState<Response>>;
updateResponse: (updater: (prevState: Response) => Response) => Promise<DeepAsyncState<Response>>;
readonly status: AsyncStatus;

@@ -41,7 +38,6 @@ readonly running: boolean;

readonly completed: boolean;
readonly request: Request;
readonly response: Response;
readonly data: Response;
readonly error: any;
}
export declare const deepAsync: <Request, Response>(storage: DeepStorage<DeepAsyncState<Request, Response>, {}>, process: (request: Request) => Promise<Response>) => Promise<DefaultDeepAsync<Request, Response>>;
export declare const deepAsync: <Response>(storage: DeepStorage<DeepAsyncState<Response>, {}>, process: () => Promise<Response>) => Promise<DefaultDeepAsync<Response>>;
export default deepAsync;

@@ -64,3 +64,3 @@ "use strict";

})(AsyncStatus = exports.AsyncStatus || (exports.AsyncStatus = {}));
var AlreadyRunningError = (function (_super) {
var AlreadyRunningError = /** @class */ (function (_super) {
__extends(AlreadyRunningError, _super);

@@ -73,3 +73,3 @@ function AlreadyRunningError() {

exports.AlreadyRunningError = AlreadyRunningError;
var DefaultDeepAsync = (function () {
var DefaultDeepAsync = /** @class */ (function () {
function DefaultDeepAsync(storage, process) {

@@ -79,4 +79,4 @@ var _this = this;

this.process = process;
this.run = function (request) { return __awaiter(_this, void 0, void 0, function () {
var response_1, error_1;
this.run = function () { return __awaiter(_this, void 0, void 0, function () {
var data_1, error_1;
return __generator(this, function (_a) {

@@ -88,3 +88,3 @@ switch (_a.label) {

throw new AlreadyRunningError();
return [4 /*yield*/, this.storage.update(function (state) { return (__assign({}, state, { status: AsyncStatus.Running, request: request, response: undefined, error: undefined })); })];
return [4 /*yield*/, this.storage.update(function (state) { return (__assign({}, state, { status: AsyncStatus.Running, data: undefined, error: undefined })); })];
case 1:

@@ -95,6 +95,6 @@ _a.sent();

_a.trys.push([2, 5, , 7]);
return [4 /*yield*/, this.process(request)];
return [4 /*yield*/, this.process()];
case 3:
response_1 = _a.sent();
return [4 /*yield*/, this.storage.update(function (state) { return (__assign({}, state, { status: AsyncStatus.Succeeded, response: response_1, error: undefined })); })];
data_1 = _a.sent();
return [4 /*yield*/, this.storage.update(function (state) { return (__assign({}, state, { status: AsyncStatus.Succeeded, data: data_1, error: undefined })); })];
case 4:

@@ -105,3 +105,3 @@ _a.sent();

error_1 = _a.sent();
return [4 /*yield*/, this.storage.update(function (state) { return (__assign({}, state, { status: AsyncStatus.Failed, error: error_1, response: undefined })); })];
return [4 /*yield*/, this.storage.update(function (state) { return (__assign({}, state, { status: AsyncStatus.Failed, error: error_1, data: undefined })); })];
case 6:

@@ -114,5 +114,2 @@ _a.sent();

}); };
this.rerun = function () {
return _this.run(_this.request);
};
this.updateResponse = function (updater) { return __awaiter(_this, void 0, void 0, function () {

@@ -122,3 +119,3 @@ return __generator(this, function (_a) {

case 0: return [4 /*yield*/, this.storage.update(function (state) {
return (__assign({}, state, { status: AsyncStatus.Succeeded, response: updater(state.response), error: undefined }));
return (__assign({}, state, { status: AsyncStatus.Succeeded, data: updater(state.data), error: undefined }));
})];

@@ -162,4 +159,4 @@ case 1:

});
Object.defineProperty(DefaultDeepAsync.prototype, "request", {
get: function () { return this.storage.state.request; },
Object.defineProperty(DefaultDeepAsync.prototype, "data", {
get: function () { return this.storage.state.data; },
enumerable: true,

@@ -169,8 +166,2 @@ configurable: true

;
Object.defineProperty(DefaultDeepAsync.prototype, "response", {
get: function () { return this.storage.state.response; },
enumerable: true,
configurable: true
});
;
Object.defineProperty(DefaultDeepAsync.prototype, "error", {

@@ -177,0 +168,0 @@ get: function () { return this.storage.state.error; },

@@ -61,3 +61,3 @@ "use strict";

exports.isPathMatch = isPathMatch;
var DefaultDeepStorage = (function () {
var DefaultDeepStorage = /** @class */ (function () {
function DefaultDeepStorage(state) {

@@ -219,3 +219,3 @@ var _this = this;

exports.DefaultDeepStorage = DefaultDeepStorage;
var NestedDeepStorage = (function () {
var NestedDeepStorage = /** @class */ (function () {
function NestedDeepStorage(path, rootStorage) {

@@ -222,0 +222,0 @@ var _this = this;

{
"name": "deep-storage",
"version": "1.0.11",
"version": "2.0.0",
"description": "Simple observable state management for reactive applications",

@@ -12,8 +12,8 @@ "main": "./lib/index.js",

"devDependencies": {
"@types/jest": "^20.0.2",
"jest": "^20.0.4",
"rimraf": "^2.6.1",
"typescript": "^2.4.1",
"webpack": "^3.3.0",
"webpack-dev-server": "^2.5.1"
"@types/jest": "^21.1.10",
"jest": "^22.0.4",
"rimraf": "^2.6.2",
"typescript": "^2.6.2",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
},

@@ -20,0 +20,0 @@ "scripts": {

@@ -8,6 +8,6 @@ import {deepAsync, deepStorage, AsyncStatus} from '../';

expect(value.status).toBe(AsyncStatus.Created);
await value.run({});
await value.run();
expect(value.started).toBeTruthy();
expect(value.status).toBe(AsyncStatus.Succeeded);
expect(value.response).toBe('test');
expect(value.data).toBe('test');
});

@@ -10,12 +10,11 @@ import { DeepStorage, UsesDeepStorage } from "./index";

export interface DeepAsyncState<Request, Response> {
export interface DeepAsyncState<Response> {
status: AsyncStatus;
request?: Request;
response?: Response;
data?: Response;
error?: any;
}
export interface DeepAsync<Request, Response> extends
DeepAsyncState<Request, Response>,
UsesDeepStorage<DeepAsyncState<Request, Response>> {
export interface DeepAsync<Response> extends
DeepAsyncState<Response>,
UsesDeepStorage<DeepAsyncState<Response>> {
completed: boolean;

@@ -26,5 +25,4 @@ succeeded: boolean;

failed: boolean;
run(request: Request): Promise<DeepAsyncState<Request, Response>>;
rerun(): Promise<DeepAsyncState<Request, Response>>;
updateResponse(updater: (prevState: Response) => Response): Promise<DeepAsyncState<Request, Response>>;
run(): Promise<DeepAsyncState<Response>>;
updateResponse(updater: (prevState: Response) => Response): Promise<DeepAsyncState<Response>>;
}

@@ -35,31 +33,28 @@

export class DefaultDeepAsync<Request, Response> implements DeepAsync<Request, Response> {
export class DefaultDeepAsync<Response> implements DeepAsync<Response> {
constructor(
public storage: DeepStorage<DeepAsyncState<Request, Response>>,
public process: (request: Request) => Promise<Response>
public storage: DeepStorage<DeepAsyncState<Response>>,
public process: () => Promise<Response>
) {
}
run = async (request: Request): Promise<DeepAsyncState<Request, Response>> => {
run = async (): Promise<DeepAsyncState<Response>> => {
// todo: probably want to queue this
if (this.status === AsyncStatus.Running) throw new AlreadyRunningError();
await this.storage.update(state => ({ ...state, status: AsyncStatus.Running, request, response: undefined, error: undefined }));
await this.storage.update(state => ({ ...state, status: AsyncStatus.Running, data: undefined, error: undefined }));
try {
const response = await this.process(request);
await this.storage.update(state => ({ ...state, status: AsyncStatus.Succeeded, response, error: undefined }));
const data = await this.process();
await this.storage.update(state => ({ ...state, status: AsyncStatus.Succeeded, data, error: undefined }));
return this.storage.state;
} catch (error) {
await this.storage.update(state => ({ ...state, status: AsyncStatus.Failed, error, response: undefined }));
await this.storage.update(state => ({ ...state, status: AsyncStatus.Failed, error, data: undefined }));
return this.storage.state;
}
}
rerun = (): Promise<DeepAsyncState<Request, Response>> => {
return this.run(this.request);
}
updateResponse = async (updater: (prevState: Response) => Response): Promise<DeepAsyncState<Request, Response>> => {
updateResponse = async (updater: (prevState: Response) => Response): Promise<DeepAsyncState<Response>> => {
await this.storage.update(
(state: DeepAsyncState<Request, Response>) =>
(state: DeepAsyncState<Response>) =>
({
...state,
status: AsyncStatus.Succeeded,
response: updater(state.response),
data: updater(state.data),
error: undefined

@@ -75,10 +70,9 @@ }));

get completed() { return this.storage.state.status === AsyncStatus.Failed || this.storage.state.status == AsyncStatus.Succeeded }
get request() { return this.storage.state.request };
get response() { return this.storage.state.response };
get data() { return this.storage.state.data };
get error() { return this.storage.state.error };
}
export const deepAsync = async <Request, Response>(
storage: DeepStorage<DeepAsyncState<Request, Response>>,
process: (request: Request) => Promise<Response>
export const deepAsync = async <Response>(
storage: DeepStorage<DeepAsyncState<Response>>,
process: () => Promise<Response>
) => {

@@ -85,0 +79,0 @@ await storage.set({

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet