@dronedeploy/rocos-js-sdk 3.0.9 → 3.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. package/cjs/helpers/kscript/kscript.d.ts +7 -2
  2. package/cjs/helpers/kscript/kscript.js +23 -13
  3. package/cjs/helpers/kscript/nodes/Identifier.d.ts +1 -0
  4. package/cjs/helpers/kscript/nodes/Identifier.js +1 -0
  5. package/cjs/helpers/kscript/nodes/Literal.d.ts +1 -0
  6. package/cjs/helpers/kscript/nodes/Literal.js +4 -1
  7. package/cjs/helpers/kscript/nodes/Node.d.ts +6 -0
  8. package/cjs/helpers/kscript/nodes/Program.d.ts +1 -0
  9. package/cjs/helpers/kscript/nodes/Program.js +10 -4
  10. package/cjs/helpers/kscript/nodes/TemplateLiteral.d.ts +1 -0
  11. package/cjs/helpers/kscript/nodes/TemplateLiteral.js +8 -0
  12. package/cjs/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +1 -0
  13. package/cjs/helpers/kscript/nodes/expressions/ArrayExpression.js +11 -0
  14. package/cjs/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +1 -0
  15. package/cjs/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +8 -1
  16. package/cjs/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +6 -0
  17. package/cjs/helpers/kscript/nodes/expressions/BinaryExpression.js +39 -22
  18. package/cjs/helpers/kscript/nodes/expressions/CallExpression.d.ts +1 -0
  19. package/cjs/helpers/kscript/nodes/expressions/CallExpression.js +11 -1
  20. package/cjs/helpers/kscript/nodes/expressions/ChainExpression.d.ts +1 -0
  21. package/cjs/helpers/kscript/nodes/expressions/ChainExpression.js +1 -0
  22. package/cjs/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +1 -0
  23. package/cjs/helpers/kscript/nodes/expressions/ConditionalExpression.js +10 -0
  24. package/cjs/helpers/kscript/nodes/expressions/ExpressionStatement.d.ts +1 -0
  25. package/cjs/helpers/kscript/nodes/expressions/ExpressionStatement.js +8 -1
  26. package/cjs/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +2 -0
  27. package/cjs/helpers/kscript/nodes/expressions/LogicalExpression.js +11 -0
  28. package/cjs/helpers/kscript/nodes/expressions/MemberExpression.d.ts +1 -0
  29. package/cjs/helpers/kscript/nodes/expressions/MemberExpression.js +7 -0
  30. package/cjs/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +1 -0
  31. package/cjs/helpers/kscript/nodes/expressions/ObjectExpression.js +29 -0
  32. package/cjs/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +2 -0
  33. package/cjs/helpers/kscript/nodes/expressions/UnaryExpression.js +9 -0
  34. package/cjs/models/asset-storage/SyncIntegrations.d.ts +3 -3
  35. package/cjs/services/AssetStorageService.d.ts +3 -3
  36. package/cjs/services/MapService.d.ts +2 -1
  37. package/cjs/services/MapService.js +7 -2
  38. package/esm/helpers/kscript/kscript.d.ts +7 -2
  39. package/esm/helpers/kscript/kscript.js +21 -12
  40. package/esm/helpers/kscript/nodes/Identifier.d.ts +1 -0
  41. package/esm/helpers/kscript/nodes/Identifier.js +1 -0
  42. package/esm/helpers/kscript/nodes/Literal.d.ts +1 -0
  43. package/esm/helpers/kscript/nodes/Literal.js +4 -1
  44. package/esm/helpers/kscript/nodes/Node.d.ts +6 -0
  45. package/esm/helpers/kscript/nodes/Program.d.ts +1 -0
  46. package/esm/helpers/kscript/nodes/Program.js +10 -4
  47. package/esm/helpers/kscript/nodes/TemplateLiteral.d.ts +1 -0
  48. package/esm/helpers/kscript/nodes/TemplateLiteral.js +8 -0
  49. package/esm/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +1 -0
  50. package/esm/helpers/kscript/nodes/expressions/ArrayExpression.js +11 -0
  51. package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +1 -0
  52. package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +8 -1
  53. package/esm/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +6 -0
  54. package/esm/helpers/kscript/nodes/expressions/BinaryExpression.js +41 -23
  55. package/esm/helpers/kscript/nodes/expressions/CallExpression.d.ts +1 -0
  56. package/esm/helpers/kscript/nodes/expressions/CallExpression.js +11 -1
  57. package/esm/helpers/kscript/nodes/expressions/ChainExpression.d.ts +1 -0
  58. package/esm/helpers/kscript/nodes/expressions/ChainExpression.js +1 -0
  59. package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +1 -0
  60. package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.js +10 -0
  61. package/esm/helpers/kscript/nodes/expressions/ExpressionStatement.d.ts +1 -0
  62. package/esm/helpers/kscript/nodes/expressions/ExpressionStatement.js +8 -1
  63. package/esm/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +2 -0
  64. package/esm/helpers/kscript/nodes/expressions/LogicalExpression.js +13 -1
  65. package/esm/helpers/kscript/nodes/expressions/MemberExpression.d.ts +1 -0
  66. package/esm/helpers/kscript/nodes/expressions/MemberExpression.js +7 -0
  67. package/esm/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +1 -0
  68. package/esm/helpers/kscript/nodes/expressions/ObjectExpression.js +29 -0
  69. package/esm/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +2 -0
  70. package/esm/helpers/kscript/nodes/expressions/UnaryExpression.js +11 -1
  71. package/esm/models/asset-storage/SyncIntegrations.d.ts +3 -3
  72. package/esm/services/AssetStorageService.d.ts +3 -3
  73. package/esm/services/MapService.d.ts +2 -1
  74. package/esm/services/MapService.js +7 -2
  75. package/package.json +1 -1
