Skip to content

Commit

Permalink
feat: type improvements for deployResult
Browse files Browse the repository at this point in the history
* feat: export fileResponse success/failure types

* feat: better typing on id getter

* chore: bump to testkit 3 and other dep updates

* fix: directoryName is always there

* test: new required dirname

* chore: auto-update metadata coverage in METADATA_SUPPORT.md

* test: record perf

* revert: don't require directoryName because it breaks plugin-source

* test: record perf

* chore: remove commitizen-related stuff

* test: record perf

* chore: bump testkit

* test: record perf

Co-authored-by: svc-cli-bot <svc_cli_bot@salesforce.com>
Co-authored-by: Peter Hale <peter.hale@salesforce.com>
  • Loading branch information
3 people authored Jan 9, 2023
1 parent 0306742 commit b961860
Show file tree
Hide file tree
Showing 29 changed files with 298 additions and 1,714 deletions.
22 changes: 3 additions & 19 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,13 @@
"args": ["run", "commit"],
"isBackground": false
},
{
"label": "Commitizen Initialization",
"command": "yarn",
"type": "shell",
"presentation": {
"focus": false,
"panel": "shared"
},
"args": ["run", "commit-init"],
"isBackground": false
},

{
"label": "Create Change Log",
"command": "./scripts/change-log-generator.js",
"type": "shell",
"args": [
"${input:verboseOutput}",
"-r",
"${input:publishType}",
"-t",
"${input:date}"
]
},
"args": ["${input:verboseOutput}", "-r", "${input:publishType}", "-t", "${input:date}"]
}
],
"inputs": [
{
Expand Down
960 changes: 201 additions & 759 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022, Salesforce.com, Inc.
Copyright (c) 2023, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
3 changes: 2 additions & 1 deletion METADATA_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This list compares metadata types found in Salesforce v57 with the [metadata reg

This repository is used by both the Salesforce CLIs and Salesforce's VSCode Extensions.

Currently, there are 499/534 supported metadata types.
Currently, there are 500/535 supported metadata types.
For status on any existing gaps, please search or file an issue in the [Salesforce CLI issues only repo](https://github.com/forcedotcom/cli/issues).
To contribute a new metadata type, please see the [Contributing Metadata Types to the Registry](./contributing/metadata.md)

Expand Down Expand Up @@ -109,6 +109,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|ChatterEmailsMDSettings|||
|ChatterExtension|||
|ChatterSettings|||
|ClaimFinancialSettings|||
|ClauseCatgConfiguration|||
|CleanDataService|||
|CollectionsDashboardSettings|||
Expand Down
1 change: 0 additions & 1 deletion contributing/commit-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ Ignore warnings and CLI update messages when using --json (#406)

### Committing

1. We enforce commit message format. We recommend using [commitizen](https://github.com/commitizen/cz-cli) by installing it with `npm install -g commitizen` and running `npm run commit-init`. When you commit, we recommend that you use `npm run commit` which will prompt you with a series of questions to format the commit message. Or you can use our VS Code Task `Commit`.
1. The commit message format that we expect is: `type: commit message`. Valid types are: feat, fix, improvement, docs, style, refactor, perf, test, build, ci, chore and revert.
1. Before commit and push, husky will run several hooks to ensure the commit message is in the correct format and that everything lints and compiles properly.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"unzipper": "0.10.11"
},
"devDependencies": {
"@salesforce/cli-plugins-testkit": "^2.5.3",
"@salesforce/cli-plugins-testkit": "^3.2.16",
"@salesforce/dev-config": "^3.0.1",
"@salesforce/dev-scripts": "^3.1.0",
"@salesforce/prettier-config": "^0.0.2",
Expand All @@ -55,7 +55,6 @@
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.46.1",
"chai": "^4.3.7",
"commitizen": "^3.1.2",
"deep-equal-in-any-order": "^1.1.19",
"deepmerge": "^4.2.2",
"eslint": "^8.30.0",
Expand Down Expand Up @@ -84,8 +83,6 @@
"ci-docs": "yarn sf-ci-docs",
"clean": "sf-clean",
"clean-all": "sf-clean all",
"commit": "git-cz",
"commit-init": "commitizen init cz-conventional-changelog --save-dev --save-exact --force",
"compile": "sf-compile",
"coverage": "nyc report --reporter=lcov",
"docs": "sf-docs",
Expand Down Expand Up @@ -117,4 +114,4 @@
"yarn": "1.22.4"
},
"config": {}
}
}
2 changes: 2 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export {
ComponentRetrieval,
ComponentDiagnostic,
FileResponse,
FileResponseFailure,
FileResponseSuccess,
AsyncResult,
RequestStatus,
MetadataRequestStatus,
Expand Down
6 changes: 5 additions & 1 deletion src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ export interface MetadataApiDeployOptions extends MetadataTransferOptions {
mdapiPath?: string;
}

export class MetadataApiDeploy extends MetadataTransfer<MetadataApiDeployStatus, DeployResult> {
export class MetadataApiDeploy extends MetadataTransfer<
MetadataApiDeployStatus,
DeployResult,
MetadataApiDeployOptions
> {
public static readonly DEFAULT_OPTIONS: Partial<MetadataApiDeployOptions> = {
apiOptions: {
rollbackOnError: true,
Expand Down
6 changes: 5 additions & 1 deletion src/client/metadataApiRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ export class RetrieveResult implements MetadataTransferResult {
}
}

export class MetadataApiRetrieve extends MetadataTransfer<MetadataApiRetrieveStatus, RetrieveResult> {
export class MetadataApiRetrieve extends MetadataTransfer<
MetadataApiRetrieveStatus,
RetrieveResult,
MetadataApiRetrieveOptions
> {
public static DEFAULT_OPTIONS: Partial<MetadataApiRetrieveOptions> = { merge: false };
private options: MetadataApiRetrieveOptions;
private orgId: string;
Expand Down
11 changes: 8 additions & 3 deletions src/client/metadataTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export interface MetadataTransferOptions {
id?: string;
}

export abstract class MetadataTransfer<Status extends MetadataRequestStatus, Result extends MetadataTransferResult> {
export abstract class MetadataTransfer<
Status extends MetadataRequestStatus,
Result extends MetadataTransferResult,
Options extends MetadataTransferOptions
> {
protected components: ComponentSet;
protected logger: Logger;
protected canceled = false;
Expand All @@ -42,15 +46,16 @@ export abstract class MetadataTransfer<Status extends MetadataRequestStatus, Res
private usernameOrConnection: string | Connection;
private apiVersion: string;

public constructor({ usernameOrConnection, components, apiVersion, id }: MetadataTransferOptions) {
public constructor({ usernameOrConnection, components, apiVersion, id }: Options) {
this.usernameOrConnection = usernameOrConnection;
this.components = components;
this.apiVersion = apiVersion;
this.transferId = id;
this.logger = Logger.childFromRoot(this.constructor.name);
}

public get id(): string | undefined {
// if you passed in an id, you don't have to worry about whether there'll be one if you ask for it
public get id(): Options['id'] extends MetadataTransferOptions['id'] ? string : string | undefined {
return this.transferId;
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ interface FileResponseBase {
filePath?: string;
}

interface FileResponseSuccess extends FileResponseBase {
export interface FileResponseSuccess extends FileResponseBase {
state: Exclude<ComponentStatus, ComponentStatus.Failed>;
}

interface FileResponseFailure extends FileResponseBase {
export interface FileResponseFailure extends FileResponseBase {
state: ComponentStatus.Failed;
lineNumber?: number;
columnNumber?: number;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export {
ComponentRetrieval,
ComponentDiagnostic,
FileResponse,
FileResponseFailure,
FileResponseSuccess,
AsyncResult,
RequestStatus,
MetadataRequestStatus,
Expand Down
4 changes: 2 additions & 2 deletions test/client/metadataTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { expect } from 'chai';
import { Duration, sleep } from '@salesforce/kit';
import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup';
import { ComponentSet } from '../../src';
import { MetadataTransfer } from '../../src/client/metadataTransfer';
import { MetadataTransfer, MetadataTransferOptions } from '../../src/client/metadataTransfer';
import { MetadataRequestStatus, MetadataTransferResult, RequestStatus } from '../../src/client/types';

Messages.importMessagesDirectory(__dirname);
Expand All @@ -21,7 +21,7 @@ describe('MetadataTransfer', () => {
const $$ = new TestContext();
const testOrg = new MockTestOrgData();

class TestTransfer extends MetadataTransfer<MetadataRequestStatus, MetadataTransferResult> {
class TestTransfer extends MetadataTransfer<MetadataRequestStatus, MetadataTransferResult, MetadataTransferOptions> {
public request = { done: true, status: RequestStatus.Succeeded, id: '1', success: true };
public lifecycle = {
pre: $$.SANDBOX.stub().returns({ id: '1' }),
Expand Down
1 change: 1 addition & 0 deletions test/mock/client/transferOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export async function stubMetadataDeploy(
const deployRestStub = sandbox.stub(connection.metadata, 'deployRest');
const pollingClientSpy = sandbox.spy(PollingClient, 'create');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { rest, ...defaultOptions } = MetadataApiDeploy.DEFAULT_OPTIONS.apiOptions;
deployRestStub.withArgs(zipBuffer, options.apiOptions ?? defaultOptions).resolves(MOCK_ASYNC_RESULT);

Expand Down
2 changes: 1 addition & 1 deletion test/nuts/local/replacements/replacements.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('e2e replacements test', () => {
project: {
sourceDir: path.join('test', 'nuts', 'local', 'replacements', 'testProj'),
},
authStrategy: 'NONE',
devhubAuthStrategy: 'NONE',
});
// Hack: rewrite the file replacement locations relative to the project
const projectJsonPath = path.join(session.project.dir, 'sfdx-project.json');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 319.0109829999856
"duration": 263.16896799999813
},
{
"name": "sourceToMdapi",
"duration": 6513.529799000011
"duration": 6221.79634700001
},
{
"name": "sourceToZip",
"duration": 4981.738588999986
"duration": 5822.086768000008
},
{
"name": "mdapiToSource",
"duration": 5392.311745999992
"duration": 4840.970211999986
}
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 589.6669420000399
"duration": 611.8538340000086
},
{
"name": "sourceToMdapi",
"duration": 10443.746392000001
"duration": 10831.910629999998
},
{
"name": "sourceToZip",
"duration": 9044.706978000002
"duration": 9510.525854000007
},
{
"name": "mdapiToSource",
"duration": 6968.501856999996
"duration": 7041.551112999994
}
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 1047.5124270000379
"duration": 1035.1475429999991
},
{
"name": "sourceToMdapi",
"duration": 15948.696778000041
"duration": 16139.942532999994
},
{
"name": "sourceToZip",
"duration": 13894.535199999984
"duration": 12259.295870000002
},
{
"name": "mdapiToSource",
"duration": 15508.926563000015
"duration": 15514.132654999994
}
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 215.97936900000786
"duration": 207.19687800000247
},
{
"name": "sourceToMdapi",
"duration": 6050.905942000012
"duration": 6143.916331
},
{
"name": "sourceToZip",
"duration": 4974.103418000013
"duration": 4272.227289999995
},
{
"name": "mdapiToSource",
"duration": 3734.206409000006
"duration": 3816.659138999996
}
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 408.8743680000189
"duration": 422.58825500000967
},
{
"name": "sourceToMdapi",
"duration": 9369.04411799999
"duration": 8270.173566000012
},
{
"name": "sourceToZip",
"duration": 7376.75736399999
"duration": 7299.296593000006
},
{
"name": "mdapiToSource",
"duration": 4596.248850000004
"duration": 4143.821972000005
}
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 712.6530869999551
"duration": 726.9991250000021
},
{
"name": "sourceToMdapi",
"duration": 11910.565894
"duration": 12085.568279999978
},
{
"name": "sourceToZip",
"duration": 13902.21678899997
"duration": 10396.505495999998
},
{
"name": "mdapiToSource",
"duration": 13933.210705999983
"duration": 14038.407707999984
}
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 200.72280899999896
"duration": 196.28944300000148
},
{
"name": "sourceToMdapi",
"duration": 4991.547512999998
"duration": 5138.501059999995
},
{
"name": "sourceToZip",
"duration": 5128.423543000012
"duration": 4118.841407
},
{
"name": "mdapiToSource",
"duration": 3427.0605170000053
"duration": 3295.1601250000094
}
]
Loading

0 comments on commit b961860

Please sign in to comment.