@salesforce/packaging 2.1.10 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,29 @@ import { Connection, SfProject } from '@salesforce/core';
2
2
  import { Duration } from '@salesforce/kit';
3
3
  import { PackageSaveResult, PackageType, PackageVersionCreateOptions, PackageVersionCreateRequestQueryOptions, PackageVersionCreateRequestResult, PackageVersionOptions, PackageVersionReportResult, PackageVersionUpdateOptions, PackagingSObjects } from '../interfaces';
4
4
  type Package2Version = PackagingSObjects.Package2Version;
5
- export declare const Package2VersionFields: string[];
5
+ export declare const Package2VersionFields: Array<keyof Package2Version>;
6
+ export type Package2VersionFieldTypes = Array<(typeof Package2VersionFields)[number]>;
7
+ export type Package2VersionQueryOptions = {
8
+ /**
9
+ * The fields to include in the returned data. Defaults to all fields.
10
+ */
11
+ fields?: Package2VersionFieldTypes;
12
+ /**
13
+ * The where clause to filter the query. E.g., "WHERE Id IN ('%IDS%')";
14
+ */
15
+ whereClause?: string;
16
+ /**
17
+ * An array of where clause items to match. The query is chunked,meaning broken into
18
+ * multiple queries when the query length would exceed the maximum char limit.
19
+ * When defining items here, the `whereClause` argument must use this token for the
20
+ * item replacement: `'%IDS%'`.
21
+ */
22
+ whereClauseItems?: string[];
23
+ /**
24
+ * The order-by clause for the query. Defaults to LastModifiedDate descending.
25
+ */
26
+ orderBy?: string;
27
+ };
6
28
  /**
7
29
  * Provides the ability to create, update, delete, and promote 2nd
8
30
  * generation package versions.
@@ -94,6 +116,18 @@ export declare class PackageVersion {
94
116
  frequency: Duration;
95
117
  timeout: Duration;
96
118
  }): Promise<PackageVersionCreateRequestResult>;
119
+ /**
120
+ * Query the Package2Version SObject and return data with the provided type.
121
+ *
122
+ * NOTE: There is a limit of 2000 records that can be returned, otherwise
123
+ * a GACK might be thrown. If more than 2000 records are desired you should
124
+ * filter the query by date and aggregate all results.
125
+ *
126
+ * @param connection jsForce Connection to the org.
127
+ * @param options Package2Version query options
128
+ * @returns Results from querying the Package2Version SObject.
129
+ */
130
+ static queryPackage2Version(connection: Connection, options?: Package2VersionQueryOptions): Promise<Partial<Package2Version[]>>;
97
131
  /**
98
132
  * Get the package version ID for this PackageVersion.
99
133
  *
@@ -283,6 +283,37 @@ class PackageVersion {
283
283
  throw (0, packageUtils_1.applyErrorAction)(err);
284
284
  }
285
285
  }
286
+ /**
287
+ * Query the Package2Version SObject and return data with the provided type.
288
+ *
289
+ * NOTE: There is a limit of 2000 records that can be returned, otherwise
290
+ * a GACK might be thrown. If more than 2000 records are desired you should
291
+ * filter the query by date and aggregate all results.
292
+ *
293
+ * @param connection jsForce Connection to the org.
294
+ * @param options Package2Version query options
295
+ * @returns Results from querying the Package2Version SObject.
296
+ */
297
+ static async queryPackage2Version(connection, options = {}) {
298
+ const fields = options.fields ?? exports.Package2VersionFields;
299
+ const { whereClause, whereClauseItems } = options;
300
+ const orderBy = options.orderBy ?? 'ORDER BY LastModifiedDate DESC';
301
+ let query = `SELECT ${fields.toString()} FROM Package2Version`;
302
+ if (whereClause) {
303
+ query += ` ${whereClause} ${orderBy}`;
304
+ if (whereClauseItems) {
305
+ query += ' LIMIT 2000';
306
+ return (0, packageUtils_1.queryWithInConditionChunking)(query, whereClauseItems, '%IDS%', connection);
307
+ }
308
+ }
309
+ query += ' LIMIT 2000';
310
+ const result = await connection.tooling.query(query);
311
+ if (result?.totalSize === 2000) {
312
+ const warningMsg = messages.getMessage('maxPackage2VersionRecords');
313
+ await core_1.Lifecycle.getInstance().emitWarning(warningMsg);
314
+ }
315
+ return result.records ?? [];
316
+ }
286
317
  /**
287
318
  * Get the package version ID for this PackageVersion.
288
319
  *
@@ -1 +1 @@
1
- export { INSTALL_URL_BASE, getContainerOptions, getPackageVersionStrings } from './packageUtils';
1
+ export { INSTALL_URL_BASE, getContainerOptions, getPackageVersionStrings, getPackageVersionNumber, } from './packageUtils';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPackageVersionStrings = exports.getContainerOptions = exports.INSTALL_URL_BASE = void 0;
3
+ exports.getPackageVersionNumber = exports.getPackageVersionStrings = exports.getContainerOptions = exports.INSTALL_URL_BASE = void 0;
4
4
  /*
5
5
  * Copyright (c) 2022, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -11,4 +11,5 @@ var packageUtils_1 = require("./packageUtils");
11
11
  Object.defineProperty(exports, "INSTALL_URL_BASE", { enumerable: true, get: function () { return packageUtils_1.INSTALL_URL_BASE; } });
12
12
  Object.defineProperty(exports, "getContainerOptions", { enumerable: true, get: function () { return packageUtils_1.getContainerOptions; } });
13
13
  Object.defineProperty(exports, "getPackageVersionStrings", { enumerable: true, get: function () { return packageUtils_1.getPackageVersionStrings; } });
14
+ Object.defineProperty(exports, "getPackageVersionNumber", { enumerable: true, get: function () { return packageUtils_1.getPackageVersionNumber; } });
14
15
  //# sourceMappingURL=index.js.map
@@ -65,7 +65,18 @@ export declare function getContainerOptions(packageIds: string | undefined | Arr
65
65
  * @param connection For tooling query
66
66
  */
