Skip to content

Commit 2924569

Browse files
authored
Merge pull request #254 from salesforcecli/wr/parkingOrbit
fix: parking orbit plugin-limits
2 parents 3be9c54 + 92ea213 commit 2924569

File tree

9 files changed

+1819
-1259
lines changed

9 files changed

+1819
-1259
lines changed

command-snapshot.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
{
33
"command": "force:limits:api:display",
44
"plugin": "@salesforce/plugin-limits",
5-
"flags": ["apiversion", "json", "loglevel", "targetusername"]
5+
"flags": ["apiversion", "json", "loglevel", "targetusername"],
6+
"alias": []
67
},
78
{
89
"command": "force:limits:recordcounts:display",
910
"plugin": "@salesforce/plugin-limits",
10-
"flags": ["apiversion", "json", "loglevel", "targetusername", "sobjecttype"]
11+
"flags": ["apiversion", "json", "loglevel", "sobjecttype", "targetusername"],
12+
"alias": []
1113
}
1214
]

messages/recordcounts.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"commandDescription": "display record counts for the specified standard and custom objects\nUse this command to get an approximate count of the records in standard or custom objects in your org. These record counts are the same as the counts listed in the Storage Usage page in Setup. The record counts are approximate because they're calculated asynchronously and your orgs storage usage isnt updated immediately.",
2+
"commandDescription": "display record counts for the specified standard and custom objects\nUse this command to get an approximate count of the records in standard or custom objects in your org. These record counts are the same as the counts listed in the Storage Usage page in Setup. The record counts are approximate because they're calculated asynchronously and your org's storage usage isn't updated immediately. To display all available record counts, run the command without the '--sobjecttype' parameter.",
33
"examples": [
4+
"sfdx force:limits:recordcounts:display",
45
"sfdx force:limits:recordcounts:display -s Account,Contact,Lead,Opportunity",
56
"sfdx force:limits:recordcounts:display -s Account,Contact -u [email protected]"
67
],

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
22
"name": "@salesforce/plugin-limits",
33
"description": "commands to display api limits to your org",
4-
"version": "1.3.0",
4+
"version": "2.0.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
7+
"main": "lib/index.js",
78
"dependencies": {
8-
"@oclif/config": "^1",
9-
"@salesforce/command": "^4.2.0",
10-
"@salesforce/core": "^2.31.0",
9+
"@oclif/core": "^1.6.3",
10+
"@salesforce/command": "^5.0.4",
11+
"@salesforce/core": "^3.10.1",
1112
"tslib": "^2"
1213
},
1314
"devDependencies": {
1415
"@oclif/dev-cli": "^1",
15-
"@oclif/plugin-command-snapshot": "^2.0.0",
16+
"@oclif/plugin-command-snapshot": "^3",
1617
"@salesforce/cli-plugins-testkit": "^1.4.10",
1718
"@salesforce/dev-config": "^3.0.0",
1819
"@salesforce/dev-scripts": "^2.0.0",
@@ -67,6 +68,9 @@
6768
"license": "BSD-3-Clause",
6869
"oclif": {
6970
"commands": "./lib/commands",
71+
"additionalHelpFlags": [
72+
"-h"
73+
],
7074
"bin": "sfdx",
7175
"devPlugins": [
7276
"@oclif/plugin-help",

src/commands/force/limits/api/display.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import * as os from 'os';
88
import { SfdxCommand } from '@salesforce/command';
9-
import { Messages, SfdxError } from '@salesforce/core';
9+
import { Messages, SfError } from '@salesforce/core';
1010

1111
Messages.importMessagesDirectory(__dirname);
1212
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'display');
@@ -44,17 +44,11 @@ export class LimitsApiDisplayCommand extends SfdxCommand {
4444
});
4545
});
4646

47-
this.ux.table(limits, {
48-
columns: [
49-
{ key: 'name', label: 'Name' },
50-
{ key: 'remaining', label: 'Remaining' },
51-
{ key: 'max', label: 'Max' },
52-
],
53-
});
47+
this.ux.table(limits, { name: { header: 'Name' }, remaining: { header: 'Remaining' }, max: { header: 'Max' } });
5448

5549
return limits;
5650
} catch (err) {
57-
throw SfdxError.wrap(err);
51+
throw SfError.wrap(err);
5852
}
5953
}
6054
}

src/commands/force/limits/recordcounts/display.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import * as os from 'os';
88
import { flags, FlagsConfig, SfdxCommand, SfdxResult } from '@salesforce/command';
9-
import { Messages, SfdxError } from '@salesforce/core';
9+
import { Messages, SfError } from '@salesforce/core';
1010

