@cparra/apex-reflection 2.23.11 → 2.23.12

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/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export declare function reflect(declarationBody: string): ReflectionResult;
2
2
  export declare function reflectTrigger(declarationBody: string): TriggerReflectionResult;
3
+ export declare function reflectAsync(declarationBody: string): Promise<ReflectionResult>;
4
+ export declare function reflectTriggerAsync(declarationBody: string): Promise<TriggerReflectionResult>;
3
5
  export interface ParamAnnotation {
4
6
  bodyLines: string[];
5
7
  paramName: string;
package/dist/index.js CHANGED
@@ -3,10 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.reflectTrigger = exports.reflect = void 0;
6
+ exports.reflectTriggerAsync = exports.reflectAsync = exports.reflectTrigger = exports.reflect = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const child_process_1 = require("child_process");
10
+ let _outJs = null;
11
+ function getOutJs() {
12
+ if (_outJs)
13
+ return _outJs;
14
+ require("./out.js");
15
+ const g = globalThis;
16
+ const selfObj = g?.self ?? g;
17
+ _outJs = {
18
+ reflect: selfObj?.reflect,
19
+ reflectAsync: selfObj?.reflectAsync,
20
+ reflectTrigger: selfObj?.reflectTrigger,
21
+ reflectTriggerAsync: selfObj?.reflectTriggerAsync,
22
+ };
23
+ return _outJs;
24
+ }
10
25
  function resolveNativeBinaryPath() {
11
26
  const platform = process.platform;
12
27
  const arch = process.arch;
@@ -33,14 +48,21 @@ function resolveNativeBinaryPath() {
33
48
  // dev flow builds to: dist/native/<platform-arch>/<fileName>
34
49
  // (same place), but keep this explicit so we can evolve paths later.
35
50
  const devBuiltPath = downloadedPath;
36
- if (fs_1.default.existsSync(downloadedPath)) {
51
+ if (fs_1.default.existsSync(downloadedPath))
37
52
  return downloadedPath;
38
- }
39
- if (fs_1.default.existsSync(devBuiltPath)) {
53
+ if (fs_1.default.existsSync(devBuiltPath))
40
54
  return devBuiltPath;
41
- }
42
55
  throw new Error(`Native binary not found. Expected one of:\n- ${downloadedPath}\n- ${devBuiltPath}\n\nIf you just installed this package, ensure postinstall succeeded.\nIf you're developing locally, run the dev build to create the host binary.`);
43
56
  }
57
+ function hasNativeBinary() {
58
+ try {
59
+ resolveNativeBinaryPath();
60
+ return true;
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ }
44
66
  function reflectFor(type, declarationBody) {
45
67
  const binaryPath = resolveNativeBinaryPath();
46
68
  const result = (0, child_process_1.spawnSync)(binaryPath, [`--type=${type}`], {
@@ -61,6 +83,13 @@ function reflectFor(type, declarationBody) {
61
83
  return stdout;
62
84
  }
63
85
  function reflect(declarationBody) {
86
+ if (!hasNativeBinary()) {
87
+ const self = getOutJs();
88
+ if (!self.reflect) {
89
+ throw new Error("Native binary not found and out.js fallback does not export `reflect`.");
90
+ }
91
+ return JSON.parse(self.reflect(declarationBody));
92
+ }
64
93
  const stdout = reflectFor("reflectType", declarationBody);
65
94
  try {
66
95
  return JSON.parse(stdout);
@@ -71,6 +100,13 @@ function reflect(declarationBody) {
71
100
  }
72
101
  exports.reflect = reflect;
73
102
  function reflectTrigger(declarationBody) {
103
+ if (!hasNativeBinary()) {
104
+ const self = getOutJs();
105
+ if (!self.reflectTrigger) {
106
+ throw new Error("Native binary not found and out.js fallback does not export `reflectTrigger`.");
107
+ }
108
+ return JSON.parse(self.reflectTrigger(declarationBody));
109
+ }
74
110
  const stdout = reflectFor("reflectTrigger", declarationBody);
75
111
  try {
76
112
  return JSON.parse(stdout);
@@ -80,3 +116,27 @@ function reflectTrigger(declarationBody) {
80
116
  }
81
117
  }
82
118
  exports.reflectTrigger = reflectTrigger;
119
+ async function reflectAsync(declarationBody) {
120
+ if (!hasNativeBinary()) {
121
+ const self = getOutJs();
122
+ if (!self.reflectAsync) {
123
+ throw new Error("Native binary not found and out.js fallback does not export `reflectAsync`.");
124
+ }
125
+ return JSON.parse(await self.reflectAsync(declarationBody));
126
+ }
127
+ // Native binary path is sync (spawnSync). Keep API available by resolving immediately.
128
+ return reflect(declarationBody);
129
+ }
130
+ exports.reflectAsync = reflectAsync;
131
+ async function reflectTriggerAsync(declarationBody) {
132
+ if (!hasNativeBinary()) {
133
+ const self = getOutJs();
134
+ if (!self.reflectTriggerAsync) {
135
+ throw new Error("Native binary not found and out.js fallback does not export `reflectTriggerAsync`.");
136
+ }
137
+ return JSON.parse(await self.reflectTriggerAsync(declarationBody));
138
+ }
139
+ // Native binary path is sync (spawnSync). Keep API available by resolving immediately.
140
+ return reflectTrigger(declarationBody);
141
+ }
142
+ exports.reflectTriggerAsync = reflectTriggerAsync;