Skip to content

Conversation

@mdonnalley
Copy link
Contributor

Adds TTLConfig class for use by sf deploy metadata, sf env create scratch, sf env create sandbox

Example usage:

import { Global, TTLConfig } from '@salesforce/core';
import { Duration } from '@salesforce/kit';

type CachedOptions = {
  api: API;
  'target-org': Org | string;
  'test-level': TestLevel;
  'api-version'?: string;
  'dry-run'?: boolean;
  'ignore-errors'?: boolean;
  'ignore-warnings'?: boolean;
  manifest?: string;
  metadata?: string[];
  'source-dir'?: string[];
  tests?: string[];
  wait?: Duration;
  verbose?: boolean;
};

export class DeployCache extends TTLConfig<TTLConfig.Options, CachedOptions> {
  public static getFileName(): string {
    return 'deploy-cache.json';
  }

  public static getDefaultOptions(): TTLConfig.Options {
    return {
      isGlobal: false,
      isState: true,
      filename: DeployCache.getFileName(),
      stateFolder: Global.SF_STATE_FOLDER,
      ttl: Duration.days(1),
    };
  }
}

[skip-validate-pr]

@mdonnalley mdonnalley self-assigned this Mar 14, 2022
Copy link
Contributor

@peternhale peternhale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdonnalley Tests?

@mdonnalley mdonnalley requested a review from peternhale March 15, 2022 15:05
Copy link
Contributor

@peternhale peternhale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdonnalley thanks for writing the tests!

const sorted = entries.sort(([, valueA], [, valueB]) => {
return new Date(valueB.timestamp).getTime() - new Date(valueA.timestamp).getTime();
});
return sorted[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty cache would throw, but it'd be an index out of range?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd put a test case on the expected empty cache behavior

@mdonnalley mdonnalley requested a review from mshanemc March 18, 2022 15:05
@mdonnalley mdonnalley merged commit e623241 into v3 Mar 21, 2022
@mdonnalley mdonnalley deleted the mdonnalley/ttl-config branch March 21, 2022 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants