Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Dependencies/salesforce-soql-parser-0.17.0.tgz
Binary file not shown.
Binary file removed Dependencies/soql-parser-0.16.0.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"antlr4": "4.8.0",
"vscode-languageserver": "6.1.1",
"vscode-languageserver-textdocument": "1.0.1",
"@salesforce/soql-parser": "file:../../Dependencies/soql-parser-0.16.0.tgz"
"@salesforce/soql-parser": "file:../../Dependencies/salesforce-soql-parser-0.17.0.tgz"
},
"devDependencies": {
"@babel/core": "^7.12.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/scripts/unbundle-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var path = require('path');
var packagePath = '../package.json';
var package = require(packagePath);
var parser = '@salesforce/soql-parser';
var tarballPath = 'file:../../Dependencies/soql-parser-0.16.0.tgz';
var tarballPath = 'file:../../Dependencies/salesforce-soql-parser-0.17.0.tgz';

delete package.bundledDependencies;
package.dependencies[parser] = tarballPath;
Expand Down
2 changes: 1 addition & 1 deletion packages/soql-model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"antlr4": "4.8.0",
"@salesforce/soql-parser": "file:../../Dependencies/soql-parser-0.16.0.tgz"
"@salesforce/soql-parser": "file:../../Dependencies/salesforce-soql-parser-0.17.0.tgz"
},
"devDependencies": {
"@types/antlr4": "4.7.2",
Expand Down
16 changes: 15 additions & 1 deletion packages/soql-model/scripts/getquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ var selectExprs = fields.map(
var queryModel = new model.Impl.QueryImpl(
new model.Impl.SelectExprsImpl(selectExprs),
new model.Impl.FromImpl(sobjectName),
new model.Impl.UnmodeledSyntaxImpl('WHERE field1 = 5'),
new model.Impl.WhereImpl(
new model.Impl.AndOrConditionImpl(
new model.Impl.FieldCompareConditionImpl(
new model.Impl.FieldRefImpl('field1'),
model.Soql.CompareOperator.LT,
new model.Impl.LiteralImpl(model.Soql.LiteralType.Number, '5')
),
'And',
new model.Impl.FieldCompareConditionImpl(
new model.Impl.FieldRefImpl('field2'),
model.Soql.CompareOperator.GT,
new model.Impl.LiteralImpl(model.Soql.LiteralType.Number, '5')
)
)
),
undefined,
undefined,
new model.Impl.OrderByImpl([
Expand Down
4 changes: 3 additions & 1 deletion packages/soql-model/scripts/getsobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var model = require('../lib');

var query =
'SELECT field1, field2 FROM object1 ORDER BY field1 DESC NULLS LAST, field2 ASC NULLS FIRST';
"SELECT field1, field2 FROM object1 WHERE field1='Hello' AND field2 < 1 ORDER BY field1 DESC NULLS LAST, field2 ASC NULLS FIRST";
// var query =
// 'SELECT field1, field2, field3 alias3, (SELECT fieldA FROM objectA), TYPEOF obj WHEN typeX THEN fieldX ELSE fieldY END FROM object1 ' +
// 'WHERE field1 = 5 WITH DATA CATEGORY cat__c AT val__c GROUP BY field1 ORDER BY field2 DESC NULLS LAST LIMIT 20 OFFSET 2 BIND field1 = 5 FOR VIEW UPDATE TRACKING';
Expand All @@ -21,13 +21,15 @@ var fields =
: undefined;
var sObject = queryModel.from ? queryModel.from.sobjectName : undefined;
var errors = queryModel.errors;
var where = queryModel.where ? queryModel.where.toSoqlSyntax() : undefined;
var orderBy = queryModel.orderBy.orderByExpressions.map(
(expr) => `${expr.field.fieldName} ${expr.order} ${expr.nullsOrder}`
);
var limit = queryModel.limit ? queryModel.limit.limit : 'undefined';
console.log(`Query: ${query}`);
console.log(`SObject: ${sObject}`);
console.log(`Fields: ${fields}`);
console.log(`Where: ${where}`);
Comment on lines +24 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample script update

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would line 32 be good to look at to get an idea of whats available to the UI for a where clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that's just the where clause transformed back to SOQL syntax. Line 16 of getquery.js is indicative of how the model is created. For raw JSON, deserializer.test.ts has lots of examples of what these different conditions look like when modeled in a WHERE clause.

console.log(`Order By: ${orderBy}`);
console.log(`Limit: ${limit}`);
console.log(`Errors: ${JSON.stringify(errors)}`);
2 changes: 1 addition & 1 deletion packages/soql-model/scripts/unbundle-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var path = require('path');
var packagePath = '../package.json';
var package = require(packagePath);
var parser = '@salesforce/soql-parser';
var tarballPath = 'file:../../Dependencies/soql-parser-0.16.0.tgz';
var tarballPath = 'file:../../Dependencies/salesforce-soql-parser-0.17.0.tgz';

delete package.bundledDependencies;
package.dependencies[parser] = tarballPath;
Expand Down
34 changes: 34 additions & 0 deletions packages/soql-model/src/model/impl/andOrConditionImpl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Impl from '.';
import { AndOr, CompareOperator, LiteralType } from '../model';

describe('AndOrConditionImpl should', () => {
it('store left and right conditions and the AndOr operator', () => {
const expected = {
leftCondition: { field: { fieldName: 'field' }, operator: '>', compareValue: { type: 'NUMBER', value: '1' } },
andOr: 'OR',
rightCondition: { field: { fieldName: 'field' }, operator: '<', compareValue: { type: 'NUMBER', value: '5' } }
};
const actual = new Impl.AndOrConditionImpl(
new Impl.FieldCompareConditionImpl(new Impl.FieldRefImpl('field'), CompareOperator.GT, new Impl.LiteralImpl(LiteralType.Number, '1')),
AndOr.Or,
new Impl.FieldCompareConditionImpl(new Impl.FieldRefImpl('field'), CompareOperator.LT, new Impl.LiteralImpl(LiteralType.Number, '5'))
);
expect(actual).toEqual(expected);
});
it('return left condition followed by AndOr operator followed by right condition for toSoqlSyntax()', () => {
const expected = 'field > 1 OR field < 5';
const actual = new Impl.AndOrConditionImpl(
new Impl.FieldCompareConditionImpl(new Impl.FieldRefImpl('field'), CompareOperator.GT, new Impl.LiteralImpl(LiteralType.Number, '1')),
AndOr.Or,
new Impl.FieldCompareConditionImpl(new Impl.FieldRefImpl('field'), CompareOperator.LT, new Impl.LiteralImpl(LiteralType.Number, '5'))
).toSoqlSyntax();
expect(actual).toEqual(expected);
});
});
18 changes: 18 additions & 0 deletions packages/soql-model/src/model/impl/andOrConditionImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Soql from '../model';
import { SoqlModelObjectImpl } from './soqlModelObjectImpl';

export class AndOrConditionImpl extends SoqlModelObjectImpl implements Soql.AndOrCondition {
public constructor(public leftCondition: Soql.Condition, public andOr: Soql.AndOr, public rightCondition: Soql.Condition) {
super();
}
public toSoqlSyntax(options?: Soql.SyntaxOptions): string {
return `${this.leftCondition.toSoqlSyntax(options)} ${this.andOr} ${this.rightCondition.toSoqlSyntax(options)}`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Impl from '.';
import { CompareOperator, LiteralType } from '../model';

describe('FieldCompareConditionImpl should', () => {
it('store field, operator, and value', () => {
const expected = { field: { fieldName: 'field' }, operator: '=', compareValue: { type: 'STRING', value: "'abc'" } };
const actual = new Impl.FieldCompareConditionImpl(
new Impl.FieldRefImpl('field'),
CompareOperator.EQ,
new Impl.LiteralImpl(LiteralType.String, "'abc'")
);
expect(actual).toEqual(expected);
});
it('return field, operator, and value separated by spaces for toSoqlSyntax()', () => {
const expected = `field = 'abc'`;
const actual = new Impl.FieldCompareConditionImpl(
new Impl.FieldRefImpl('field'),
CompareOperator.EQ,
new Impl.LiteralImpl(LiteralType.String, "'abc'")
).toSoqlSyntax();
expect(actual).toEqual(expected);
});
});
18 changes: 18 additions & 0 deletions packages/soql-model/src/model/impl/fieldCompareConditionImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Soql from '../model';
import { SoqlModelObjectImpl } from './soqlModelObjectImpl';

export class FieldCompareConditionImpl extends SoqlModelObjectImpl implements Soql.FieldCompareCondition {
public constructor(public field: Soql.Field, public operator: Soql.CompareOperator, public compareValue: Soql.CompareValue) {
super();
}
public toSoqlSyntax(options?: Soql.SyntaxOptions): string {
return `${this.field.toSoqlSyntax(options)} ${this.operator} ${this.compareValue.toSoqlSyntax(options)}`;
}
}
30 changes: 30 additions & 0 deletions packages/soql-model/src/model/impl/inListConditionImpl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Impl from '.';
import { InOperator, LiteralType } from '../model';

describe('InListConditionImpl should', () => {
it('store field, operator, and values', () => {
const expected = { field: { fieldName: 'field' }, operator: 'NOT IN', values: [{ type: 'STRING', value: "'abc'" }, { type: 'STRING', value: "'def'" }] };
const actual = new Impl.InListConditionImpl(
new Impl.FieldRefImpl('field'),
InOperator.NotIn,
[new Impl.LiteralImpl(LiteralType.String, "'abc'"), new Impl.LiteralImpl(LiteralType.String, "'def'")]
);
expect(actual).toEqual(expected);
});
it('return field, operator, and parenthesized comma-separated values separated by spaces for toSoqlSyntax()', () => {
const expected = "field NOT IN ( 'abc', 'def' )";
const actual = new Impl.InListConditionImpl(
new Impl.FieldRefImpl('field'),
InOperator.NotIn,
[new Impl.LiteralImpl(LiteralType.String, "'abc'"), new Impl.LiteralImpl(LiteralType.String, "'def'")]
).toSoqlSyntax();
expect(actual).toEqual(expected);
});
});
24 changes: 24 additions & 0 deletions packages/soql-model/src/model/impl/inListConditionImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Soql from '../model';
import { SoqlModelObjectImpl } from './soqlModelObjectImpl';

export class InListConditionImpl extends SoqlModelObjectImpl implements Soql.InListCondition {
public constructor(public field: Soql.Field, public operator: Soql.InOperator, public values: Soql.CompareValue[]) {
super();
}
public toSoqlSyntax(options?: Soql.SyntaxOptions): string {
let valuesSyntax = '';
this.values.forEach(value => valuesSyntax = `${valuesSyntax}, ${value.toSoqlSyntax(options)}`);
if (valuesSyntax.length > 2) {
// remove comma separator at start of string
valuesSyntax = valuesSyntax.substring(2);
}
return `${this.field.toSoqlSyntax(options)} ${this.operator} ( ${valuesSyntax} )`;
}
}
30 changes: 30 additions & 0 deletions packages/soql-model/src/model/impl/includesConditionImpl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Impl from '.';
import { IncludesOperator, LiteralType } from '../model';

describe('IncludesConditionImpl should', () => {
it('store field, operator, and values', () => {
const expected = { field: { fieldName: 'field' }, operator: 'INCLUDES', values: [{ type: 'STRING', value: "'abc'" }, { type: 'STRING', value: "'def'" }] };
const actual = new Impl.IncludesConditionImpl(
new Impl.FieldRefImpl('field'),
IncludesOperator.Includes,
[new Impl.LiteralImpl(LiteralType.String, "'abc'"), new Impl.LiteralImpl(LiteralType.String, "'def'")]
);
expect(actual).toEqual(expected);
});
it('return field, operator, and parenthesized comma-separated values separated by spaces for toSoqlSyntax()', () => {
const expected = "field INCLUDES ( 'abc', 'def' )";
const actual = new Impl.IncludesConditionImpl(
new Impl.FieldRefImpl('field'),
IncludesOperator.Includes,
[new Impl.LiteralImpl(LiteralType.String, "'abc'"), new Impl.LiteralImpl(LiteralType.String, "'def'")]
).toSoqlSyntax();
expect(actual).toEqual(expected);
});
});
24 changes: 24 additions & 0 deletions packages/soql-model/src/model/impl/includesConditionImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Soql from '../model';
import { SoqlModelObjectImpl } from './soqlModelObjectImpl';

export class IncludesConditionImpl extends SoqlModelObjectImpl implements Soql.IncludesCondition {
public constructor(public field: Soql.Field, public operator: Soql.IncludesOperator, public values: Soql.CompareValue[]) {
super();
}
public toSoqlSyntax(options?: Soql.SyntaxOptions): string {
let valuesSyntax = '';
this.values.forEach(value => valuesSyntax = `${valuesSyntax}, ${value.toSoqlSyntax(options)}`);
if (valuesSyntax.length > 2) {
// remove comma separator at start of string
valuesSyntax = valuesSyntax.substring(2);
}
return `${this.field.toSoqlSyntax(options)} ${this.operator} ( ${valuesSyntax} )`;
}
}
18 changes: 18 additions & 0 deletions packages/soql-model/src/model/impl/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
import { AndOrConditionImpl } from './andOrConditionImpl';
import { FieldCompareConditionImpl } from './fieldCompareConditionImpl';
import { FieldRefImpl } from './fieldRefImpl';
import { FieldSelectionImpl } from './fieldSelectionImpl';
import { FromImpl } from './fromImpl';
import { IncludesConditionImpl } from './includesConditionImpl';
import { InListConditionImpl } from './inListConditionImpl';
import { LikeConditionImpl } from './likeConditionImpl';
import { LimitImpl } from './limitImpl';
import { LiteralImpl } from './literalImpl';
import { NestedConditionImpl } from './nestedConditionImpl';
import { NotConditionImpl } from './notConditionImpl';
import { OrderByImpl } from './orderByImpl';
import { OrderByExpressionImpl } from './orderByExpressionImpl';
import { QueryImpl } from './queryImpl';
import { SelectExprsImpl } from './selectExprsImpl';
import { WhereImpl } from './whereImpl';
import { UnmodeledSyntaxImpl } from './unmodeledSyntaxImpl';

export {
AndOrConditionImpl,
FieldCompareConditionImpl,
FieldRefImpl,
FieldSelectionImpl,
FromImpl,
IncludesConditionImpl,
InListConditionImpl,
LikeConditionImpl,
LimitImpl,
LiteralImpl,
NestedConditionImpl,
NotConditionImpl,
QueryImpl,
SelectExprsImpl,
OrderByImpl,
OrderByExpressionImpl,
WhereImpl,
UnmodeledSyntaxImpl,
};
28 changes: 28 additions & 0 deletions packages/soql-model/src/model/impl/likeConditionImpl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Impl from '.';
import { LiteralType } from '../model';

describe('LikeConditionImpl should', () => {
it('store field and value', () => {
const expected = { field: { fieldName: 'field' }, compareValue: { type: 'STRING', value: "'abc'" } };
const actual = new Impl.LikeConditionImpl(
new Impl.FieldRefImpl('field'),
new Impl.LiteralImpl(LiteralType.String, "'abc'")
);
expect(actual).toEqual(expected);
});
it('return field, LIKE keyword, and value separated by spaces for toSoqlSyntax()', () => {
const expected = `field LIKE 'abc'`;
const actual = new Impl.LikeConditionImpl(
new Impl.FieldRefImpl('field'),
new Impl.LiteralImpl(LiteralType.String, "'abc'")
).toSoqlSyntax();
expect(actual).toEqual(expected);
});
});
18 changes: 18 additions & 0 deletions packages/soql-model/src/model/impl/likeConditionImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as Soql from '../model';
import { SoqlModelObjectImpl } from './soqlModelObjectImpl';

export class LikeConditionImpl extends SoqlModelObjectImpl implements Soql.LikeCondition {
public constructor(public field: Soql.Field, public compareValue: Soql.CompareValue) {
super();
}
public toSoqlSyntax(options?: Soql.SyntaxOptions): string {
return `${this.field.toSoqlSyntax(options)} LIKE ${this.compareValue.toSoqlSyntax(options)}`;
}
}
Loading