@cparra/apexdocs 3.17.0-beta.3 → 3.17.0-beta.4

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.
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_worker_threads_1 = require("node:worker_threads");
4
+ const apex_reflection_1 = require("@cparra/apex-reflection");
5
+ function isRequestMessage(msg) {
6
+ if (!msg || typeof msg !== 'object')
7
+ return false;
8
+ const m = msg;
9
+ if (typeof m.id !== 'number')
10
+ return false;
11
+ if (!m.payload || typeof m.payload !== 'object')
12
+ return false;
13
+ const p = m.payload;
14
+ return typeof p.content === 'string';
15
+ }
16
+ function post(msg) {
17
+ // `parentPort` should always exist in a worker, but guard anyway.
18
+ if (!node_worker_threads_1.parentPort) {
19
+ return;
20
+ }
21
+ node_worker_threads_1.parentPort.postMessage(msg);
22
+ }
23
+ function reflectOrThrow(rawSource) {
24
+ const result = (0, apex_reflection_1.reflect)(rawSource);
25
+ if (result.typeMirror) {
26
+ return result.typeMirror;
27
+ }
28
+ if (result.error) {
29
+ throw result.error;
30
+ }
31
+ throw new Error('Unknown reflection failure: no typeMirror or error returned.');
32
+ }
33
+ if (!node_worker_threads_1.parentPort) {
34
+ throw new Error('apex-reflection.worker started without a parentPort');
35
+ }
36
+ node_worker_threads_1.parentPort.on('message', (msg) => {
37
+ if (!isRequestMessage(msg)) {
38
+ // Can't correlate without a valid id; ignore.
39
+ return;
40
+ }
41
+ const { id, payload } = msg;
42
+ try {
43
+ const typeMirror = reflectOrThrow(payload.content);
44
+ post({ id, ok: true, result: typeMirror });
45
+ }
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';
51
+ post({
52
+ id,
53
+ ok: false,
54
+ error: { message },
55
+ });
56
+ }
57
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "3.17.0-beta.3",
3
+ "version": "3.17.0-beta.4",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "keywords": [
6
6
  "apex",
@@ -36,7 +36,7 @@
36
36
  "output": []
37
37
  },
38
38
  "build": {
39
- "command": "tsc --noEmit --pretty && pkgroll --target node18 && node -e \"const fs=require('fs'); const path=require('path'); const src=path.join(__dirname,'src','core','reflection','apex','apex-reflection.worker.ts'); const distRoot=path.join(__dirname,'dist'); const candidates=[]; (function walk(dir){ for (const ent of fs.readdirSync(dir,{withFileTypes:true})) { const p=path.join(dir,ent.name); if (ent.isDirectory()) walk(p); else if (ent.isFile() && ent.name==='generate.js') candidates.push(p); } })(distRoot); if (!candidates.length) throw new Error('Could not locate dist bundle to determine worker output location'); const distEntry=candidates[0]; const destDir=path.join(path.dirname(distEntry),'..','core','reflection','apex'); fs.mkdirSync(destDir,{recursive:true}); const out=path.join(destDir,'apex-reflection.worker.js'); const ts=require('typescript'); const input=fs.readFileSync(src,'utf8'); const res=ts.transpileModule(input,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2018,esModuleInterop:true}}); fs.writeFileSync(out,res.outputText,'utf8'); if (!fs.existsSync(out)) throw new Error('Failed to write worker entrypoint');\"",
39
+ "command": "tsc --noEmit --pretty && pkgroll --target node18 && node -e \"const fs=require('fs'); const path=require('path'); const src=path.join(__dirname,'src','core','reflection','apex','apex-reflection.worker.ts'); const distRoot=path.join(__dirname,'dist'); const candidates=[]; (function walk(dir){ for (const ent of fs.readdirSync(dir,{withFileTypes:true})) { const p=path.join(dir,ent.name); if (ent.isDirectory()) walk(p); else if (ent.isFile() && ent.name==='generate.js') candidates.push(p); } })(distRoot); if (!candidates.length) throw new Error('Could not locate dist bundle to determine worker output location'); const distEntry=candidates[0]; const destDir=path.join(path.dirname(distEntry),'..','core','reflection','apex'); fs.mkdirSync(destDir,{recursive:true}); const out=path.join(destDir,'apex-reflection.worker.js'); const ts=require('typescript'); const input=fs.readFileSync(src,'utf8'); const res=ts.transpileModule(input,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2018,esModuleInterop:true}}); fs.writeFileSync(out,res.outputText,'utf8'); if (!fs.existsSync(out)) throw new Error('Failed to write worker entrypoint'); const rootOut=path.join(distRoot,'apex-reflection.worker.js'); fs.copyFileSync(out, rootOut); if (!fs.existsSync(rootOut)) throw new Error('Failed to copy worker entrypoint to dist root');\"",
40
40
  "dependencies": [
41
41
  "lint"
42
42
  ],