@cparra/apexdocs 3.17.0-beta.6 → 3.17.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.
package/README.md CHANGED
@@ -157,6 +157,8 @@ apexdocs changelog --previousVersionDir force-app-previous --currentVersionDir f
157
157
  | `--lwcGroupName` | N/A | The name under which Lightning Web Components will be grouped in the Reference Guide | `Lightning Web Components` | No |
158
158
  | `--includeFieldSecurityMetadata` | N/A | Whether to include the compliance category and security classification for fields in the generated files. | `false` | No |
159
159
  | `--includeInlineHelpTextMetadata` | N/A | Whether to include the inline help text for fields in the generated files. | `false` | No |
160
+ | `--parallelReflection` | N/A | Parallelize CPU-heavy reflection via worker threads. | `true` | No |
161
+ | `--parallelReflectionMaxWorkers` | N/A | Maximum number of worker threads to use for parallel reflection. Defaults to a reasonable value based on CPU count. | N/A | No |
160
162
 
161
163
  > **Note:** The `*` in the Required column indicates that **one** of the source directory options must be specified:
162
164
  > - `--sourceDir` (single directory or array of directories)
@@ -204,14 +206,16 @@ apexdocs markdown -s force-app -t docs -p global public namespaceaccessible -n M
204
206
 
205
207
  #### Flags
206
208
 
207
- | Flag | Alias | Description | Default | Required |
208
- |----------------|-------|-------------------------------------------------------------------------------|-----------------|----------|
209
- | `--sourceDir` | `-s` | The directory where the source files are located. | N/A | Yes |
210
- | `--targetDir` | `-t` | The directory where the generated files will be placed. | `docs` | No |
211
- | `--fileName` | N/A | The name of the OpenApi file. | `openapi.json` | No |
212
- | `--namespace` | N/A | The package namespace, if any. This will be added to the API file Server Url. | N/A | No |
213
- | `--title` | N/A | The title of the OpenApi file. | `Apex REST API` | No |
214
- | `--apiVersion` | N/A | The version of the API. | `1.0.0` | No |
209
+ | Flag | Alias | Description | Default | Required |
210
+ |----------------------------------|-------|--------------------------------------------------------------------------------------------------|-----------------|----------|
211
+ | `--sourceDir` | `-s` | The directory where the source files are located. | N/A | Yes |
212
+ | `--targetDir` | `-t` | The directory where the generated files will be placed. | `docs` | No |
213
+ | `--fileName` | N/A | The name of the OpenApi file. | `openapi.json` | No |
214
+ | `--namespace` | N/A | The package namespace, if any. This will be added to the API file Server Url. | N/A | No |
215
+ | `--title` | N/A | The title of the OpenApi file. | `Apex REST API` | No |
216
+ | `--apiVersion` | N/A | The version of the API. | `1.0.0` | No |
217
+ | `--parallelReflection` | N/A | Parallelize CPU-heavy reflection via worker threads. | `true` | No |
218
+ | `--parallelReflectionMaxWorkers` | N/A | Maximum number of worker threads to use for parallel reflection. Defaults to a reasonable value. | N/A | No |
215
219
 
216
220
  #### Sample Usage
217
221
 
@@ -225,15 +229,17 @@ apexdocs openapi -s force-app -t docs -n MyNamespace --title "My Custom OpenApi
225
229
 
226
230
  #### Flags
227
231
 
228
- | Flag | Alias | Description | Default | Required |
229
- |----------------------------|-------|--------------------------------------------------------------------------------------|-------------|----------|
230
- | `--previousVersionDir` | `-p` | The directory location of the previous version of the source code. | N/A | Yes |
231
- | `--currentVersionDir` | `-t` | The directory location of the current version of the source code. | N/A | Yes |
232
- | `--targetDir` | `-t` | The directory location where the changelog file will be generated. | `./docs/` | No |
233
- | `--fileName` | N/A | The name of the changelog file to be generated. | `changelog` | No |
234
- | `--scope` | N/A | The list of scope to respect when generating the changelog. | ['global'] | No |
235
- | `--customObjectVisibility` | `-v` | Controls which custom objects are documented. Values should be separated by a space. | ['public'] | No |
236
- | `--skipIfNoChanges` | N/A | Whether to skip generating the changelog if there are no changes. | `true` | No |
232
+ | Flag | Alias | Description | Default | Required |
233
+ |----------------------------------|-------|--------------------------------------------------------------------------------------------------|-------------|----------|
234
+ | `--previousVersionDir` | `-p` | The directory location of the previous version of the source code. | N/A | Yes |
235
+ | `--currentVersionDir` | `-t` | The directory location of the current version of the source code. | N/A | Yes |
236
+ | `--targetDir` | `-t` | The directory location where the changelog file will be generated. | `./docs/` | No |
237
+ | `--fileName` | N/A | The name of the changelog file to be generated. | `changelog` | No |
238
+ | `--scope` | N/A | The list of scope to respect when generating the changelog. | ['global'] | No |
239
+ | `--customObjectVisibility` | `-v` | Controls which custom objects are documented. Values should be separated by a space. | ['public'] | No |
240
+ | `--skipIfNoChanges` | N/A | Whether to skip generating the changelog if there are no changes. | `true` | No |
241
+ | `--parallelReflection` | N/A | Parallelize CPU-heavy reflection via worker threads. | `true` | No |
242
+ | `--parallelReflectionMaxWorkers` | N/A | Maximum number of worker threads to use for parallel reflection. Defaults to a reasonable value. | N/A | No |
237
243
 
