Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0478505
Applied prettier, created pre-commit hook and config
ZackFra Jan 11, 2025
820823c
Refactor Selector class query method for improved readability
ZackFra Jan 11, 2025
66f8ef2
Created husky dependency
ZackFra Jan 11, 2025
0d6cade
Fix indentation in Selector class query method for improved readability
ZackFra Jan 11, 2025
04fcfc8
Fix indentation in Selector class query method for improved readability
ZackFra Jan 11, 2025
f877f45
Fix indentation in Selector class query method for improved readability
ZackFra Jan 11, 2025
b875a61
Fix indentation in Selector class for improved readability
ZackFra Jan 11, 2025
360cc87
Fix indentation in Selector class for improved readability
ZackFra Jan 11, 2025
3ad1e44
Fix lint-staged glob pattern for better file matching
ZackFra Jan 11, 2025
2a34535
Test
ZackFra Jan 11, 2025
49d1d95
Refactor Selector class method for improved readability and update hu…
ZackFra Jan 11, 2025
96fe610
Fix indentation in Selector class for improved readability
ZackFra Jan 11, 2025
1092980
Update prettier verify script to use apex plugin for consistency
ZackFra Jan 11, 2025
8eacd52
Format code in Selector class for improved readability
ZackFra Jan 11, 2025
709294b
Add test script to package.json for validation
ZackFra Jan 11, 2025
3b3e6f9
Update lint-staged configuration to only format modified JavaScript f…
ZackFra Jan 11, 2025
92fa1f8
Update lint-staged configuration to format all Apex files without fil…
ZackFra Jan 11, 2025
aa4c09d
Add suppression for excessive parameter list warning in Node constructor
ZackFra Jan 11, 2025
2ed97fe
Remove unnecessary blank line in Node constructor
ZackFra Jan 11, 2025
1f9e9f2
Remove unnecessary blank line in Node constructor
ZackFra Jan 11, 2025
ea34466
Fix formatting in Node constructor by removing unnecessary blank lines
ZackFra Jan 11, 2025
fd45ae4
Updating the pre-commit trigger to filter on apex files
ZackFra Jan 11, 2025
4999406
Remove deprecated prettier script for apex file formatting
ZackFra Jan 11, 2025
5674c93
Refactor formatting in MockSelectorHavingClauseTest for improved read…
ZackFra Jan 11, 2025
db0bb07
Update package.json to add @salesforce/cli dependency and remove old …
ZackFra Jan 11, 2025
1f7199f
Remove husky from .gitignore to allow for proper version control
ZackFra Jan 11, 2025
a2a3feb
Add husky hooks for pre-commit and script execution
ZackFra Jan 11, 2025
9c26028
Remove husky.sh script as part of husky cleanup
ZackFra Jan 11, 2025
1b75e23
Refactor Node constructor for improved readability
ZackFra Jan 11, 2025
3c0c2f0
Enhance pre-commit hook to include code scanning and update sf:codesc…
ZackFra Jan 11, 2025
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules/
.vscode/
.husky/

package-lock.json
.sf/
Expand Down
36 changes: 36 additions & 0 deletions .husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env sh
if [ -z "$husky_skip_init" ]; then
debug () {
if [ "$HUSKY_DEBUG" = "1" ]; then
echo "husky (debug) - $1"
fi
}

readonly hook_name="$(basename -- "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

readonly husky_skip_init=1
export husky_skip_init
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
fi

if [ $exitCode = 127 ]; then
echo "husky - command not found in PATH=$PATH"
fi

exit $exitCode
fi
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged --allow-empty
npm run sf:codescan
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 4
}
15 changes: 7 additions & 8 deletions moxygen/main/default/classes/aggregate/Aggregate.cls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
/*
* MIT License
*
* Copyright (c) 2024 Zackary Frazier
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand All @@ -21,17 +21,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
*/