1111
Messages.importMessagesDirectory(__dirname);
1212
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'recordcounts');
@@ -26,10 +26,8 @@ export class LimitsRecordCountsDisplayCommand extends SfdxCommand {
2626
public static readonly requiresUsername = true;
2727
public static readonly result: SfdxResult = {
2828
tableColumnData: {
29-
columns: [
30-
{ key: 'name', label: 'sObject' },
31-
{ key: 'count', label: 'Record Count' },
32-
],
29+
name: { header: 'sObject' },
30+
count: { header: 'Record Count' },
3331
},
3432
display() {
3533
if (Array.isArray(this.data) && this.data.length) {
@@ -41,28 +39,31 @@ export class LimitsRecordCountsDisplayCommand extends SfdxCommand {
4139
protected static readonly flagsConfig: FlagsConfig = {
4240
sobjecttype: flags.array({
4341
char: 's',
44-
required: true,
4542
description: messages.getMessage('sobjecttypeFlagDescription'),
4643
}),
4744
};
4845

4946
public async run(): Promise<RecordCount[]> {
5047
try {
51-
const sobjecttypeString = (this.flags.sobjecttype as string[]).join();
48+
const sobjectsPassed = this.flags.sobjecttype as string[];
49+
const sobjectsQuery = sobjectsPassed ? `=${sobjectsPassed.join()}` : '';
50+
5251
const conn = this.org.getConnection();
53-
const geturl = `${conn.baseUrl()}/limits/recordCount?sObjects=${sobjecttypeString}`;
54-
const result = (await conn.request(geturl)) as unknown as Result;
52+
const geturl = `${conn.baseUrl()}/limits/recordCount?sObjects${sobjectsQuery}`;
53+
const result = await conn.request<Result>(geturl);
5554

5655
// if an object is requested, but there's 0 of them on the server, append that object to the result
57-
sobjecttypeString.split(',').forEach((name) => {
58-
if (!result.sObjects.find((record) => record.name === name)) {
59-
result.sObjects.push({ name, count: 0 });
60-
}
61-
});
56+
if (sobjectsPassed) {
57+
sobjectsPassed.forEach((name) => {
58+
if (!result.sObjects.find((record) => record.name === name)) {
59+
result.sObjects.push({ name, count: 0 });
60+
}
61+
});
62+
}
6263

6364
return result.sObjects;
6465
} catch (err) {
65-
throw SfdxError.wrap(err);
66+
throw SfError.wrap(err);
6667
}
6768
}
6869
}

test/commands/display.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { $$, test, expect } from '@salesforce/command/lib/test';
99

1010
describe('force:limits:api:display', () => {
1111
async function prepareStubs() {
12-
$$.SANDBOX.stub(Org.prototype, 'getConnection').callsFake(() => Connection.prototype);
12+
$$.SANDBOX.stub(Org.prototype, 'getConnection').returns(Connection.prototype);
1313
$$.SANDBOX.stub(Connection.prototype, 'request').resolves({
1414
AnalyticsExternalDataSizeMB: {
1515
Max: 40960,

test/commands/recordcounts.nut.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ describe('recordcounts:display', () => {
3838
expect(output.status).to.equal(0);
3939
});
4040

41+
it('Displays all records (json)', () => {
42+
const output = execCmd<RecordCount[]>(`force:limits:recordcounts:display -u ${username} --json`, {
43+
ensureExitCode: 0,
44+
}).jsonOutput;
45+
46+
expect(output.result).length.greaterThan(10);
47+
expect(output.status).to.equal(0);
48+
});
49+
4150
it('Displays the records (human readable)', () => {
4251
const command = `force:limits:recordcounts:display -s Account -u ${username}`;
4352
const result = execCmd(command, { ensureExitCode: 0 });

test/commands/recordcounts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { $$, test, expect } from '@salesforce/command/lib/test';
99

1010
describe('force:limits:recordcounts:display', () => {
1111
async function prepareStubs() {
12-
$$.SANDBOX.stub(Org.prototype, 'getConnection').callsFake(() => Connection.prototype);
12+
$$.SANDBOX.stub(Org.prototype, 'getConnection').returns(Connection.prototype);
1313
$$.SANDBOX.stub(Connection.prototype, 'request').resolves({
1414
sObjects: [
1515
{ count: 34, name: 'Account' },

0 commit comments

Comments
 (0)