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

typescript-state-machine

Package Overview
Dependencies
Maintainers
6
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-state-machine - npm Package Compare versions

Comparing version 0.9.3 to 0.9.4

1

dist/index.d.ts

@@ -56,4 +56,5 @@ export declare namespace fsm {

function CheckStateIn(states: State[], message?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
function CheckStateNotIn(states: State[], message?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
function AssumeStateIs(state: State): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
function AssumeStateIsNot(state: State): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
}

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

catch (e) {
this.log.warn('Uncaught error in listener :' + e);
this.log.error('Uncaught error in listener', e);
}

@@ -254,2 +254,37 @@ }

/*
Method annotator. Throw an error if the state when the method is called
is one of the given states
*/
function CheckStateNotIn(states, message) {
return function (target, propertyKey, descriptor) {
var originalMethod;
if (descriptor.value) {
originalMethod = descriptor.value;
descriptor.value = function () {
var context = this;
if (states.indexOf(context.state) === -1) {
return originalMethod.apply(context, arguments);
}
else {
throw new Error(message || 'Illegal execution of ' + propertyKey + ' : State should not be one of ' + states);
}
};
}
else if (descriptor.get) {
var originalGetter_2 = descriptor.get;
descriptor.get = function () {
var context = this;
if (states.indexOf(context.state) === -1) {
return originalGetter_2.apply(context, arguments);
}
else {
throw new Error(message || 'Illegal execution of ' + propertyKey + ' : State should not be one of these states: ' + states);
}
};
}
return descriptor;
};
}
fsm.CheckStateNotIn = CheckStateNotIn;
/*
Method annotator. Skip the method execution if the state when the method is called

@@ -256,0 +291,0 @@ is different from the given state

2

package.json
{
"name": "typescript-state-machine",
"version": "0.9.3",
"version": "0.9.4",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -128,3 +128,3 @@ import { getLogger } from 'log4javascript'

} catch (e) {
this.log.warn('Uncaught error in listener :' + e)
this.log.error('Uncaught error in listener', e)
}

@@ -302,4 +302,34 @@ } else {

}
/*
Method annotator. Throw an error if the state when the method is called
is one of the given states
*/
export function CheckStateNotIn(states: State[], message?: string) {
return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
let originalMethod: any
if (descriptor.value) {
originalMethod = descriptor.value
descriptor.value = function() {
const context = this as StateMachine<any>
if (states.indexOf(context.state) === -1) {
return originalMethod.apply(context, arguments)
} else {
throw new Error(message || 'Illegal execution of ' + propertyKey + ' : State should not be one of ' + states)
}
}
} else if (descriptor.get) {
const originalGetter = descriptor.get
descriptor.get = function() {
const context = this as StateMachine<any>
if (states.indexOf(context.state) === -1) {
return originalGetter.apply(context, arguments)
} else {
throw new Error(message || 'Illegal execution of ' + propertyKey + ' : State should not be one of these states: ' + states)
}
}
}
return descriptor
}
}
/*
Method annotator. Skip the method execution if the state when the method is called

@@ -306,0 +336,0 @@ is different from the given state

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