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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
module.exports = {
extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license', 'plugin:sf-plugin/recommended'],
extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license'],
};
32 changes: 4 additions & 28 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,13 @@
{
"command": "force:limits:api:display",
"plugin": "@salesforce/plugin-limits",
"flags": ["json", "target-org"],
"alias": ["force:limits:api:display", "org:list:api-limits"]
"flags": ["apiversion", "json", "loglevel", "targetusername"],
"alias": []
},
{
"command": "force:limits:recordcounts:display",
"plugin": "@salesforce/plugin-limits",
"flags": ["json", "sobject", "target-org"],
"alias": ["force:limits:recordcounts:display", "org:list:sobject:record-counts"]
},
{
"command": "limits:api:display",
"plugin": "@salesforce/plugin-limits",
"flags": ["json", "target-org"],
"alias": ["force:limits:api:display", "org:list:api-limits"]
},
{
"command": "limits:recordcounts:display",
"plugin": "@salesforce/plugin-limits",
"flags": ["json", "sobject", "target-org"],
"alias": ["force:limits:recordcounts:display", "org:list:sobject:record-counts"]
},
{
"command": "org:list:api-limits",
"plugin": "@salesforce/plugin-limits",
"flags": ["json", "target-org"],
"alias": ["force:limits:api:display", "org:list:api-limits"]
},
{
"command": "org:list:sobject:record-counts",
"plugin": "@salesforce/plugin-limits",
"flags": ["json", "sobject", "target-org"],
"alias": ["force:limits:recordcounts:display", "org:list:sobject:record-counts"]
"flags": ["apiversion", "json", "loglevel", "sobjecttype", "targetusername"],
"alias": []
}
]
4 changes: 4 additions & 0 deletions messages/display.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "display current org’s limits\nWhen you execute this command in a project, it provides limit information for your default scratch org.",
"examples": ["$ sfdx force:limits:api:display", "$ sfdx force:limits:api:display -u me@my.org"]
}
13 changes: 0 additions & 13 deletions messages/display.md

This file was deleted.

9 changes: 9 additions & 0 deletions messages/recordcounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"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.",
"examples": [
"$ sfdx force:limits:recordcounts:display",
"$ sfdx force:limits:recordcounts:display -s Account,Contact,Lead,Opportunity",
"$ sfdx force:limits:recordcounts:display -s Account,Contact -u me@my.org"
],
"sobjecttypeFlagDescription": "comma-separated list of API names of standard or custom objects for which to display record counts"
}
17 changes: 0 additions & 17 deletions messages/recordcounts.md

This file was deleted.

