@cparra/apex-reflection 4.0.0-beta.4 → 4.0.0-beta.5

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
@@ -11,13 +11,12 @@ npm i @cparra/apex-reflection
11
11
  ## Usage
12
12
 
13
13
  This library exposes a single function that handles parsing the body of an Apex top level type (class, interface, or
14
- enum)
15
- and returns the result.
14
+ enum) and returns the result.
16
15
 
17
16
  ```typescript
18
- import {reflect} from '@cparra/apex-reflection';
17
+ import { reflect } from "@cparra/apex-reflection";
19
18
 
20
- const classBody = 'public with sharing class ExampleClass {}';
19
+ const classBody = "public with sharing class ExampleClass {}";
21
20
  const response = reflect(classBody);
22
21
  ```
23
22
 
@@ -34,23 +33,33 @@ const response = reflect(rawFile.toString());
34
33
  ```
35
34
 
36
35
  The `reflect` function returns a `ReflectionResult` which contains either the results of the parsed `Type`
37
- (which will either be a `ClassMirror`, an `InterfaceMirror` or an `EnumMirror`) or a `ParsingError` if the passed in
36
+ (which will either be a `ClassMirror`, an `InterfaceMirror`, or an `EnumMirror`) or a `ParsingError` if the passed in
38
37
  body was not parsed successfully, with a message indicating where the error occurred.
39
38
 
40
39
  ## Contributing
41
40
 
42
41
  Even though this library is exposed as a Node.js library, the project's source code is written in Dart. The source can
43
- be found in the `lib/src` directory.
42
+ be found in the `lib/src` directory of the repository.
43
+
44
+ This package ships the Dart code compiled to a WebAssembly module (`dist/node.wasm`) together with its JS loader
45
+ (`dist/node.mjs`), loaded lazily by the thin TypeScript wrapper in `index.mts`. Node.js 22 or newer is required (the
46
+ module uses WasmGC). To rebuild the module after changing the Dart source, run from the repository root:
47
+
48
+ ```shell
49
+ dart compile wasm lib/src/node/node.dart -o js/node.wasm
50
+ ```
51
+
52
+ `npm run build` compiles the TypeScript wrapper and copies the wasm module and its loader into `dist/`.
44
53
 
45
54
  ### Tests
46
55
 
47
- Both the Dart source code and the JS output must be tested.
56
+ Both the Dart source code and the packaged WebAssembly module must be tested.
48
57
 
49
- The Dart tests live in the `test` directory. The Dart source code must have unit tests testing each individual Dart file
50
- as well as end-to-end tests that verify the overall parsing functionality.
58
+ The Dart tests live in the repository's `test` directory. The Dart source code must have unit tests testing each
59
+ individual Dart file as well as end-to-end tests that verify the overall parsing functionality.
51
60
 
52
- The JS tests live in `js/apex-reflection-node/__tests__`. These are end-to-end tests that ensure that the transpiled JS
53
- code is working as intended.
61
+ The JS tests live in `__tests__`. These are end-to-end tests that run against the built package (`dist/`), so they
62
+ also guard against publishing a stale WebAssembly artifact. Run them with `npm test`.
54
63
 
55
64
  ### JSON serialization
56
65
 
@@ -62,27 +71,16 @@ helps automatically create the round-trip code for serialization and de-serializ
62
71
 
63
72
  When changing any of the model classes with serialization support, to re-build the serialization code run
64
73
 
65
- ```
66
- pub run build_runner build
67
- ```
68
-
69
- ### Parsing
70
-
71
- The parsing algorithm relies on using ANTLR4 and its Dart target. Currently `dart2js` is not able to transpile the
72
- source from the `antrl4` library hosted in pub.dev, so we rely on a local copy that fixes the transpilation issues,
73
- which lives in `lib/antrl4-4.9.2`.
74
-
75
- To generate the Antlr4 Apex output run:
76
-
77
74
  ```shell
78
- antlr4 -Dlanguage=Dart lib/src/antlr/grammars/apex/ApexLexer.g4 lib/src/antlr/grammars/apex/ApexParser.g4 -o lib/src/antlr/lib/apex/
75
+ dart run build_runner build
79
76
  ```
80
77
 
81
- To generate the Antlr4 Apexdoc output run:
78
+ ### Parsing
82
79
 
83
- ```shell
84
- antlr4 -Dlanguage=Dart lib/src/antlr/grammars/apexdoc/ApexdocLexer.g4 lib/src/antlr/grammars/apexdoc/ApexdocParser.g4 -o lib/src/antlr/lib/apexdoc/
85
- ```
80
+ Parsing is implemented with handwritten [petitparser](https://pub.dev/packages/petitparser) grammars.
81
+ The Apex grammar parses only the declaration structure needed for reflection (bodies are skipped as
82
+ balanced blocks), and the Apexdoc grammar is composed into it, so doc comments are parsed in the same single pass. See
83
+ the repository README for details.
86
84
 
87
85
  ## Typescript
88
86
 
package/dist/node.mjs CHANGED
@@ -222,7 +222,6 @@ class CompiledApp {
222
222
  _217: (o, p) => o[p],
223
223
  _218: (o, p, v) => o[p] = v,
224
224
  _220: o => o instanceof Array,
225
- _227: (a, s) => a.join(s),
226
225
  _231: a => a.length,
227
226
  _233: (a, i) => a[i],
228
227
  _239: o => o instanceof Uint8Array,
package/dist/node.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apex-reflection",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.0-beta.5",
4
4
  "description": "Provides tools for reflecting Apex code, the language used in Salesforce development.",
5
5
  "main": "dist/index.mjs",
6
6
  "scripts": {