@@ -1,6 +1,11 @@
1
1
  import { ContextOptions, PrototypeWhitelist, Scope } from './Context';
2
2
  import { Node } from './nodes';
3
- export declare function execute(code: string, scope?: Scope, options?: ContextOptions): unknown;
4
- export declare function compile(code: string, scope?: Scope, options?: ContextOptions): Node;
3
+ export declare const compile: (code: string, scope?: Scope, options?: ContextOptions) => Node;
4
+ /** Throws an error if the code uses an invalid node.
5
+ *
6
+ * This does not check that the code will run without errors, only that the nodes used are allowed.
7
+ **/
8
+ export declare const validate: (code: string, options?: ContextOptions) => void;
9
+ export declare const execute: (code: string, scope?: Scope, options?: ContextOptions) => unknown;
5
10
  export declare const SAFE_GLOBALS: Map<string, unknown>;
6
11
  export declare const SAFE_PROTOTYPES: PrototypeWhitelist;
@@ -3,36 +3,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SAFE_PROTOTYPES = exports.SAFE_GLOBALS = exports.compile = exports.execute = void 0;
6
+ exports.SAFE_PROTOTYPES = exports.SAFE_GLOBALS = exports.execute = exports.validate = exports.compile = void 0;
7
7
  const Context_1 = __importDefault(require("./Context"));
8
8
  const acorn_1 = require("acorn");
9
9
  const utils_1 = require("./utils");
10
- function execute(code, scope, options) {
11
- return compile(code, scope, options).run();
12
- }
13
- exports.execute = execute;
14
- function compile(code, scope, options) {
15
- let program;
10
+ const parse = (code) => {
16
11
  try {
17
12
  // we add the brackets to ensure that object literals are parsed correctly
18
- program = (0, acorn_1.parse)(`(${code})`, { ecmaVersion: 2020, sourceType: 'script' });
13
+ // e.g. `{ a: 1 }` is not a valid statement, but `({ a: 1 })` is
14
+ return (0, acorn_1.parse)(`(${code})`, { ecmaVersion: 2020, sourceType: 'script' });
19
15
  }
20
16
  catch (error) {
21
17
  if (error instanceof SyntaxError) {
22
18
  // fallback to non-wrapped code for edge cases where the brackets cause issues
23
- program = (0, acorn_1.parse)(`${code}`, { ecmaVersion: 2020, sourceType: 'script' });
24
- }
25
- else {
26
- throw error;
19
+ // e.g. `if (a) 2; else 4;` will throw a syntax error if wrapped in brackets
20
+ return (0, acorn_1.parse)(`${code}`, { ecmaVersion: 2020, sourceType: 'script' });
27
21
  }
22
+ throw error;
28
23
  }
24
+ };
25
+ const compile = (code, scope, options) => {
26
+ const program = parse(code);
29
27
  const context = new Context_1.default(scope ?? exports.SAFE_GLOBALS, {
30
28
  prototypeWhitelist: exports.SAFE_PROTOTYPES,
31
29
  ...options,
32
30
  });
33
31
  return (0, utils_1.construct)(program, context);
34
- }
32
+ };
35
33
  exports.compile = compile;