47 changes: 22 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,39 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"main": "lib/index.js",
"dependencies": {
"@salesforce/core": "^3.31.18",
"@salesforce/kit": "^1.8.0",
"@salesforce/sf-plugins-core": "^1.17.4",
"@salesforce/ts-types": "^1.7.1",
"@oclif/core": "^1.20.4",
"@salesforce/command": "^5.2.22",
"@salesforce/core": "^3.31.16",
"tslib": "^2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^3",
"@oclif/test": "^2.2.10",
"@salesforce/cli-plugins-testkit": "^3.2.6",
"@salesforce/dev-config": "^3.1.0",
"@salesforce/dev-config": "^3.0.0",
"@salesforce/dev-scripts": "^3.1.0",
"@salesforce/plugin-command-reference": "^2.2.8",
"@salesforce/plugin-command-reference": "^1.5.1",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "^1.4.2",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"@salesforce/ts-sinon": "1.4.0",
"@swc/core": "^1.3.16",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.42.0",
"chai": "^4.3.7",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-salesforce": "^1.1.0",
"eslint-config-salesforce-license": "^0.1.6",
"eslint-config-salesforce-typescript": "^1.1.1",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsdoc": "^39.3.14",
"eslint-plugin-sf-plugin": "^1.1.5",
"husky": "^7.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"pretty-quick": "^3.1.0",
"shx": "0.3.4",
"sinon": "10.0.0",
"swc": "^1.0.11",
"ts-node": "^10.4.0",
"ts-node": "^10.0.0",
"typescript": "^4.8.4"
},
"config": {},
Expand All @@ -51,8 +48,7 @@
"files": [
"/lib",
"/messages",
"/oclif.manifest.json",
"/schemas"
"/oclif.manifest.json"
],
"homepage": "https://github.com/salesforcecli/plugin-limits",
"keywords": [
Expand All @@ -75,14 +71,16 @@
"@salesforce/plugin-command-reference"
],
"topics": {
"limits": {
"description": "display current org’s limits",
"force": {
"external": true,
"subtopics": {
"api": {
"description": "display current org’s api limits"
},
"recordcounts": {
"description": "display record counts for the current"
"limits": {
"description": "display current org’s limits",
"subtopics": {
"api": {
"description": "display current org’s api limits"
}
}
}
}
}
Expand All @@ -99,14 +97,13 @@
"format": "sf-format",
"lint": "sf-lint",
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "yarn lint && yarn test:deprecation-policy && yarn test:command-reference && yarn test:json-schema",
"posttest": "yarn lint && yarn test:deprecation-policy && yarn test:command-reference",
"prepack": "sf-prepack",
"prepare": "sf-install",
"pretest": "sf-compile-test",
"test": "sf-test",
"test:command-reference": "./bin/dev commandreference:generate --erroronwarnings",
"test:deprecation-policy": "./bin/dev snapshot:compare",
"test:json-schema": "./bin/dev schema:compare",
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"version": "oclif-dev readme"
},
Expand Down
25 changes: 0 additions & 25 deletions schemas/limits-api-display.json

This file was deleted.

25 changes: 0 additions & 25 deletions schemas/limits-recordcounts-display.json

This file was deleted.

57 changes: 57 additions & 0 deletions src/commands/force/limits/api/display.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 os from 'os';
import { SfdxCommand } from '@salesforce/command';
import { Messages, SfError } from '@salesforce/core';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'display');

type ApiLimit = {
name: string;
max: number;
remaining: number;
};

interface Result {
[key: string]: {
Max: number;
Remaining: number;
};
}

export class LimitsApiDisplayCommand extends SfdxCommand {
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessage('examples').split(os.EOL);
public static readonly requiresUsername = true;

public async run(): Promise<ApiLimit[]> {
try {
const conn = this.org.getConnection();
const geturl = `${conn.instanceUrl}/services/data/v${conn.version}/limits`;
const result = await conn.request<Result>(geturl);
const limits: ApiLimit[] = [];

Object.keys(result).map((limitName) => {
limits.push({
name: limitName,
max: result[limitName].Max,
remaining: result[limitName].Remaining,
});
});

this.ux.table(limits, { name: { header: 'Name' }, remaining: { header: 'Remaining' }, max: { header: 'Max' } });

return limits;
} catch (err) {
if (err instanceof Error || typeof err === 'string') {
throw SfError.wrap(err);
}
throw err;
}
}
}
72 changes: 72 additions & 0 deletions src/commands/force/limits/recordcounts/display.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 os from 'os';
import { flags, FlagsConfig, SfdxCommand, SfdxResult } from '@salesforce/command';
import { Messages, SfError } from '@salesforce/core';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-limits', 'recordcounts');

export interface RecordCount {
name: string;
count: number;
}

interface Result {
sObjects: RecordCount[];
}

export class LimitsRecordCountsDisplayCommand extends SfdxCommand {
public static readonly description = messages.getMessage('commandDescription');
public static readonly examples = messages.getMessage('examples').split(os.EOL);
public static readonly requiresUsername = true;
public static readonly result: SfdxResult = {
tableColumnData: {
name: { header: 'sObject' },
count: { header: 'Record Count' },
},
display() {
if (Array.isArray(this.data) && this.data.length) {
this.ux.table(this.data, this.tableColumnData);
}
},
};

protected static readonly flagsConfig: FlagsConfig = {
sobjecttype: flags.array({
char: 's',
description: messages.getMessage('sobjecttypeFlagDescription'),
}),
};

public async run(): Promise<RecordCount[]> {
try {
const sobjectsPassed = this.flags.sobjecttype as string[];
const sobjectsQuery = sobjectsPassed ? `=${sobjectsPassed.join()}` : '';

const conn = this.org.getConnection();
const geturl = `${conn.baseUrl()}/limits/recordCount?sObjects${sobjectsQuery}`;
const result = await conn.request<Result>(geturl);

// if an object is requested, but there's 0 of them on the server, append that object to the result
if (sobjectsPassed) {
sobjectsPassed.forEach((name) => {
if (!result.sObjects.find((record) => record.name === name)) {
result.sObjects.push({ name, count: 0 });
}
});
}

return result.sObjects;
} catch (err) {
if (err instanceof Error || typeof err === 'string') {
throw SfError.wrap(err);
}
throw err;
}
}
}
Loading