@dronedeploy/rocos-js-sdk 3.0.10 → 3.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) 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/esm/helpers/kscript/kscript.d.ts +7 -2
  37. package/esm/helpers/kscript/kscript.js +21 -12
  38. package/esm/helpers/kscript/nodes/Identifier.d.ts +1 -0
  39. package/esm/helpers/kscript/nodes/Identifier.js +1 -0
  40. package/esm/helpers/kscript/nodes/Literal.d.ts +1 -0
  41. package/esm/helpers/kscript/nodes/Literal.js +4 -1
  42. package/esm/helpers/kscript/nodes/Node.d.ts +6 -0
  43. package/esm/helpers/kscript/nodes/Program.d.ts +1 -0
  44. package/esm/helpers/kscript/nodes/Program.js +10 -4
  45. package/esm/helpers/kscript/nodes/TemplateLiteral.d.ts +1 -0
  46. package/esm/helpers/kscript/nodes/TemplateLiteral.js +8 -0
  47. package/esm/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +1 -0
  48. package/esm/helpers/kscript/nodes/expressions/ArrayExpression.js +11 -0
  49. package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +1 -0
  50. package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +8 -1
  51. package/esm/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +6 -0
  52. package/esm/helpers/kscript/nodes/expressions/BinaryExpression.js +41 -23
  53. package/esm/helpers/kscript/nodes/expressions/CallExpression.d.ts +1 -0
  54. package/esm/helpers/kscript/nodes/expressions/CallExpression.js +11 -1
  55. package/esm/helpers/kscript/nodes/expressions/ChainExpression.d.ts +1 -0
  56. package/esm/helpers/kscript/nodes/expressions/ChainExpression.js +1 -0
  57. package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +1 -0
  58. package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.js +10 -0
  59. package/esm/helpers/kscript/nodes/expressions/ExpressionStatement.d.ts +1 -0
  60. package/esm/helpers/kscript/nodes/expressions/ExpressionStatement.js +8 -1
  61. package/esm/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +2 -0
  62. package/esm/helpers/kscript/nodes/expressions/LogicalExpression.js +13 -1
  63. package/esm/helpers/kscript/nodes/expressions/MemberExpression.d.ts +1 -0
  64. package/esm/helpers/kscript/nodes/expressions/MemberExpression.js +7 -0
  65. package/esm/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +1 -0
  66. package/esm/helpers/kscript/nodes/expressions/ObjectExpression.js +29 -0
  67. package/esm/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +2 -0
  68. package/esm/helpers/kscript/nodes/expressions/UnaryExpression.js +11 -1
  69. package/esm/models/asset-storage/SyncIntegrations.d.ts +3 -3
  70. package/esm/services/AssetStorageService.d.ts +3 -3
  71. package/package.json +1 -1
@@ -1,30 +1,39 @@
1
1
  import Context from './Context';
2
- import { parse } from 'acorn';
2
+ import { parse as acorn } from 'acorn';
3
3
  import { construct } from './utils';
