diff --git a/CHANGELOG.md b/CHANGELOG.md index ef4b3082..6050456e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0-alpha.4 +- Support `WITH SECURITY_ENFORCED` in SOQL ([issue](https://github.com/dangmai/prettier-plugin-apex/issues/9)). +- Fix `npm scripts` pointing to old files. + ## 1.0.0-alpha.3 - Fix DML operation having double indents ([issue](https://github.com/dangmai/prettier-plugin-apex/issues/8)). diff --git a/src/printer.js b/src/printer.js index 34eccd6c..2c5d0728 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1266,11 +1266,15 @@ function handleWhereInnerExpression(path, print) { } function handleQuery(path, print) { + const withIdentifierDocs = path.map(print, "withIdentifiers"); const parts = []; parts.push(path.call(print, "select")); parts.push(path.call(print, "from")); _pushIfExist(parts, path.call(print, "where", "value")); _pushIfExist(parts, path.call(print, "with", "value")); + if (withIdentifierDocs.length > 0) { + parts.push(join(" ", withIdentifierDocs)); + } _pushIfExist(parts, path.call(print, "groupBy", "value")); _pushIfExist(parts, path.call(print, "orderBy", "value")); _pushIfExist(parts, path.call(print, "limit", "value")); @@ -2202,6 +2206,8 @@ nodeHandler[apexNames.SEARCH_USING_CLAUSE] = (path, print) => nodeHandler[apexNames.USING_TYPE] = handleUsingType; nodeHandler[apexNames.BIND_CLAUSE] = handleBindClause; nodeHandler[apexNames.BIND_EXPRESSION] = handleBindExpression; +nodeHandler[apexNames.WITH_IDENTIFIER] = (path, print) => + concat(["WITH", " ", path.call(print, "identifier")]); function handleTrailingEmptyLines(doc, node) { if (node.trailingEmptyLine) { diff --git a/src/values.js b/src/values.js index fbfd002e..932f4936 100644 --- a/src/values.js +++ b/src/values.js @@ -204,6 +204,7 @@ const values = { WITH_DATA_CATEGORIES: "apex.jorje.data.soql.WithClause$WithDataCategories", DATA_CATEGORY: "apex.jorje.data.soql.DataCategory", DATA_CATEGORY_OPERATOR: "apex.jorje.data.soql.DataCategoryOperator", + WITH_IDENTIFIER: "apex.jorje.data.soql.WithIdentifier", }, BINARY: { ADDITION: "+", diff --git a/tests/soql/SOQLClass.cls b/tests/soql/SOQLClass.cls index 83130010..bad8325c 100644 --- a/tests/soql/SOQLClass.cls +++ b/tests/soql/SOQLClass.cls @@ -110,6 +110,12 @@ class SOQLClass { Contact[] fullOrder = [SELECT Id FROM Contact ORDER BY Name ASC NULLS FIRST]; } + void withIdentifiersSoql() { + Account[] withSecurityEnforced = [SELECT Id FROM Account WITH SECURITY_ENFORCED]; + Account[] withRandomIdentifiers = [SELECT Id FROM Account WITH SECURITY_ENFORCED WITH RANDOM_IDENTIFIER]; + Account[] withIdentifierOrder = [SELECT Id FROM Account WHERE Name = 'Hello' WITH SECURITY_ENFORCED GROUP BY Id]; + } + void nicheSoql() { Contact[] forView = [SELECT Name, ID FROM Contact LIMIT 1 FOR VIEW]; Contact[] forReference = [SELECT Name, ID FROM Contact LIMIT 1 FOR REFERENCE]; diff --git a/tests/soql/__snapshots__/jsfmt.spec.js.snap b/tests/soql/__snapshots__/jsfmt.spec.js.snap index 3da1545d..37c5b478 100644 --- a/tests/soql/__snapshots__/jsfmt.spec.js.snap +++ b/tests/soql/__snapshots__/jsfmt.spec.js.snap @@ -113,6 +113,12 @@ class SOQLClass { Contact[] fullOrder = [SELECT Id FROM Contact ORDER BY Name ASC NULLS FIRST]; } + void withIdentifiersSoql() { + Account[] withSecurityEnforced = [SELECT Id FROM Account WITH SECURITY_ENFORCED]; + Account[] withRandomIdentifiers = [SELECT Id FROM Account WITH SECURITY_ENFORCED WITH RANDOM_IDENTIFIER]; + Account[] withIdentifierOrder = [SELECT Id FROM Account WHERE Name = 'Hello' WITH SECURITY_ENFORCED GROUP BY Id]; + } + void nicheSoql() { Contact[] forView = [SELECT Name, ID FROM Contact LIMIT 1 FOR VIEW]; Contact[] forReference = [SELECT Name, ID FROM Contact LIMIT 1 FOR REFERENCE]; @@ -369,6 +375,26 @@ class SOQLClass { ]; } + void withIdentifiersSoql() { + Account[] withSecurityEnforced = [ + SELECT Id + FROM Account + WITH SECURITY_ENFORCED + ]; + Account[] withRandomIdentifiers = [ + SELECT Id + FROM Account + WITH SECURITY_ENFORCED WITH RANDOM_IDENTIFIER + ]; + Account[] withIdentifierOrder = [ + SELECT Id + FROM Account + WHERE Name = 'Hello' + WITH SECURITY_ENFORCED + GROUP BY Id + ]; + } + void nicheSoql() { Contact[] forView = [SELECT Name, ID FROM Contact LIMIT 1 FOR VIEW]; Contact[] forReference = [ diff --git a/vendor/apex-ast-serializer/lib/apex-ast-serializer-1.0-SNAPSHOT.jar b/vendor/apex-ast-serializer/lib/apex-ast-serializer-1.0-SNAPSHOT.jar index c0c9f2f4..7cb20381 100644 Binary files a/vendor/apex-ast-serializer/lib/apex-ast-serializer-1.0-SNAPSHOT.jar and b/vendor/apex-ast-serializer/lib/apex-ast-serializer-1.0-SNAPSHOT.jar differ diff --git a/vendor/apex-ast-serializer/lib/apex-jorje-lsp.jar b/vendor/apex-ast-serializer/lib/apex-jorje-lsp.jar index cef59d7a..94eec9af 100644 Binary files a/vendor/apex-ast-serializer/lib/apex-jorje-lsp.jar and b/vendor/apex-ast-serializer/lib/apex-jorje-lsp.jar differ