67
67
  export declare function getPackageVersionStrings(subscriberPackageVersionIds: string[], connection: Connection): Promise<Map<string, string>>;
68
- export declare function getPackageVersionNumber(package2VersionObj: PackagingSObjects.Package2Version): string;
68
+ /**
69
+ * For queries with an IN condition, determine if the WHERE clause will exceed
70
+ * SOQL's 4000 character limit. Perform multiple queries as needed to stay below the limit.
71
+ *
72
+ * @return concatenated array of records returned from the resulting query(ies)
73
+ * @param query The full query to execute containing the replaceToken param in its IN clause
74
+ * @param items The IN clause items. A length-appropriate single-quoted comma-separated string chunk will be made from the items.
75
+ * @param replaceToken A placeholder in the query's IN condition that will be replaced with the chunked items
76
+ * @param connection For tooling query
77
+ */
78
+ export declare function queryWithInConditionChunking<T extends Record<string, unknown> = Record<string, unknown>>(query: string, items: string[], replaceToken: string, connection: Connection): Promise<T[]>;
79
+ export declare function getPackageVersionNumber(package2VersionObj: PackagingSObjects.Package2Version, includeBuild?: boolean): string;
69
80
  /**
70
81
  * Generate package alias json entry for this package version that can be written to sfdx-project.json
71
82
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPackageDirectoryEffectivelyEmpty = exports.replaceIfEmpty = exports.copyDescriptorProperties = exports.copyDir = exports.zipDir = exports.numberToDuration = exports.combineSaveErrors = exports.generatePackageAliasEntry = exports.getPackageVersionNumber = exports.getPackageVersionStrings = exports.getContainerOptions = exports.escapeInstallationKey = exports.getPackageVersionId = exports.massageErrorMessage = exports.applyErrorAction = exports.validateIdNoThrow = exports.validateId = exports.uniqid = exports.BY_LABEL = exports.DEFAULT_PACKAGE_DIR = exports.POLL_INTERVAL_SECONDS = exports.INSTALL_URL_BASE = exports.VERSION_NUMBER_SEP = void 0;
3
+ exports.isPackageDirectoryEffectivelyEmpty = exports.replaceIfEmpty = exports.copyDescriptorProperties = exports.copyDir = exports.zipDir = exports.numberToDuration = exports.combineSaveErrors = exports.generatePackageAliasEntry = exports.getPackageVersionNumber = exports.queryWithInConditionChunking = exports.getPackageVersionStrings = exports.getContainerOptions = exports.escapeInstallationKey = exports.getPackageVersionId = exports.massageErrorMessage = exports.applyErrorAction = exports.validateIdNoThrow = exports.validateId = exports.uniqid = exports.BY_LABEL = exports.DEFAULT_PACKAGE_DIR = exports.POLL_INTERVAL_SECONDS = exports.INSTALL_URL_BASE = exports.VERSION_NUMBER_SEP = void 0;
4
4
  /*
5
5
  * Copyright (c) 2022, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -268,6 +268,7 @@ async function queryWithInConditionChunking(query, items, replaceToken, connecti
268
268
  }
269
269
  return records;
270
270
  }
271
+ exports.queryWithInConditionChunking = queryWithInConditionChunking;
271
272
  /**
272
273
  * Returns the number of items that can be included in a quoted comma-separated string (e.g., "'item1','item2'") not exceeding maxLength
273
274
  */