238
244
  #### Sample Usage
239
245
 
@@ -577,12 +583,14 @@ public class MyClass {
577
583
 
578
584
  ##### **templates**
579
585
 
580
- Allows providing custom templates for generating Markdown documentation, giving you control over the output format.
586
+ Allows providing custom templates for generating Markdown documentation, giving you control over the output format.
581
587
  You can define templates for each type of metadata
582
588
  supported by the `markdown` command (class, interface, enum, trigger, LWC, custom object, and reference guide) .
583
589
 
584
- For detailed information about creating custom templates, including examples, available helpers, and configuration options,
585
- please refer to the [wiki documentation](https://github.com/cesarParra/apexdocs/wiki/5.-Custom-Templates). You can also find a working example in the
590
+ For detailed information about creating custom templates, including examples, available helpers, and configuration
591
+ options,
592
+ please refer to the [wiki documentation](https://github.com/cesarParra/apexdocs/wiki/5.-Custom-Templates). You can also
593
+ find a working example in the
586
594
  `examples/markdown-custom-templates` directory.
587
595
 
588
596
  #### Changelog Hooks
@@ -2,23 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const node_worker_threads_1 = require("node:worker_threads");
4
4
  const apex_reflection_1 = require("@cparra/apex-reflection");
5
- function isRequestMessage(msg) {
6
- if (!msg || typeof msg !== 'object')
5
+ function isRequestMessage(message) {
6
+ if (!message || typeof message !== 'object') {
7
7
  return false;
8
- const m = msg;
9
- if (typeof m.id !== 'number')
8
+ }
9
+ const candidateMessage = message;
10
+ if (typeof candidateMessage.id !== 'number') {
10
11
  return false;
11
- if (!m.payload || typeof m.payload !== 'object')
12
+ }
13
+ if (!candidateMessage.payload || typeof candidateMessage.payload !== 'object') {
12
14
  return false;
13
- const p = m.payload;
14
- return typeof p.content === 'string';
15
+ }
16
+ const candidatePayload = candidateMessage.payload;
17
+ return typeof candidatePayload.content === 'string';
15
18
  }
16
- function post(msg) {
19
+ function post(responseMessage) {
17
20
  // `parentPort` should always exist in a worker, but guard anyway.
18
21
  if (!node_worker_threads_1.parentPort) {
19
22
  return;
20
23
  }
21
- node_worker_threads_1.parentPort.postMessage(msg);
24
+ node_worker_threads_1.parentPort.postMessage(responseMessage);
22
25
  }
23
26
  function reflectOrThrow(rawSource) {
24
27
  const result = (0, apex_reflection_1.reflect)(rawSource);
@@ -33,25 +36,23 @@ function reflectOrThrow(rawSource) {
33
36
  if (!node_worker_threads_1.parentPort) {
34
37
  throw new Error('apex-reflection.worker started without a parentPort');
35
38
  }
36
- node_worker_threads_1.parentPort.on('message', (msg) => {
37
- if (!isRequestMessage(msg)) {
39
+ node_worker_threads_1.parentPort.on('message', (message) => {
40
+ if (!isRequestMessage(message)) {
38
41
  // Can't correlate without a valid id; ignore.
39
42
  return;
40
43
  }
41
- const { id, payload } = msg;
44
+ const { id, payload } = message;
42
45
  try {
43
46
  const typeMirror = reflectOrThrow(payload.content);
44
47
  post({ id, ok: true, result: typeMirror });
45
48
  }
46
- catch (e) {
47
- const message = (e === null || e === void 0 ? void 0 : e.message) &&
48
- typeof e.message === 'string'
49
- ? e.message
50
- : 'Unknown error';
49
+ catch (caughtError) {
50
+ const candidateMessage = caughtError === null || caughtError === void 0 ? void 0 : caughtError.message;
51
+ const errorMessage = typeof candidateMessage === 'string' ? candidateMessage : 'Unknown error';
51
52
  post({
52
53
  id,
53
54
  ok: false,
54
- error: { message },
55
+ error: { message: errorMessage },
55
56
  });
56
57
  }
57
58
  });
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var logger$1 = require('../logger-PMTbceqG.js');
4
+ var logger$1 = require('../logger-Cr1iCXZc.js');
5
5
  var cosmiconfig = require('cosmiconfig');
6
6
  var yargs = require('yargs');
7
7
  var E = require('fp-ts/Either');
@@ -221,6 +221,16 @@ const openApiOptions = {
221
221
  type: "string",
222
222
  default: logger$1.openApiDefaults.apiVersion,
223
223
  describe: "The version of the OpenApi file."
224
+ },
225
+ parallelReflection: {
226
+ type: "boolean",
227
+ describe: "Parallelize CPU-heavy reflection via worker threads.",
228
+ default: logger$1.openApiDefaults.parallelReflection
229
+ },
230
+ parallelReflectionMaxWorkers: {
231
+ type: "number",
232
+ describe: "Maximum number of worker threads to use for parallel reflection. Defaults to a reasonable value based on CPU count.",
233
+ default: logger$1.openApiDefaults.parallelReflectionMaxWorkers
224
234
  }
225
235
  };
226
236
 
@@ -236,6 +246,16 @@ function validateChangelogArgs(argv) {
236
246
  return true;
237
247
  }
238
248
  const changeLogOptions = {
249
+ parallelReflection: {
250
+ type: "boolean",
251
+ describe: "Parallelize CPU-heavy reflection via worker threads.",
252
+ default: logger$1.markdownDefaults.parallelReflection
253
+ },
254
+ parallelReflectionMaxWorkers: {
255
+ type: "number",
256
+ describe: "Maximum number of worker threads to use for parallel reflection. Defaults to a reasonable value based on CPU count.",
257
+ default: logger$1.markdownDefaults.parallelReflectionMaxWorkers
258
+ },
239
259
  previousVersionDir: {
240
260
  type: "string",
241
261
  array: true,
package/dist/index.d.ts CHANGED
@@ -400,17 +400,7 @@ type CliConfigurableMarkdownConfig = {
400
400
  includeFieldSecurityMetadata: boolean;
401
401
  includeInlineHelpTextMetadata: boolean;
402
402
  experimentalLwcSupport: boolean;
403
-
404
- /**
405
- * Whether to parallelize CPU-heavy reflection steps via worker threads.
406
- * Defaults to true.
407
- */
408
403
  parallelReflection: boolean;
409
-
410
- /**
411
- * Max number of worker threads to use for parallel reflection.
412
- * Defaults to a reasonable value based on CPU count.
413
- */
414
404
  parallelReflectionMaxWorkers?: number;
415
405
  };
416
406
 
@@ -433,6 +423,8 @@ type UserDefinedOpenApiConfig = {
433
423
  title: string;
434
424
  apiVersion: string;
435
425
  exclude: string[];
426
+ parallelReflection: boolean;
427
+ parallelReflectionMaxWorkers?: number;
436
428
  };
437
429
 
438
430
  type UserDefinedChangelogConfig = {
@@ -446,6 +438,8 @@ type UserDefinedChangelogConfig = {
446
438
  exclude: string[];
447
439
  skipIfNoChanges: boolean;
448
440
  translations?: UserTranslations['changelog'];
441
+ parallelReflection: boolean;
442
+ parallelReflectionMaxWorkers?: number;
449
443
  } & Partial<ChangelogConfigurableHooks>;
450
444
 
451
445
  type UserDefinedConfig = UserDefinedMarkdownConfig | UserDefinedOpenApiConfig | UserDefinedChangelogConfig;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var logger = require('./logger-PMTbceqG.js');
4
+ var logger = require('./logger-Cr1iCXZc.js');
5
5
  var E = require('fp-ts/Either');
6
6
  require('fp-ts/function');
7
7
  require('fp-ts/TaskEither');
@@ -1198,21 +1198,6 @@ class WorkerPool {
1198
1198
  this.pump();
1199
1199
  });
1200
1200
  }
1201
- /**
1202
- * Returns current pool stats.
1203
- */
1204
- stats() {
1205
- return {
1206
- maxWorkers: this.maxWorkers,
1207
- activeWorkers: this.allWorkers.size,
1208
- idleWorkers: this.idleWorkers.length,
1209
- queuedTasks: this.queue.length,
1210
- inFlightTasks: this.inFlightByWorker.size,
1211
- createdWorkers: this.createdWorkers,
1212
- completedTasks: this.completedTasks,
1213
- failedTasks: this.failedTasks
1214
- };
1215
- }
1216
1201
  /**
1217
1202
  * Terminates all workers and rejects queued tasks (unless drainOnTerminate=true).
1218
1203
  *
@@ -1277,8 +1262,7 @@ class WorkerPool {
1277
1262
  const idleWorker = this.idleWorkers.pop();
1278
1263
  if (idleWorker) return idleWorker;
1279
1264
  if (this.allWorkers.size < this.maxWorkers) {
1280
- const spawnedWorker = this.spawnWorker();
1281
- return spawnedWorker;
1265
+ return this.spawnWorker();
1282
1266
  }
1283
1267
  return null;
1284
1268
  }
@@ -1460,8 +1444,12 @@ function supportsWorkerThreads() {
1460
1444
  function isWorkerReflectionEnabled(config) {
1461
1445
  var _a, _b;
1462
1446
  const env = ((_a = process.env.APEXDOCS_WORKER_REFLECTION) != null ? _a : "").toLowerCase();
1463
- if (env === "true" || env === "1") return true;
1464
- if (env === "false" || env === "0") return false;
1447
+ if (env === "true" || env === "1") {
1448
+ return true;
1449
+ }
1450
+ if (env === "false" || env === "0") {
1451
+ return false;
1452
+ }
1465
1453
  return (_b = config == null ? void 0 : config.parallelReflection) != null ? _b : true;
1466
1454
  }
1467
1455
  function getWorkerEntrypointPath() {
@@ -1480,16 +1468,13 @@ function reflectAsTaskParallel(apexBundles, config) {
1480
1468
  const maxWorkers = Math.max(1, (_c = config == null ? void 0 : config.parallelReflectionMaxWorkers) != null ? _c : defaultMax);
1481
1469
  const pool = new WorkerPool(() => new node_worker_threads.Worker(getWorkerEntrypointPath()), {
1482
1470
  maxWorkers
1483
- // Keep default queue size (Infinity) unless we later decide to bound it via config.
1484
1471
  });
1485
1472
  try {
1486
- const results = yield Promise.all(
1473
+ return yield Promise.all(
1487
1474
  apexBundles.map((bundle) => __async$5(null, null, function* () {
1488
- const typeMirror = yield pool.run({ content: bundle.content });
1489
- return typeMirror;
1475
+ return yield pool.run({ content: bundle.content });
1490
1476
  }))
1491
1477
  );
1492
- return results;
1493
1478
  } finally {
1494
1479
  yield pool.terminate();
1495
1480
  }
@@ -2184,20 +2169,22 @@ const markdownDefaults = __spreadProps$j(__spreadValues$k({}, markdownAndChangel
2184
2169
  includeFieldSecurityMetadata: false,
2185
2170
  includeInlineHelpTextMetadata: false,
2186
2171
  experimentalLwcSupport: false,
2187
- // Performance: parallel reflection via worker threads (enabled by default).
2188
2172
  parallelReflection: true,
2189
- // Default is computed at runtime if not provided.
2190
2173
  parallelReflectionMaxWorkers: void 0
2191
2174
  });
2192
2175
  const openApiDefaults = __spreadProps$j(__spreadValues$k({}, commonDefaults), {
2193
2176
  fileName: "openapi",
2194
2177
  title: "Apex REST API",
2195
2178
  apiVersion: "1.0.0",
2196
- exclude: []
2179
+ exclude: [],
2180
+ parallelReflection: true,
2181
+ parallelReflectionMaxWorkers: void 0
2197
2182
  });
2198
2183
  const changeLogDefaults = __spreadProps$j(__spreadValues$k({}, markdownAndChangelogDefaults), {
2199
2184
  fileName: "changelog",
2200
- skipIfNoChanges: true
2185
+ skipIfNoChanges: true,
2186
+ parallelReflection: true,
2187
+ parallelReflectionMaxWorkers: void 0
2201
2188
  });
2202
2189
 
2203
2190
  const customObjectTemplate = `
@@ -4758,7 +4745,32 @@ function openApi(logger, fileBodies, config) {
4758
4745
  namespace: config.namespace,
4759
4746
  version: config.apiVersion
4760
4747
  });
4761
- const manifest = createManifest(new RawBodyParser(logger, fileBodies), apply(reflectionWithLogger, logger));
4748
+ const parsedFilesEither = yield reflectApexSource(fileBodies, {
4749
+ parallelReflection: config.parallelReflection,
4750
+ parallelReflectionMaxWorkers: config.parallelReflectionMaxWorkers
4751
+ })();
4752
+ if (E__namespace.isLeft(parsedFilesEither)) {
4753
+ const errors = parsedFilesEither.left;
4754
+ logger.error(errors);
4755
+ return;
4756
+ }
4757
+ const parsedFiles = parsedFilesEither.right;
4758
+ const reflectionByPath = /* @__PURE__ */ new Map();
4759
+ for (const parsed of parsedFiles) {
4760
+ if (!("filePath" in parsed.source)) {
4761
+ continue;
4762
+ }
4763
+ reflectionByPath.set(parsed.source.filePath, { typeMirror: parsed.type });
4764
+ }
4765
+ function reflectFromMap(apexBundle) {
4766
+ const result = reflectionByPath.get(apexBundle.filePath);
4767
+ if (result) {
4768
+ return result;
4769
+ }
4770
+ logger.error(`${apexBundle.filePath} - Parsing error Unknown error`);
4771
+ return { typeMirror: null, error: new Error("Unknown error") };
4772
+ }
4773
+ const manifest = createManifest(new RawBodyParser(logger, fileBodies), reflectFromMap);
4762
4774
  TypesRepository.getInstance().populateAll(manifest.types);
4763
4775
  const filteredTypes = filterByScopes(logger, manifest);
4764
4776
  const processor = new OpenApiDocsProcessor(logger);
@@ -4773,14 +4785,6 @@ function openApi(logger, fileBodies, config) {
4773
4785
  ErrorLogger.logErrors(logger, filteredTypes);
4774
4786
  });
4775
4787
  }
4776
- function reflectionWithLogger(logger, apexBundle) {
4777
- var _a;
4778
- const result = apexReflection.reflect(apexBundle.content);
4779
- if (result.error) {
4780
- logger.error(`${apexBundle.filePath} - Parsing error ${(_a = result.error) == null ? void 0 : _a.message}`);
4781
- }
4782
- return result;
4783
- }
4784
4788
  function filterByScopes(logger, manifest) {
4785
4789
  const filteredTypes = manifest.filteredByAccessModifierAndAnnotations([
4786
4790
  "restresource",
@@ -5434,9 +5438,12 @@ var __async$1 = (__this, __arguments, generator) => {
5434
5438
  step((generator = generator.apply(__this, __arguments)).next());
5435
5439
  });
5436
5440
  };
5437
- const changelogReflectionConfig = {
5438
- parallelReflection: false
5439
- };
5441
+ function changelogReflectionConfig(config) {
5442
+ return {
5443
+ parallelReflection: config.parallelReflection,
5444
+ parallelReflectionMaxWorkers: config.parallelReflectionMaxWorkers
5445
+ };
5446
+ }
5440
5447
  function generateChangeLog(oldBundles, newBundles, config) {
5441
5448
  const convertToPageData = apply(toPageData, config.fileName);
5442
5449
  function handleConversion({ changelog, newManifest }) {
@@ -5467,7 +5474,7 @@ function generateChangeLog(oldBundles, newBundles, config) {
5467
5474
  function reflect(bundles, config) {
5468
5475
  const filterOutOfScopeApex = apply(filterScope, config.scope);
5469
5476
  function reflectApexFiles(sourceFiles) {
5470
- return _function.pipe(reflectApexSource(sourceFiles, changelogReflectionConfig), TE__namespace.map(filterOutOfScopeApex));
5477
+ return _function.pipe(reflectApexSource(sourceFiles, changelogReflectionConfig(config)), TE__namespace.map(filterOutOfScopeApex));
5471
5478
  }
5472
5479
  return _function.pipe(
5473
5480
  // Filter out LWC. These will be implemented at a later date
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "3.17.0-beta.6",
3
+ "version": "3.17.0",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -96,7 +96,7 @@
96
96
  ]
97
97
  },
98
98
  "dependencies": {
99
- "@cparra/apex-reflection": "2.21.1",
99
+ "@cparra/apex-reflection": "2.22.0",
100
100
  "@salesforce/source-deploy-retrieve": "^12.20.1",
101
101
  "@types/js-yaml": "^4.0.9",
102
102
  "@types/yargs": "^17.0.32",