4
- export function execute(code, scope, options) {
5
- return compile(code, scope, options).run();
6
- }
7
- export function compile(code, scope, options) {
8
- let program;
4
+ const parse = (code) => {
9
5
  try {
10
6
  // we add the brackets to ensure that object literals are parsed correctly
11
- program = parse(`(${code})`, { ecmaVersion: 2020, sourceType: 'script' });
7
+ // e.g. `{ a: 1 }` is not a valid statement, but `({ a: 1 })` is
8
+ return acorn(`(${code})`, { ecmaVersion: 2020, sourceType: 'script' });
12
9
  }
13
10
  catch (error) {
14
11
  if (error instanceof SyntaxError) {
15
12
  // fallback to non-wrapped code for edge cases where the brackets cause issues
16
- program = parse(`${code}`, { ecmaVersion: 2020, sourceType: 'script' });
17
- }
18
- else {
19
- throw error;
13
+ // e.g. `if (a) 2; else 4;` will throw a syntax error if wrapped in brackets
14
+ return acorn(`${code}`, { ecmaVersion: 2020, sourceType: 'script' });
20
15
  }
16
+ throw error;
21
17
  }
18
+ };
19
+ export const compile = (code, scope, options) => {
20
+ const program = parse(code);
22
21
  const context = new Context(scope ?? SAFE_GLOBALS, {
23
22
  prototypeWhitelist: SAFE_PROTOTYPES,
24
23
  ...options,
25
24
  });
26
25
  return construct(program, context);
27
- }
26
+ };
27
+ /** Throws an error if the code uses an invalid node.
28
+ *
29
+ * This does not check that the code will run without errors, only that the nodes used are allowed.
30
+ **/
31
+ export const validate = (code, options) => {
32
+ compile(code, undefined, options).validate(true);
33
+ };
34
+ export const execute = (code, scope, options) => {
35
+ return compile(code, scope, options).run();
36
+ };
28
37
  export const SAFE_GLOBALS = new Map(Object.entries({
29
38
  console: {
30
39
  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
  }
@@ -8,6 +8,7 @@ export default class IdentifierNode extends Node {
8
8
  constructor(node, context) {
9
9
  super(node, context, 'Identifier');
10
10
  }
11
+ validate() { }
11
12
  run() {
12
13
  return this.scope.get(this.node.name);
13
14
  }
@@ -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
  }
@@ -7,10 +7,13 @@ export default class LiteralNode extends Node {
7
7
  constructor(node, context) {
8
8
  super(node, context, 'Literal');
9
9
  }
10
- run() {
10
+ validate() {
11
11
  if (this.node.bigint) {
12
12
  throw new Error('BigInts are not supported');
13
13
  }
14
+ }
15
+ run() {
16
+ this.validate();
14
17
  return this.node.value;
15
18
  }
16
19
  }
@@ -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
  }
@@ -8,11 +8,17 @@ export default class ProgramNode extends Node {
8
8
  constructor(node, scope) {
9
9
  super(node, scope, 'Program');
10
10
  }
11
- run() {
12
- const children = this.node.body;
13
- if (children.length !== 1) {
11
+ validate(validateChildren = false) {
12
+ if (this.node.body.length !== 1) {
14
13
  throw new Error('Only a single statement is supported in the sandbox');
15
14
  }
16
- return construct(children[0], this.context).run();
15
+ if (!validateChildren) {
16
+ return;
17
+ }
18
+ construct(this.node.body[0], this.context).validate(true);
19
+ }
20
+ run() {
21
+ this.validate();
22
+ return construct(this.node.body[0], this.context).run();
17
23
  }
18
24
  }
@@ -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
  }
@@ -20,6 +20,14 @@ export default class TemplateLiteralNode extends Node {
20
20
  constructor(node, scope) {
21
21
  super(node, scope, 'TemplateLiteral');
22
22
  }
23
+ validate(validateChildren = false) {
24
+ if (!validateChildren) {
25
+ return;
26
+ }
27
+ for (const expression of this.node.expressions) {
28
+ construct(expression, this.context).validate(true);
29
+ }
30
+ }
23
31
  run() {
24
32
  return this.node.quasis.reduce((acc, quasi, i) => {
25
33
  const expression = this.node.expressions[i] ? 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
  }
@@ -4,6 +4,17 @@ export default class ArrayExpressionNode extends Node {
4
4
  constructor(node, context) {
5
5
  super(node, context, 'ArrayExpression');
6
6
  }
7
+ validate(validateChildren = false) {
8
+ if (!validateChildren) {
9
+ return;
10
+ }
11
+ for (const element of this.node.elements) {
12
+ if (element === null) {
13
+ continue;
14
+ }
15
+ construct(element, this.context).validate(true);
16
+ }
17
+ }
7
18
  run() {
8
19
  const array = [];
9
20
  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
  }
@@ -14,13 +14,20 @@ export default class ArrowFunctionExpressionNode extends Node {
14
14
  }
15
15
  this.params = this.node.params;
16
16
  }
17
- run() {
17
+ validate(validateChildren = false) {
18
18
  if (!this.context.isFunctionCallAllowed)
19
19
  throw new Error('functions are not allowed');
20
20
  if (!this.node.expression)
21
21
  throw new Error('functions must be an expression');
22
22
  if (this.node.async)
23
23
  throw new Error('async functions are not supported');
24
+ if (!validateChildren) {
25
+ return;
26
+ }
27
+ construct(this.node.body, this.context).validate(true);
28
+ }
29
+ run() {
30
+ this.validate();
24
31
  return (...args) => {
25
32
  const scope = new Map();
26
33
  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;
@@ -4,39 +4,39 @@ import { construct } from '../../utils';
4
4
  *
5
5
  * e.g. `1 + 2`, `a === b`, `c < d`
6
6
  */
7
- export default class BinaryExpressionNode extends Node {
7
+ class BinaryExpressionNode extends Node {
8
8
  constructor(node, context) {
9
9
  super(node, context, 'BinaryExpression');
10
10
  }
11
+ validate(validateChildren = false) {
12
+ if (!BinaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
13
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
14
+ }
15
+ if (!validateChildren) {
16
+ return;
17
+ }
18
+ construct(this.node.left, this.context).validate(true);
19
+ construct(this.node.right, this.context).validate(true);
20
+ }
11
21
  run() {
12
22
  const left = construct(this.node.left, this.context).run();
13
23
  const right = construct(this.node.right, this.context).run();
14
24
  return this.operate(left, right);
15
25
  }
16
26
  operate(left, right) {
17
- switch (this.node.operator) {
18
- case '==':
19
- case '!=':
20
- case '===':
21
- case '!==':
22
- return this.equality(this.node.operator, left, right);
23
- case '<':
24
- case '<=':
25
- case '>':
26
- case '>=':
27
- return this.comparison(this.node.operator, left, right);
28
- case 'in':
29
- return this.checkIn(left, right);
30
- case '**':
31
- case '+':
32
- case '-':
33
- case '*':
34
- case '/':
35
- case '%':
36
- return this.arithmetic(this.node.operator, left, right);
37
- default:
38
- throw new Error(`Unsupported operator: ${this.node.operator}`);
27
+ if (BinaryExpressionNode.EQUALITY_OPERATORS.has(this.node.operator)) {
28
+ return this.equality(this.node.operator, left, right);
29
+ }
30
+ if (BinaryExpressionNode.COMPARISON_OPERATORS.has(this.node.operator)) {
31
+ return this.comparison(this.node.operator, left, right);
32
+ }
33
+ if (BinaryExpressionNode.ARITHMETIC_OPERATORS.has(this.node.operator)) {
34
+ return this.arithmetic(this.node.operator, left, right);
35
+ }
36
+ if (this.node.operator === BinaryExpressionNode.IN_OPERATOR) {
37
+ return this.checkIn(left, right);
39
38
  }
39
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
40
40
  }
41
41
  arithmetic(operator, left, right) {
42
42
  if (operator === '+' && (typeof left === 'string' || typeof right === 'string')) {
@@ -96,3 +96,21 @@ export default class BinaryExpressionNode extends Node {
96
96
  return right.includes(left);
97
97
  }
98
98
  }
99
+ BinaryExpressionNode.EQUALITY_OPERATORS = new Set(['==', '!=', '===', '!==']);
100
+ BinaryExpressionNode.COMPARISON_OPERATORS = new Set(['<', '<=', '>', '>=']);
101
+ BinaryExpressionNode.ARITHMETIC_OPERATORS = new Set([
102
+ '+',
103
+ '-',
104
+ '*',
105
+ '/',
106
+ '%',
107
+ '**',
108
+ ]);
109
+ BinaryExpressionNode.IN_OPERATOR = 'in';
110
+ BinaryExpressionNode.SUPPORTED_OPERATORS = new Set([
111
+ ...BinaryExpressionNode.EQUALITY_OPERATORS,
112
+ ...BinaryExpressionNode.COMPARISON_OPERATORS,
113
+ ...BinaryExpressionNode.ARITHMETIC_OPERATORS,
114
+ BinaryExpressionNode.IN_OPERATOR,
115
+ ]);
116
+ export 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
  }
@@ -4,9 +4,19 @@ export default class CallExpressionNode extends Node {
4
4
  constructor(node, context) {
5
5
  super(node, context, 'CallExpression');
6
6
  }
7
- run() {
7
+ validate(validateChildren = false) {
8
8
  if (!this.context.isFunctionCallAllowed)
9
9
  throw new Error('Function calls are not allowed');
10
+ if (!validateChildren) {
11
+ return;
12
+ }
13
+ construct(this.node.callee, this.context).validate(true);
14
+ for (const arg of this.node.arguments) {
15
+ construct(arg, this.context).validate(true);
16
+ }
17
+ }
18
+ run() {
19
+ this.validate();
10
20
  const callee = construct(this.node.callee, this.context).run();
11
21
  let thisArg = {};
12
22
  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
  }
@@ -13,6 +13,7 @@ export default class ExpressionStatementNode extends Node {
13
13
  constructor(node, context) {
14
14
  super(node, context, 'ChainExpression');
15
15
  }
16
+ validate() { }
16
17
  run() {
17
18
  return construct(this.node.expression, this.context).run();
18
19
  }
@@ -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
  }
@@ -11,6 +11,16 @@ export default class ConditionalExpressionNode extends Node {
11
11
  constructor(node, context) {
12
12
  super(node, context, ['ConditionalExpression', 'IfStatement']);
13
13
  }
14
+ validate(validateChildren) {
15
+ if (!validateChildren) {
16
+ return;
17
+ }
18
+ construct(this.node.test, this.context).validate(true);
19
+ construct(this.node.consequent, this.context).validate(true);
20
+ if (this.node.alternate !== null && this.node.alternate !== undefined) {
21
+ construct(this.node.alternate, this.context).validate(true);
22
+ }
23
+ }
14
24
  run() {
15
25
  const test = construct(this.node.test, this.context).run();
16
26
  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
  }
@@ -4,9 +4,16 @@ export default class ExpressionStatementNode extends Node {
4
4
  constructor(node, context) {
5
5
  super(node, context, 'ExpressionStatement');
6
6
  }
7
- run() {
7
+ validate(validateChildren = false) {
8
8
  if (this.node.directive)
9
9
  throw new Error('Directives are not supported');
10
+ if (!validateChildren) {
11
+ return;
12
+ }
13
+ construct(this.node.expression, this.context).validate(true);
14
+ }
15
+ run() {
16
+ this.validate();
10
17
  return construct(this.node.expression, this.context).run();
11
18
  }
12
19
  }
@@ -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;
@@ -1,9 +1,19 @@
1
1
  import Node from '../Node';
2
2
  import { construct } from '../../utils';
3
- export default class BinaryExpressionNode extends Node {
3
+ class BinaryExpressionNode extends Node {
4
4
  constructor(node, context) {
5
5
  super(node, context, 'LogicalExpression');
6
6
  }
7
+ validate(validateChildren) {
8
+ if (!BinaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
9
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
10
+ }
11
+ if (!validateChildren) {
12
+ return;
13
+ }
14
+ construct(this.node.left, this.context).validate(true);
15
+ construct(this.node.right, this.context).validate(true);
16
+ }
7
17
  run() {
8
18
  const left = construct(this.node.left, this.context).run();
9
19
  const shortCircuit = this.shortCircuit(left);
@@ -39,3 +49,5 @@ export default class BinaryExpressionNode extends Node {
39
49
  }
40
50
  }
41
51
  }
52
+ BinaryExpressionNode.SUPPORTED_OPERATORS = new Set(['||', '&&', '??']);
53
+ export 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
  *
@@ -23,6 +23,13 @@ export default class MemberExpressionNode extends Node {
23
23
  constructor(node, context) {
24
24
  super(node, context, 'MemberExpression');
25
25
  }
26
+ validate(validateChildren = false) {
27
+ if (!validateChildren) {
28
+ return;
29
+ }
30
+ construct(this.node.object, this.context).validate(true);
31
+ construct(this.node.property, this.context).validate(true);
32
+ }
26
33
  run() {
27
34
  const object = construct(this.node.object, this.context).run();
28
35
  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;
@@ -4,6 +4,35 @@ export default class ObjectExpressionNode extends Node {
4
4
  constructor(node, context) {
5
5
  super(node, context, 'ObjectExpression');
6
6
  }
7
+ validate(validateChildren) {
8
+ for (const property of this.node.properties) {
9
+ // SpreadElements do not need to be validated - they only have a single argument
10
+ if (property.type === 'SpreadElement') {
11
+ continue;
12
+ }
13
+ if (property.kind !== 'init') {
14
+ // do not support getters or setters
15
+ throw new Error('Only init properties are supported');
16
+ }
17
+ if (!property.computed) {
18
+ // ensure that the key is valid
19
+ this.getStaticKey(property.key);
20
+ }
21
+ }
22
+ if (!validateChildren) {
23
+ return;
24
+ }
25
+ for (const property of this.node.properties) {
26
+ if (property.type === 'SpreadElement') {
27
+ construct(property.argument, this.context).validate(true);
28
+ continue;
29
+ }
30
+ if (property.computed) {
31
+ construct(property.key, this.context).validate(true);
32
+ }
33
+ construct(property.value, this.context).validate(true);
34
+ }
35
+ }
7
36
  run() {
8
37
  const object = {};
9
38
  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
  }
@@ -4,10 +4,18 @@ import { construct } from '../../utils';
4
4
  *
5
5
  * e.g. `+1`, `-2`, `!true`, `typeof x`
6
6
  */
7
- export default class UnaryExpressionNode extends Node {
7
+ class UnaryExpressionNode extends Node {
8
8
  constructor(node, context) {
9
9
  super(node, context, 'UnaryExpression');
10
10
  }
11
+ validate(validateChildren) {
12
+ if (!UnaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
13
+ throw new Error(`Unsupported operator: ${this.node.operator}`);
14
+ }
15
+ if (validateChildren) {
16
+ construct(this.node.argument, this.context).validate(true);
17
+ }
18
+ }
11
19
  run() {
12
20
  const argument = construct(this.node.argument, this.context).run();
13
21
  switch (this.node.operator) {
@@ -36,3 +44,5 @@ export default class UnaryExpressionNode extends Node {
36
44
  }
37
45
  }
38
46
  }
47
+ UnaryExpressionNode.SUPPORTED_OPERATORS = new Set(['+', '-', '!', 'typeof']);
48
+ export 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dronedeploy/rocos-js-sdk",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "description": "Javascript SDK for rocos",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",