@@ -295,9 +296,9 @@ function getInClauseItemsCount(items, startIndex, maxLength) {
295
296
  function concatVersion(major, minor, patch, build) {
296
297
  return [major, minor, patch, build].map((part) => (part ? `${part}` : '0')).join('.');
297
298
  }
298
- function getPackageVersionNumber(package2VersionObj) {
299
- const version = concatVersion(package2VersionObj.MajorVersion, package2VersionObj.MinorVersion, package2VersionObj.PatchVersion, undefined);
300
- return version.slice(0, version.lastIndexOf('.'));
299
+ function getPackageVersionNumber(package2VersionObj, includeBuild = false) {
300
+ const version = concatVersion(package2VersionObj.MajorVersion, package2VersionObj.MinorVersion, package2VersionObj.PatchVersion, includeBuild ? package2VersionObj.BuildNumber : undefined);
301
+ return includeBuild ? version : version.slice(0, version.lastIndexOf('.'));
301
302
  }
302
303
  exports.getPackageVersionNumber = getPackageVersionNumber;
303
304
  /**
@@ -17,3 +17,7 @@ The package version create result ID must be defined when checking for completio
17
17
  # errorNoSubscriberPackageVersionId
18
18
 
19
19
  Could not fetch the subscriber package version ID (04t).
20
+
21
+ # maxPackage2VersionRecords
22
+
23
+ The maximum result size (2000) was reached when querying the Package2Version SObject. This means there could be more records that were not returned by the query. If all records are required you may have to break the query into multiple requests filtered by date, then aggregate the results.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/packaging",
3
- "version": "2.1.10",
3
+ "version": "2.2.0",
4
4
  "description": "Packaging library for the Salesforce packaging platform",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -44,7 +44,7 @@
44
44
  "@oclif/core": "^2.8.7",
45
45
  "@salesforce/core": "^4.3.2",
46
46
  "@salesforce/kit": "^3.0.3",
47
- "@salesforce/schemas": "^1.5.1",
47
+ "@salesforce/schemas": "^1.6.0",
48
48
  "@salesforce/source-deploy-retrieve": "^8.6.0",
49
49
  "@salesforce/ts-types": "^2.0.3",
50
50
  "@xmldom/xmldom": "^0.8.8",
@@ -70,17 +70,17 @@
70
70
  "@types/jszip": "^3.4.1",
71
71
  "@types/xml2js": "^0.4.11",
72
72
  "@typescript-eslint/eslint-plugin": "^5.60.0",
73
- "@typescript-eslint/parser": "^5.60.0",
73
+ "@typescript-eslint/parser": "^5.60.1",
74
74
  "chai": "^4.3.7",
75
75
  "commitizen": "^4.2.6",
76
- "eslint": "^8.43.0",
76
+ "eslint": "^8.44.0",
77
77
  "eslint-config-prettier": "^8.8.0",
78
78
  "eslint-config-salesforce": "^2.0.1",
79
79
  "eslint-config-salesforce-license": "^0.2.0",
80
80
  "eslint-config-salesforce-typescript": "^1.1.1",
81
81
  "eslint-plugin-header": "3.1.1",
82
82
  "eslint-plugin-import": "^2.27.5",
83
- "eslint-plugin-jsdoc": "^44.2.4",
83
+ "eslint-plugin-jsdoc": "^44.2.7",
84
84
  "eslint-plugin-sf-plugin": "^1.15.9",
85
85
  "husky": "^8.0.3",
86
86
  "mocha": "^10.2.0",