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

asl-validator

Package Overview
Dependencies
Maintainers
2
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asl-validator - npm Package Compare versions

Comparing version 3.9.0 to 3.10.0

dist/src/schemas/jsonata.json

4

dist/src/checks/json-schema-errors.js

@@ -9,2 +9,3 @@ "use strict";

var paths_json_1 = __importDefault(require("../schemas/paths.json"));
var jsonata_json_1 = __importDefault(require("../schemas/jsonata.json"));
var choice_json_1 = __importDefault(require("../schemas/choice.json"));

@@ -29,2 +30,3 @@ var fail_json_1 = __importDefault(require("../schemas/fail.json"));

paths_json_1.default,
jsonata_json_1.default,
choice_json_1.default,

@@ -52,2 +54,4 @@ fail_json_1.default,

ajv.addFormat("asl_payload_template", function () { return true; });
// An ASL ResultPath is a ReferencePath that cannot have variables.
ajv.addFormat("asl_result_path", function () { return true; });
}

@@ -54,0 +58,0 @@ if (options.checkArn) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExactlyOne = exports.AtMostOne = exports.stateChecks = exports.IsChoice = exports.IsFail = exports.IsSucceed = exports.IsWait = exports.IsTask = exports.IsMap = void 0;
exports.ExactlyOne = exports.None = exports.AtMostOne = exports.stateChecks = exports.IsChoice = exports.IsFail = exports.IsSucceed = exports.IsWait = exports.IsTask = exports.IsMap = void 0;
var get_states_1 = require("./get-states");

@@ -66,4 +66,4 @@ var jsonpath_plus_1 = require("jsonpath-plus");

};
var AtMostOne = function (_a) {
var props = _a.props, errorCode = _a.errorCode, path = _a.path;
var enforceMaxCount = function (_a) {
var props = _a.props, errorCode = _a.errorCode, path = _a.path, maxCount = _a.maxCount, errorMessage = _a.errorMessage;
return function (_a) {

@@ -82,3 +82,3 @@ var state = _a.state, stateName = _a.stateName;

var count = getPropertyCount({ object: object, props: props });
if (count > 1) {
if (count > maxCount) {
return {

@@ -88,3 +88,3 @@ "Error code": errorCode,

// since the state names are unique.
Message: "State \"".concat(stateName, "\" MUST contain at most one of ").concat(props
Message: "State \"".concat(stateName, "\" ").concat(errorMessage, " ").concat(props
.map(function (p) {

@@ -99,3 +99,24 @@ return "\"".concat(p, "\"");

};
var AtMostOne = function (_a) {
var props = _a.props, errorCode = _a.errorCode, path = _a.path;
return enforceMaxCount({
maxCount: 1,
props: props,
errorCode: errorCode,
path: path,
errorMessage: "MUST contain at most one of",
});
};
exports.AtMostOne = AtMostOne;
var None = function (_a) {
var props = _a.props, errorCode = _a.errorCode, path = _a.path;
return enforceMaxCount({
maxCount: 0,
props: props,
errorCode: errorCode,
path: path,
errorMessage: "MUST NOT contain any of",
});
};
exports.None = None;
var ExactlyOne = function (_a) {

@@ -102,0 +123,0 @@ var props = _a.props, errorCode = _a.errorCode;

@@ -142,2 +142,5 @@ {

"type": "boolean"
},
"Condition": {
"$ref": "jsonata.json#/definitions/condition"
}

@@ -271,2 +274,5 @@ },

"required": ["IsTimestamp"]
},
{
"required": ["Condition"]
}

@@ -318,2 +324,8 @@ ]

"type": "string"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
}

@@ -320,0 +332,0 @@ },

@@ -26,2 +26,5 @@ {

"type": "string"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -28,0 +31,0 @@ },

@@ -26,3 +26,3 @@ {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
},

@@ -66,2 +66,5 @@ "ItemsPath": {

"$ref": "paths.json#/definitions/asl_ref_path"
},
"Arguments": {
"$ref": "jsonata.json#/definitions/arguments"
}

@@ -206,2 +209,11 @@ },

"$ref": "paths.json#/definitions/asl_ref_path"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -208,0 +220,0 @@ },

@@ -32,3 +32,3 @@ {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
},

@@ -83,3 +83,3 @@ "Branches": {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
}

@@ -89,2 +89,14 @@ },

}
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"Arguments": {
"$ref": "jsonata.json#/definitions/arguments"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -91,0 +103,0 @@ },

@@ -26,3 +26,3 @@ {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
},

@@ -32,3 +32,12 @@ "Parameters": {

},
"Result": {}
"Result": {},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}
},