/**
* @description Aggregate class to represent the result of an aggregate query
* @author Zackary Frazier
* @since 4/5/2024
*/
public inherited sharing class Aggregate {

private Map<String, Object> data;

/**
* @description Standard constructor, creates an Aggregate object from an AggregateResult
* @param ar the AggregateResult to create the Aggregate from
Expand All @@ -49,8 +48,8 @@ public inherited sharing class Aggregate {
}

/**
* @description Constructor for testing purposes, creates an Aggregate object from a ProtoAggregate
* @param ar
* @description Constructor for testing purposes, creates an Aggregate object from a ProtoAggregate
* @param ar
*/
public Aggregate(ProtoAggregate ar) {
this.data = ar.getPrototype();
Expand All @@ -77,4 +76,4 @@ public inherited sharing class Aggregate {
private Set<String> keySet() {
return data.keySet();
}
}
}
38 changes: 20 additions & 18 deletions moxygen/main/default/classes/aggregate/AggregateBuilder.cls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
/*
* MIT License
*
* Copyright (c) 2024 Zackary Frazier
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand Down Expand Up @@ -32,13 +32,15 @@ public with sharing class AggregateBuilder {
List<ProtoAggregate> protoAggregates;
TopLevelNodes topLevelNodes;
Map<String, Object> params;

/**
* @description Setter for proto-aggregates
* @param protoAggregates the proto-aggregates
* @return the aggregate builder
*/
public AggregateBuilder setProtoAggregates(List<ProtoAggregate> protoAggregates) {
public AggregateBuilder setProtoAggregates(
List<ProtoAggregate> protoAggregates
) {
this.protoAggregates = protoAggregates;
return this;
}
Expand Down Expand Up @@ -68,14 +70,15 @@ public with sharing class AggregateBuilder {
* @return The cleaned up aggregate result list
*/
public List<Aggregate> build() {

// get list of all fields to group by, if is aggregate query
Map<String, List<String>> aggregateFields = AggregateService.getAggregateFields(topLevelNodes);
Map<String, List<String>> aggregateFields = AggregateService.getAggregateFields(
topLevelNodes
);
List<String> groupByFields = aggregateFields.get('groupByFields');
List<String> selectFields = aggregateFields.get('selectFields');

List<Aggregate> aggregateResultsList = new List<Aggregate>();
for(Integer i = 0; i < protoAggregates.size(); i++) {
for (Integer i = 0; i < protoAggregates.size(); i++) {
ProtoAggregate ar = protoAggregates[i];

ar = cleanUpAggregateResult(ar, groupByFields, selectFields);
Expand All @@ -86,34 +89,33 @@ public with sharing class AggregateBuilder {
}

private ProtoAggregate cleanUpAggregateResult(
ProtoAggregate aggr,
List<String> groupByFields,
ProtoAggregate aggr,
List<String> groupByFields,
List<String> selectFields
) {
aggr = aggr.clone();

// remove any fields that are grouped by, but not selected
for(String groupByField : groupByFields) {
if(selectFields.contains(groupByField)) {
for (String groupByField : groupByFields) {
if (selectFields.contains(groupByField)) {
continue;
}

for(String key : aggr.keySet()) {
if(key.toLowerCase() == groupByField) {
for (String key : aggr.keySet()) {
if (key.toLowerCase() == groupByField) {
aggr.remove(key);
}
}
}

// remove the internal fields used for COUNT_DISTINCT and AVG
for(String key : aggr.keySet()) {
for (String key : aggr.keySet()) {
Boolean isAvg = key.endsWith('__n');
Boolean isDistinct = key.endsWith('__distinct');
if(isAvg || isDistinct) {
if (isAvg || isDistinct) {
aggr.remove(key);
}
}
return aggr;
}

}
}
18 changes: 11 additions & 7 deletions moxygen/main/default/classes/aggregate/AggregateTest.cls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
/*
* MIT License
*
* Copyright (c) 2024 Zackary Frazier
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand Down Expand Up @@ -43,7 +43,7 @@ private class AggregateTest {

@IsTest
private static void testAggregate() {
Map<String, Object> ar = new Map<String, Object> {
Map<String, Object> ar = new Map<String, Object>{
'Name' => 'Test Account',
'Type' => 'Prospect',
'Industry' => 'Agriculture'
Expand All @@ -63,7 +63,7 @@ private class AggregateTest {

@IsTest
private static void testGet() {
Map<String, Object> ar = new Map<String, Object> {
Map<String, Object> ar = new Map<String, Object>{
'Name' => 'Test Account',
'Type' => 'Prospect',
'Industry' => 'Agriculture'
Expand All @@ -83,7 +83,7 @@ private class AggregateTest {

@IsTest
private static void testToString() {
Map<String, Object> ar = new Map<String, Object> {
Map<String, Object> ar = new Map<String, Object>{
'Name' => 'Test Account',
'Type' => 'Prospect',
'Industry' => 'Agriculture'
Expand All @@ -94,6 +94,10 @@ private class AggregateTest {
String s = a.toString();
Test.stopTest();

Assert.areEqual('{Industry=Agriculture, Name=Test Account, Type=Prospect}', s, 'String is not correct');
Assert.areEqual(
'{Industry=Agriculture, Name=Test Account, Type=Prospect}',
s,
'String is not correct'
);
}
}
}
39 changes: 19 additions & 20 deletions moxygen/main/default/classes/aggregate/ProtoAggregate.cls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
/*
* MIT License
*
* Copyright (c) 2024 Zackary Frazier
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
Expand Down Expand Up @@ -31,12 +31,12 @@
*/
public with sharing class ProtoAggregate {
public Map<String, Object> prototype = new Map<String, Object>();

List<SObject> records = new List<SObject>();

/**
* @description Constructor
* @param prototype
* @param prototype
*/
public ProtoAggregate(Map<String, Object> prototype) {
this.prototype = prototype;
Expand All @@ -50,26 +50,26 @@ public with sharing class ProtoAggregate {
}

/**
* @description put a key-value pair in the proto-aggregate
* @param key
* @param value
* @description put a key-value pair in the proto-aggregate
* @param key
* @param value
*/
public void put(String key, Object value) {
this.prototype.put(key, value);
}

/**
* @description get a value from the proto-aggregate
* @param key
* @description get a value from the proto-aggregate
* @param key
* @return `Object`
*/
public Object get(String key) {
return this.prototype.get(key);
}

/**
* @description remove a key-value pair from the proto-aggregate
* @param key
* @description remove a key-value pair from the proto-aggregate
* @param key
*/
public void remove(String key) {
this.prototype.remove(key);
Expand All @@ -83,48 +83,48 @@ public with sharing class ProtoAggregate {
}

/**
* @description get the size of the proto-aggregate
* @description get the size of the proto-aggregate
* @return `Integer`
*/
public Integer size() {
return this.prototype.size();
}

/**
* @description check if the proto-aggregate is empty
* @description check if the proto-aggregate is empty
* @return `Boolean`
*/
public Boolean isEmpty() {
return this.prototype.isEmpty();
}

/**
* @description check if the proto-aggregate contains a key
* @param key
* @description check if the proto-aggregate contains a key
* @param key
* @return `Boolean`
*/
public Boolean containsKey(String key) {
return this.prototype.containsKey(key);
}

/**
* @description check if the proto-aggregate contains a value
* @description check if the proto-aggregate contains a value
* @return `Set<String>`
*/
public Set<String> keySet() {
return this.prototype.keySet();
}

/**
* @description get the values of the proto-aggregate
* @description get the values of the proto-aggregate
* @return `List<Object>`
*/
public List<Object> values() {
return this.prototype.values();
}

/**
* @description Returns the proto-aggregate as a `Map<String, Object>`
* @description Returns the proto-aggregate as a `Map<String, Object>`
* @return `Map<String, Object>`
*/
public Map<String, Object> getPrototype() {
Expand All @@ -146,5 +146,4 @@ public with sharing class ProtoAggregate {
public void addRecord(SObject record) {
this.records.add(record);
}

}
}
Loading
Loading