34
+ /** Throws an error if the code uses an invalid node.
35
+ *
36
+ * This does not check that the code will run without errors, only that the nodes used are allowed.
37
+ **/
38
+ const validate = (code, options) => {
39
+ (0, exports.compile)(code, undefined, options).validate(true);
40
+ };
41
+ exports.validate = validate;
42
+ const execute = (code, scope, options) => {
43
+ return (0, exports.compile)(code, scope, options).run();
44
+ };
45
+ exports.execute = execute;
36
46
  exports.SAFE_GLOBALS = new Map(Object.entries({
37
47
  console: {
38
48
  debug: console.debug,
@@ -8,5 +8,6 @@ import Node from './Node';
8
8
  */
9
9
  export default class IdentifierNode extends Node<Identifier> {
10
10
  constructor(node: AnyNode, context: Context);
11
+ validate(): void;
11
12
  run(): unknown;
12
13
  }
@@ -13,6 +13,7 @@ class IdentifierNode extends Node_1.default {
13
13
  constructor(node, context) {
14
14
  super(node, context, 'Identifier');
15
15
  }
16
+ validate() { }
16
17
  run() {
17
18
  return this.scope.get(this.node.name);
18
19
  }
@@ -7,5 +7,6 @@ import Node from './Node';
7
7
  */
8
8
  export default class LiteralNode extends Node<Literal> {
9
9
  constructor(node: AnyNode, context: Context);
10
+ validate(): void;
10
11
  run(): unknown;
11
12
  }
@@ -12,10 +12,13 @@ class LiteralNode extends Node_1.default {
12
12
  constructor(node, context) {
13
13
  super(node, context, 'Literal');
14
14
  }
15
- run() {
15
+ validate() {
16
16
  if (this.node.bigint) {
17
17
  throw new Error('BigInts are not supported');
18
18
  }
19
+ }
20
+ run() {
21
+ this.validate();
19
22
  return this.node.value;
20
23
  }
21
24
  }
@@ -5,5 +5,11 @@ export default abstract class Node<T extends AnyNode = AnyNode> {
5
5
  protected node: T;
6
6
  protected scope: Context['scope'];
7
7
  protected constructor(node: AnyNode, context: Context, expectedType: T['type'] | T['type'][]);
8
+ /** Runs the node. */
8
9
  abstract run(): unknown;
10
+ /** Validates the node. If the node is invalid, an error is thrown.
11
+ *
12
+ * if `validateChildren` is true, the children of the node will also be validated.
13
+ */
14
+ abstract validate(validateChildren: boolean): void;
9
15
  }
@@ -7,5 +7,6 @@ import Node from './Node';
7
7
  */
8
8
  export default class ProgramNode extends Node<Program> {
9
9
  constructor(node: AnyNode, scope: Context);
10
+ validate(validateChildren?: boolean): void;
10
11
  run(): unknown;
11
12
  }
@@ -13,12 +13,18 @@ class ProgramNode extends Node_1.default {
13
13
  constructor(node, scope) {
14
14
  super(node, scope, 'Program');
15
15
  }
16
- run() {
17
- const children = this.node.body;
18
- if (children.length !== 1) {
16
+ validate(validateChildren = false) {
17
+ if (this.node.body.length !== 1) {
19
18
  throw new Error('Only a single statement is supported in the sandbox');
20
19
  }
21
- return (0, utils_1.construct)(children[0], this.context).run();
20
+ if (!validateChildren) {
21
+ return;
22
+ }
23
+ (0, utils_1.construct)(this.node.body[0], this.context).validate(true);
24
+ }
25
+ run() {
26
+ this.validate();
27
+ return (0, utils_1.construct)(this.node.body[0], this.context).run();
22
28
  }
23
29
  }
24
30
  exports.default = ProgramNode;
@@ -19,5 +19,6 @@ import Node from './Node';
19
19
  */
20
20
  export default class TemplateLiteralNode extends Node<TemplateLiteral> {
21
21
  constructor(node: AnyNode, scope: Context);
22
+ validate(validateChildren?: boolean): void;
22
23
  run(): unknown;
23
24
  }
@@ -25,6 +25,14 @@ class TemplateLiteralNode extends Node_1.default {
25
25
  constructor(node, scope) {
26
26
  super(node, scope, 'TemplateLiteral');
27
27
  }
28
+ validate(validateChildren = false) {
29
+ if (!validateChildren) {
30
+ return;
31
+ }
32
+ for (const expression of this.node.expressions) {
33
+ (0, utils_1.construct)(expression, this.context).validate(true);
34
+ }
35
+ }
28
36
  run() {
29
37
  return this.node.quasis.reduce((acc, quasi, i) => {
30
38
  const expression = this.node.expressions[i] ? (0, utils_1.construct)(this.node.expressions[i], this.context).run() : '';
@@ -3,5 +3,6 @@ import type Context from '../../Context';
3
3
  import Node from '../Node';
4
4
  export default class ArrayExpressionNode extends Node<ArrayExpression> {
5
5
  constructor(node: AnyNode, context: Context);
6
+ validate(validateChildren?: boolean): void;
6
7
  run(): unknown;
7
8
  }
@@ -9,6 +9,17 @@ class ArrayExpressionNode extends Node_1.default {
9
9
  constructor(node, context) {
10
10
  super(node, context, 'ArrayExpression');
11
11
  }
12
+ validate(validateChildren = false) {
13
+ if (!validateChildren) {
14
+ return;
15
+ }
16
+ for (const element of this.node.elements) {
17
+ if (element === null) {
18
+ continue;
19
+ }
20
+ (0, utils_1.construct)(element, this.context).validate(true);
21
+ }
22
+ }
12
23
  run() {
13
24
  const array = [];
14
25
  for (const element of this.node.elements) {
@@ -10,5 +10,6 @@ import Node from '../Node';
10
10
  export default class ArrowFunctionExpressionNode extends Node<ArrowFunctionExpression> {
11
11
  private readonly params;
12
12
  constructor(node: AnyNode, context: Context);
13
+ validate(validateChildren?: boolean): void;
13
14
  run(): unknown;
14
15
  }
@@ -19,13 +19,20 @@ class ArrowFunctionExpressionNode extends Node_1.default {
19
19
  }
20
20
  this.params = this.node.params;
21
21
  }
22
- run() {
22
+ validate(validateChildren = false) {
23
23
  if (!this.context.isFunctionCallAllowed)
24
24
  throw new Error('functions are not allowed');
25
25
  if (!this.node.expression)
26
26
  throw new Error('functions must be an expression');
27
27
  if (this.node.async)
28
28
  throw new Error('async functions are not supported');
29
+ if (!validateChildren) {
30
+ return;
31
+ }
32
+ (0, utils_1.construct)(this.node.body, this.context).validate(true);
33
+ }
34
+ run() {
35
+ this.validate();
29
36
  return (...args) => {
30
37
  const scope = new Map();
31
38
  for (const param of this.params) {
@@ -6,7 +6,13 @@ import Node from '../Node';
6
6
  * e.g. `1 + 2`, `a === b`, `c < d`
7
7
  */
8
8
  export default class BinaryExpressionNode extends Node<BinaryExpression> {
9
+ private static readonly EQUALITY_OPERATORS;
10
+ private static readonly COMPARISON_OPERATORS;
11
+ private static readonly ARITHMETIC_OPERATORS;
12
+ private static readonly IN_OPERATOR;
13
+ private static readonly SUPPORTED_OPERATORS;
9
14
  constructor(node: AnyNode, context: Context);
15
+ validate(validateChildren?: boolean): void;
10
16
  run(): unknown;
11
17
  private operate;
12
18
  private arithmetic;
@@ -13,35 +13,35 @@ class BinaryExpressionNode extends Node_1.default {
13
13
  constructor(node, context) {
14
14
  super(node, context, 'BinaryExpression');
15
15
  }
16
+ validate(validateChildren = false) {
17
+ if (!BinaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
18
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
19
+ }
20
+ if (!validateChildren) {
21
+ return;
22
+ }
23
+ (0, utils_1.construct)(this.node.left, this.context).validate(true);
24
+ (0, utils_1.construct)(this.node.right, this.context).validate(true);
25
+ }
16
26
  run() {
17
27
  const left = (0, utils_1.construct)(this.node.left, this.context).run();
18
28
  const right = (0, utils_1.construct)(this.node.right, this.context).run();
19
29
  return this.operate(left, right);
20
30
  }
21
31
  operate(left, right) {
22
- switch (this.node.operator) {
23
- case '==':
24
- case '!=':
25
- case '===':
26
- case '!==':
27
- return this.equality(this.node.operator, left, right);
28
- case '<':
29
- case '<=':
30
- case '>':
31
- case '>=':
32
- return this.comparison(this.node.operator, left, right);
33
- case 'in':
34
- return this.checkIn(left, right);
35
- case '**':
36
- case '+':
37
- case '-':
38
- case '*':
39
- case '/':
40
- case '%':
41
- return this.arithmetic(this.node.operator, left, right);
42
- default:
43
- throw new Error(`Unsupported operator: ${this.node.operator}`);
32
+ if (BinaryExpressionNode.EQUALITY_OPERATORS.has(this.node.operator)) {
33
+ return this.equality(this.node.operator, left, right);
34
+ }
35
+ if (BinaryExpressionNode.COMPARISON_OPERATORS.has(this.node.operator)) {
36
+ return this.comparison(this.node.operator, left, right);
37
+ }
38
+ if (BinaryExpressionNode.ARITHMETIC_OPERATORS.has(this.node.operator)) {
39
+ return this.arithmetic(this.node.operator, left, right);
40
+ }
41
+ if (this.node.operator === BinaryExpressionNode.IN_OPERATOR) {
42
+ return this.checkIn(left, right);
44
43
  }
44
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
45
45
  }
46
46
  arithmetic(operator, left, right) {
47
47
  if (operator === '+' && (typeof left === 'string' || typeof right === 'string')) {
@@ -101,4 +101,21 @@ class BinaryExpressionNode extends Node_1.default {
101
101
  return right.includes(left);
102
102
  }
103
103
  }
104
+ BinaryExpressionNode.EQUALITY_OPERATORS = new Set(['==', '!=', '===', '!==']);
105
+ BinaryExpressionNode.COMPARISON_OPERATORS = new Set(['<', '<=', '>', '>=']);
106
+ BinaryExpressionNode.ARITHMETIC_OPERATORS = new Set([
107
+ '+',
108
+ '-',
109
+ '*',
110
+ '/',
111
+ '%',
112
+ '**',
113
+ ]);
114
+ BinaryExpressionNode.IN_OPERATOR = 'in';
115
+ BinaryExpressionNode.SUPPORTED_OPERATORS = new Set([
116
+ ...BinaryExpressionNode.EQUALITY_OPERATORS,
117
+ ...BinaryExpressionNode.COMPARISON_OPERATORS,
118
+ ...BinaryExpressionNode.ARITHMETIC_OPERATORS,
119
+ BinaryExpressionNode.IN_OPERATOR,
120
+ ]);
104
121
  exports.default = BinaryExpressionNode;
@@ -3,6 +3,7 @@ import Context from '../../Context';
3
3
  import Node from '../Node';
4
4
  export default class CallExpressionNode extends Node<CallExpression> {
5
5
  constructor(node: AnyNode, context: Context);
6
+ validate(validateChildren?: boolean): void;
6
7
  run(): unknown;
7
8
  private spreadArgs;
8
9
  }
@@ -9,9 +9,19 @@ class CallExpressionNode extends Node_1.default {
9
9
  constructor(node, context) {
10
10
  super(node, context, 'CallExpression');
11
11
  }
12
- run() {
12
+ validate(validateChildren = false) {
13
13
  if (!this.context.isFunctionCallAllowed)
14
14
  throw new Error('Function calls are not allowed');
15
+ if (!validateChildren) {
16
+ return;
17
+ }
18
+ (0, utils_1.construct)(this.node.callee, this.context).validate(true);
19
+ for (const arg of this.node.arguments) {
20
+ (0, utils_1.construct)(arg, this.context).validate(true);
21
+ }
22
+ }
23
+ run() {
24
+ this.validate();
15
25
  const callee = (0, utils_1.construct)(this.node.callee, this.context).run();
16
26
  let thisArg = {};
17
27
  if (this.node.callee.type === 'MemberExpression') {
@@ -12,5 +12,6 @@ import Node from '../Node';
12
12
  */
13
13
  export default class ExpressionStatementNode extends Node<ChainExpression> {
14
14
  constructor(node: AnyNode, context: Context);
15
+ validate(): void;
15
16
  run(): unknown;
16
17
  }
@@ -18,6 +18,7 @@ class ExpressionStatementNode extends Node_1.default {
18
18
  constructor(node, context) {
19
19
  super(node, context, 'ChainExpression');
20
20
  }
21
+ validate() { }
21
22
  run() {
22
23
  return (0, utils_1.construct)(this.node.expression, this.context).run();
23
24
  }
@@ -10,5 +10,6 @@ import Node from '../Node';
10
10
  */
11
11
  export default class ConditionalExpressionNode extends Node<IfStatement | ConditionalExpression> {
12
12
  constructor(node: AnyNode, context: Context);
13
+ validate(validateChildren: boolean): void;
13
14
  run(): unknown;
14
15
  }
@@ -16,6 +16,16 @@ class ConditionalExpressionNode extends Node_1.default {
16
16
  constructor(node, context) {
17
17
  super(node, context, ['ConditionalExpression', 'IfStatement']);
18
18
  }
19
+ validate(validateChildren) {
20
+ if (!validateChildren) {
21
+ return;
22
+ }
23
+ (0, utils_1.construct)(this.node.test, this.context).validate(true);
24
+ (0, utils_1.construct)(this.node.consequent, this.context).validate(true);
25
+ if (this.node.alternate !== null && this.node.alternate !== undefined) {
26
+ (0, utils_1.construct)(this.node.alternate, this.context).validate(true);
27
+ }
28
+ }
19
29
  run() {
20
30
  const test = (0, utils_1.construct)(this.node.test, this.context).run();
21
31
  if (test) {
@@ -3,5 +3,6 @@ import Context from '../../Context';
3
3
  import Node from '../Node';
4
4
  export default class ExpressionStatementNode extends Node<ExpressionStatement> {
5
5
  constructor(node: AnyNode, context: Context);
6
+ validate(validateChildren?: boolean): void;
6
7
  run(): unknown;
7
8
  }
@@ -9,9 +9,16 @@ class ExpressionStatementNode extends Node_1.default {
9
9
  constructor(node, context) {
10
10
  super(node, context, 'ExpressionStatement');
11
11
  }
12
- run() {
12
+ validate(validateChildren = false) {
13
13
  if (this.node.directive)
14
14
  throw new Error('Directives are not supported');
15
+ if (!validateChildren) {
16
+ return;
17
+ }
18
+ (0, utils_1.construct)(this.node.expression, this.context).validate(true);
19
+ }
20
+ run() {
21
+ this.validate();
15
22
  return (0, utils_1.construct)(this.node.expression, this.context).run();
16
23
  }
17
24
  }
@@ -2,7 +2,9 @@ import { AnyNode, LogicalExpression } from 'acorn';
2
2
  import Context from '../../Context';
3
3
  import Node from '../Node';
4
4
  export default class BinaryExpressionNode extends Node<LogicalExpression> {
5
+ private static readonly SUPPORTED_OPERATORS;
5
6
  constructor(node: AnyNode, context: Context);
7
+ validate(validateChildren: boolean): void;
6
8
  run(): unknown;
7
9
  /** Try and skip evaluating the right operand */
8
10
  private shortCircuit;
@@ -9,6 +9,16 @@ class BinaryExpressionNode extends Node_1.default {
9
9
  constructor(node, context) {
10
10
  super(node, context, 'LogicalExpression');
11
11
  }
12
+ validate(validateChildren) {
13
+ if (!BinaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
14
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
15
+ }
16
+ if (!validateChildren) {
17
+ return;
18
+ }
19
+ (0, utils_1.construct)(this.node.left, this.context).validate(true);
20
+ (0, utils_1.construct)(this.node.right, this.context).validate(true);
21
+ }
12
22
  run() {
13
23
  const left = (0, utils_1.construct)(this.node.left, this.context).run();
14
24
  const shortCircuit = this.shortCircuit(left);
@@ -44,4 +54,5 @@ class BinaryExpressionNode extends Node_1.default {
44
54
  }
45
55
  }
46
56
  }
57
+ BinaryExpressionNode.SUPPORTED_OPERATORS = new Set(['||', '&&', '??']);
47
58
  exports.default = BinaryExpressionNode;
@@ -22,6 +22,7 @@ import Node from '../Node';
22
22
  */
23
23
  export default class MemberExpressionNode extends Node<MemberExpression> {
24
24
  constructor(node: AnyNode, context: Context);
25
+ validate(validateChildren?: boolean): void;
25
26
  run(): unknown;
26
27
  /** Returns the name of the property being accessed.
27
28
  *
@@ -28,6 +28,13 @@ class MemberExpressionNode extends Node_1.default {
28
28
  constructor(node, context) {
29
29
  super(node, context, 'MemberExpression');
30
30
  }
31
+ validate(validateChildren = false) {
32
+ if (!validateChildren) {
33
+ return;
34
+ }
35
+ (0, utils_1.construct)(this.node.object, this.context).validate(true);
36
+ (0, utils_1.construct)(this.node.property, this.context).validate(true);
37
+ }
31
38
  run() {
32
39
  const object = (0, utils_1.construct)(this.node.object, this.context).run();
33
40
  if (object === null || object === undefined) {
@@ -3,6 +3,7 @@ import type Context from '../../Context';
3
3
  import Node from '../Node';
4
4
  export default class ObjectExpressionNode extends Node<ObjectExpression> {
5
5
  constructor(node: AnyNode, context: Context);
6
+ validate(validateChildren: boolean): void;
6
7
  run(): unknown;
7
8
  private addProperty;
8
9
  private spreadProperty;
@@ -9,6 +9,35 @@ class ObjectExpressionNode extends Node_1.default {
9
9
  constructor(node, context) {
10
10
  super(node, context, 'ObjectExpression');
11
11
  }
12
+ validate(validateChildren) {
13
+ for (const property of this.node.properties) {
14
+ // SpreadElements do not need to be validated - they only have a single argument
15
+ if (property.type === 'SpreadElement') {
16
+ continue;
17
+ }
18
+ if (property.kind !== 'init') {
19
+ // do not support getters or setters
20
+ throw new Error('Only init properties are supported');
21
+ }
22
+ if (!property.computed) {
23
+ // ensure that the key is valid
24
+ this.getStaticKey(property.key);
25
+ }
26
+ }
27
+ if (!validateChildren) {
28
+ return;
29
+ }
30
+ for (const property of this.node.properties) {
31
+ if (property.type === 'SpreadElement') {
32
+ (0, utils_1.construct)(property.argument, this.context).validate(true);
33
+ continue;
34
+ }
35
+ if (property.computed) {
36
+ (0, utils_1.construct)(property.key, this.context).validate(true);
37
+ }
38
+ (0, utils_1.construct)(property.value, this.context).validate(true);
39
+ }
40
+ }
12
41
  run() {
13
42
  const object = {};
14
43
  for (const property of this.node.properties) {
@@ -6,7 +6,9 @@ import Node from '../Node';
6
6
  * e.g. `+1`, `-2`, `!true`, `typeof x`
7
7
  */
8
8
  export default class UnaryExpressionNode extends Node<UnaryExpression> {
9
+ private static readonly SUPPORTED_OPERATORS;
9
10
  constructor(node: AnyNode, context: Context);
11
+ validate(validateChildren: boolean): void;
10
12
  run(): unknown;
11
13
  private arithmetic;
12
14
  }
@@ -13,6 +13,14 @@ class UnaryExpressionNode extends Node_1.default {
13
13
  constructor(node, context) {
14
14
  super(node, context, 'UnaryExpression');
15
15
  }
16
+ validate(validateChildren) {
17
+ if (!UnaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
18
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
19
+ }
20
+ if (validateChildren) {
21
+ (0, utils_1.construct)(this.node.argument, this.context).validate(true);
22
+ }
23
+ }
16
24
  run() {
17
25
  const argument = (0, utils_1.construct)(this.node.argument, this.context).run();
18
26
  switch (this.node.operator) {
@@ -41,4 +49,5 @@ class UnaryExpressionNode extends Node_1.default {
41
49
  }
42
50
  }
43
51
  }
52
+ UnaryExpressionNode.SUPPORTED_OPERATORS = new Set(['+', '-', '!', 'typeof']);
44
53
  exports.default = UnaryExpressionNode;
@@ -12,9 +12,9 @@ export interface AssetSyncDefinitionModel {
12
12
  export interface AssetSyncDefinitionOverrideModel extends AssetSyncDefinitionModel {
13
13
  _isOverridden: boolean;
14
14
  }
15
- export interface AssetSyncDefinitionsModel {
16
- items: AssetSyncDefinitionModel[];
17
- profileOverriddenItems?: AssetSyncDefinitionOverrideModel[];
15
+ export interface AssetSyncDefinitionsModel<I extends AssetSyncDefinitionModel = AssetSyncDefinitionOverrideModel> {
16
+ items: I[];
17
+ profileOverriddenItems?: AssetSyncDefinitionModel[];
18
18
  }
19
19
  export interface AssetSyncIntegrationProviderModel {
20
20
  provider: string;
@@ -1,4 +1,4 @@
1
- import { AssetItemModel, AssetItemWithObservationsModel, AssetSyncDefinitionsModel, AssetSyncIntegrationModel, AssetSyncIntegrationProviderModel, CreateAssetSyncIntegrationModel, IBaseService, IRocosSDKConfig, RocosError } from '../models';
1
+ import { AssetItemModel, AssetItemWithObservationsModel, AssetSyncDefinitionModel, AssetSyncDefinitionsModel, AssetSyncIntegrationModel, AssetSyncIntegrationProviderModel, CreateAssetSyncIntegrationModel, IBaseService, IRocosSDKConfig, RocosError } from '../models';
2
2
  import { BaseServiceAbstract } from './BaseServiceAbstract';
3
3
  export declare class AssetStorageService extends BaseServiceAbstract implements IBaseService {
4
4
  constructor(config: IRocosSDKConfig);
@@ -92,7 +92,7 @@ export declare class AssetStorageService extends BaseServiceAbstract implements
92
92
  * @param definition
93
93
  * @param syncNow - Sync configured paths immediately
94
94
  */
95
- setRobotSyncDefinitions(projectId: string, callsign: string, definition: AssetSyncDefinitionsModel, syncNow?: boolean): Promise<AssetSyncDefinitionsModel>;
95
+ setRobotSyncDefinitions(projectId: string, callsign: string, definition: AssetSyncDefinitionsModel<AssetSyncDefinitionModel>, syncNow?: boolean): Promise<AssetSyncDefinitionsModel>;
96
96
  /**
97
97
  * Get Robot Sync Definitions
98
98
  * @param projectId
@@ -105,7 +105,7 @@ export declare class AssetStorageService extends BaseServiceAbstract implements
105
105
  * @param profileId
106
106
  * @param definition
107
107
  */
108
- setProfileSyncDefinitions(projectId: string, profileId: string, definition: AssetSyncDefinitionsModel): Promise<AssetSyncDefinitionsModel>;
108
+ setProfileSyncDefinitions(projectId: string, profileId: string, definition: Omit<AssetSyncDefinitionsModel<AssetSyncDefinitionModel>, 'profileOverriddenItems'>): Promise<AssetSyncDefinitionsModel>;
109
109
  /**
110
110
  * Get Profile Sync Definitions
111
111
  * @param projectId
@@ -22,9 +22,10 @@ export declare class MapService extends BaseServiceAbstract implements IBaseServ
22
22
  *
23
23
  * @param projectId Project ID
24
24
  * @param callsign Robot callsign
25
+ * @param includeSystem Include system maps
25
26
  * @returns All maps in the cloud
26
27
  */
27
- list(projectId: string, callsign: string): Promise<Map[]>;
28
+ list(projectId: string, callsign: string, includeSystem: boolean): Promise<Map[]>;
28
29
  /** List maps to be deployed to a callsign
29
30
  *
30
31
  * @param projectId