@@ -35,0 +44,0 @@ "required": ["Type"],

@@ -13,2 +13,6 @@ {

},
"asl_result_path": {
"type": ["string", "null"],
"format": "asl_result_path"
},
"_payload_template_object": {

@@ -15,0 +19,0 @@ "type": "object",

@@ -27,2 +27,5 @@ {

"minimum": 0
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -29,0 +32,0 @@ },

@@ -18,2 +18,8 @@ {

"$ref": "paths.json#/definitions/asl_path"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -20,0 +26,0 @@ },

@@ -54,3 +54,3 @@ {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
},

@@ -99,3 +99,3 @@ "Retry": {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
}

@@ -128,2 +128,14 @@ },

"$ref": "paths.json#/definitions/asl_payload_template"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"Arguments": {
"$ref": "jsonata.json#/definitions/arguments"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -130,0 +142,0 @@ },

@@ -37,2 +37,11 @@ {

"$ref": "paths.json#/definitions/asl_ref_path"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -39,0 +48,0 @@ },

@@ -26,2 +26,3 @@ "use strict";

StateMachineErrorCode["FailErrorProperty"] = "FAIL_ERROR_PROPERTY";
StateMachineErrorCode["QueryLanguageFieldError"] = "QUERY_LANGUAGE_FIELD";
})(StateMachineErrorCode || (exports.StateMachineErrorCode = StateMachineErrorCode = {}));

@@ -15,2 +15,19 @@ "use strict";

module.exports = function validator(definition, opts) {
var _a;
// A state machine's query language defaults to JSONPath.
// The interpreter MUST support JSONPath and JSONata, and
// MAY support others.
var defaultQueryLanguage = (_a = definition.QueryLanguage) !== null && _a !== void 0 ? _a : "JSONPath";
var IsJsonPath = function (_a) {
var _b;
var state = _a.state;
var queryLanguage = (_b = state.QueryLanguage) !== null && _b !== void 0 ? _b : defaultQueryLanguage;
return queryLanguage === "JSONPath";
};
var IsJsonNata = function (_a) {
var _b;
var state = _a.state;
var queryLanguage = (_b = state.QueryLanguage) !== null && _b !== void 0 ? _b : defaultQueryLanguage;
return queryLanguage === "JSONata";
};
var options = opts !== null && opts !== void 0 ? opts : DefaultOptions;

@@ -138,2 +155,32 @@ var errors = (0, json_schema_errors_1.jsonSchemaErrors)(definition, options);

},
{
filter: IsJsonNata,
checker: (0, state_checks_1.None)({
props: [
"InputPath",
"OutputPath",
"ResultPath",
"Parameters",
"ResultSelector",
],
errorCode: types_1.StateMachineErrorCode.QueryLanguageFieldError,
}),
},
{
filter: IsJsonPath,
checker: (0, state_checks_1.None)({
props: ["Arguments", "Output"],
errorCode: types_1.StateMachineErrorCode.QueryLanguageFieldError,
}),
},
{
filter: function (entry) {
return (0, state_checks_1.IsMap)(entry) && IsJsonPath(entry);
},
checker: (0, state_checks_1.None)({
props: ["Arguments"],
path: "$.ItemReader",
errorCode: types_1.StateMachineErrorCode.QueryLanguageFieldError,
}),
},
]));

@@ -140,0 +187,0 @@ }

4

package.json
{
"name": "asl-validator",
"version": "3.9.0",
"version": "3.10.0",
"description": "Amazon States Language validator",

@@ -37,3 +37,3 @@ "main": "./dist/src/validator.js",

"ajv": "^8.12.0",
"asl-path-validator": "^0.14.2",
"asl-path-validator": "^0.15.0",
"commander": "^10.0.1",

@@ -40,0 +40,0 @@ "jsonpath-plus": "^10.0.0",

import Ajv, { ErrorObject } from "ajv";
import paths from "../schemas/paths.json";
import jsonata from "../schemas/jsonata.json";
import choice from "../schemas/choice.json";

@@ -23,2 +24,3 @@ import fail from "../schemas/fail.json";

paths,
jsonata,
choice,

@@ -45,2 +47,4 @@ fail,

ajv.addFormat("asl_payload_template", () => true);
// An ASL ResultPath is a ReferencePath that cannot have variables.
ajv.addFormat("asl_result_path", () => true);
}

@@ -47,0 +51,0 @@ if (options.checkArn) {

@@ -82,9 +82,13 @@ import {

export const AtMostOne = ({
const enforceMaxCount = ({
props,
errorCode,
path,
maxCount,
errorMessage,
}: {
props: string[];
errorCode: StateMachineErrorCode;
maxCount: number;
errorMessage: string;
// path to a sub-property within the state to use as the

@@ -110,3 +114,3 @@ // context for the property checks. This is intended to

const count = getPropertyCount({ object, props });
if (count > 1) {
if (count > maxCount) {
return {

@@ -116,3 +120,3 @@ "Error code": errorCode,

// since the state names are unique.
Message: `State "${stateName}" MUST contain at most one of ${props
Message: `State "${stateName}" ${errorMessage} ${props
.map((p) => {

@@ -128,2 +132,50 @@ return `"${p}"`;

export const AtMostOne = ({
props,
errorCode,
path,
}: {
props: string[];
errorCode: StateMachineErrorCode;
// path to a sub-property within the state to use as the
// context for the property checks. This is intended to
// support enforcement of constraints on nested properties
// within a State.
// See the Map's ItemReader.ReaderConfiguration at most one
// rule for MaxItems and MaxItemsPath.
path?: string;
}): StateChecker => {
return enforceMaxCount({
maxCount: 1,
props,
errorCode,
path,
errorMessage: "MUST contain at most one of",
});
};
export const None = ({
props,
errorCode,
path,
}: {
props: string[];
errorCode: StateMachineErrorCode;
// path to a sub-property within the state to use as the
// context for the property checks. This is intended to
// support enforcement of constraints on nested properties
// within a State.
// See the Map's ItemReader.ReaderConfiguration at most one
// rule for MaxItems and MaxItemsPath.
path?: string;
}): StateChecker => {
return enforceMaxCount({
maxCount: 0,
props,
errorCode,
path,
errorMessage: "MUST NOT contain any of",
});
};
export const ExactlyOne = ({

@@ -130,0 +182,0 @@ props,

@@ -142,2 +142,5 @@ {

"type": "boolean"
},
"Condition": {
"$ref": "jsonata.json#/definitions/condition"
}

@@ -271,2 +274,5 @@ },

"required": ["IsTimestamp"]
},
{
"required": ["Condition"]
}

@@ -318,2 +324,8 @@ ]

"type": "string"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
}

@@ -320,0 +332,0 @@ },

@@ -26,2 +26,5 @@ {

"type": "string"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -28,0 +31,0 @@ },

@@ -26,3 +26,3 @@ {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
},

@@ -66,2 +66,5 @@ "ItemsPath": {

"$ref": "paths.json#/definitions/asl_ref_path"
},
"Arguments": {
"$ref": "jsonata.json#/definitions/arguments"
}

@@ -206,2 +209,11 @@ },

"$ref": "paths.json#/definitions/asl_ref_path"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -208,0 +220,0 @@ },

@@ -32,3 +32,3 @@ {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
},

@@ -83,3 +83,3 @@ "Branches": {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
}

@@ -89,2 +89,14 @@ },

}
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"Arguments": {
"$ref": "jsonata.json#/definitions/arguments"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -91,0 +103,0 @@ },

@@ -26,3 +26,3 @@ {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
},

@@ -32,3 +32,12 @@ "Parameters": {

},
"Result": {}
"Result": {},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}
},

@@ -35,0 +44,0 @@ "required": ["Type"],

@@ -13,2 +13,6 @@ {

},
"asl_result_path": {
"type": ["string", "null"],
"format": "asl_result_path"
},
"_payload_template_object": {

@@ -15,0 +19,0 @@ "type": "object",

@@ -27,2 +27,5 @@ {

"minimum": 0
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -29,0 +32,0 @@ },

@@ -18,2 +18,8 @@ {

"$ref": "paths.json#/definitions/asl_path"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -20,0 +26,0 @@ },

@@ -54,3 +54,3 @@ {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
},

@@ -99,3 +99,3 @@ "Retry": {

"ResultPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
"$ref": "paths.json#/definitions/asl_result_path"
}

@@ -128,2 +128,14 @@ },

"$ref": "paths.json#/definitions/asl_payload_template"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"Arguments": {
"$ref": "jsonata.json#/definitions/arguments"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -130,0 +142,0 @@ },

@@ -37,2 +37,11 @@ {

"$ref": "paths.json#/definitions/asl_ref_path"
},
"Output": {
"$ref": "jsonata.json#/definitions/output"
},
"Assign": {
"$ref": "jsonata.json#/definitions/assign"
},
"QueryLanguage": {
"$ref": "jsonata.json#/definitions/queryLanguage"
}

@@ -39,0 +48,0 @@ },

export type State = Record<string, unknown>;
export type States = Record<string, State>;
export type StateMachine = {
QueryLanguage?: string | null;
States: States;

@@ -27,2 +28,3 @@ };

FailErrorProperty = "FAIL_ERROR_PROPERTY",
QueryLanguageFieldError = "QUERY_LANGUAGE_FIELD",
}

@@ -29,0 +31,0 @@ export type StateMachineError = {

@@ -24,4 +24,6 @@ import { ErrorObject } from "ajv";

IsWait,
None,
stateChecks,
} from "./checks/state-checks";
import { StateEntry } from "./checks/get-states";

@@ -41,2 +43,16 @@ const DefaultOptions: ValidationOptions = {

} {
// A state machine's query language defaults to JSONPath.
// The interpreter MUST support JSONPath and JSONata, and
// MAY support others.
const defaultQueryLanguage = definition.QueryLanguage ?? "JSONPath";
const IsJsonPath = ({ state }: StateEntry): boolean => {
const queryLanguage = state.QueryLanguage ?? defaultQueryLanguage;
return queryLanguage === "JSONPath";
};
const IsJsonNata = ({ state }: StateEntry): boolean => {
const queryLanguage = state.QueryLanguage ?? defaultQueryLanguage;
return queryLanguage === "JSONata";
};
const options = opts ?? DefaultOptions;

@@ -167,2 +183,32 @@ const errors = jsonSchemaErrors(definition, options);

},
{
filter: IsJsonNata,
checker: None({
props: [
"InputPath",
"OutputPath",
"ResultPath",
"Parameters",
"ResultSelector",
],
errorCode: StateMachineErrorCode.QueryLanguageFieldError,
}),
},
{
filter: IsJsonPath,
checker: None({
props: ["Arguments", "Output"],
errorCode: StateMachineErrorCode.QueryLanguageFieldError,
}),
},
{
filter: (entry) => {
return IsMap(entry) && IsJsonPath(entry);
},
checker: None({
props: ["Arguments"],
path: "$.ItemReader",
errorCode: StateMachineErrorCode.QueryLanguageFieldError,
}),
},
])

@@ -169,0 +215,0 @@ );

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