@happyvertical/smrt-scanner 0.30.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/AGENTS.md ADDED
@@ -0,0 +1,69 @@
1
+ # @happyvertical/smrt-scanner
2
+
3
+ AST-based scanner for discovering SMRT objects in TypeScript source. Uses
4
+ oxc-parser (Rust, 2-3x faster than tsc) for syntactic parsing — it never
5
+ executes the source.
6
+
7
+ ## Key Exports
8
+
9
+ - `OxcScanner` — class that globs `.ts` files (`fast-glob`) and parses each into
10
+ raw class/field/method metadata. `scan()` parses; `scanAndResolve()` parses
11
+ then resolves inheritance in one call.
12
+ - `InheritanceResolver` — resolves class inheritance chains across files
13
+ (`addClasses()` → `resolveAll()`), merging inherited fields/config into each
14
+ `@smrt()` subclass.
15
+ - `ManifestAdapter` — converts resolved classes into the SMRT manifest shape
16
+ (`toManifest()`); owns field-type inference (the `0` vs `0.0` integer/decimal
17
+ heuristic, decorator interpretation, union/alias resolution).
18
+ - `parseFile` / `parseSource` — parse a single file or a source string to a
19
+ `FileScanResult` (classes, errors, type aliases, SMRT imports).
20
+ - `extractSmrtImports` — pull SMRT-related imports from a parsed file.
21
+ - `verifyManifestCompleteness({ packageDir })` — publish guard: re-scans `src/`
22
+ and asserts every `@smrt()` object reached `dist/manifest.json` (issue #1483).
23
+ Returns `ok` / `incomplete` / `missing-manifest` / `scan-error` / `skipped`.
24
+ Driven by `scripts/verify-manifest-completeness.mjs` from `prepack`.
25
+ - Types (re-exported from `./types`): `RawClassDefinition`,
26
+ `RawFieldDefinition`, `RawMethodDefinition`, `ResolvedClassDefinition`,
27
+ `ScanResults`, `FileScanResult`, `OxcScannerOptions`, `InferredFieldType`,
28
+ `FieldTypeInference`.
29
+
30
+ ## How It Works
31
+
32
+ 1. `fast-glob` finds `.ts` files matching include/exclude patterns.
33
+ 2. `oxc-parser` parses each file's AST (TS-ESTree shape).
34
+ 3. Extracts: `@smrt()` config, class hierarchy, field defaults (0 vs 0.0
35
+ heuristic, including negative initializers via `UnaryExpression` unwrap),
36
+ relationships, static properties (`uiSlots`, `adminRoutes`).
37
+ 4. `InheritanceResolver` merges inherited members; `ManifestAdapter` emits the
38
+ manifest JSON consumed by code generators, the vitest plugin, and the CLI.
39
+
40
+ ## Key Files
41
+
42
+ - `src/oxc-parser.ts` — core AST → raw metadata extraction (`parseFile`,
43
+ `parseSource`, `extractSmrtImports`, field/decorator/type extractors).
44
+ - `src/scanner.ts` — `OxcScanner`: globbing + multi-file orchestration
45
+ (`scan` / `scanAndResolve`).
46
+ - `src/inheritance-resolver.ts` — `InheritanceResolver`: cross-file inheritance
47
+ merging.
48
+ - `src/manifest-adapter.ts` — `ManifestAdapter`: raw → manifest conversion and
49
+ field-type inference.
50
+ - `src/verify-completeness.ts` — `verifyManifestCompleteness` publish guard.
51
+ - `src/types.ts` — shared raw/resolved/result type definitions.
52
+ - `src/cli.ts` / `bin/smrt-scan.js` — the `smrt-scan` CLI.
53
+
54
+ ## Gotchas
55
+
56
+ - **Syntactic only**: the scanner parses, it does not type-check or execute.
57
+ Type aliases are resolved heuristically (bounded depth), not via the TS type
58
+ system.
59
+ - **Build-time consumers**: `smrtVitestPlugin()` and the build's vite-plugin run
60
+ the scanner at startup; add a new `@smrt()` class → rebuild/restart so it
61
+ reaches the manifest.
62
+ - **`ManifestBuilder` / `discoverBaseClasses` live in `@happyvertical/smrt-core`,
63
+ not here.** This package is the lower-level AST layer; core orchestrates
64
+ manifest generation and base-class discovery on top of it.
65
+ - **0 vs 0.0 heuristic**: `count = 0` → integer, `price = 0.0` → decimal; the
66
+ raw initializer text (not the parsed value) decides, and negative defaults are
67
+ unwrapped from their `UnaryExpression` before the check.
68
+ - **Static property capture**: captures `uiSlots` and `adminRoutes` for agent
69
+ manifest generation.
package/CLAUDE.md ADDED
@@ -0,0 +1 @@
1
+ @AGENTS.md
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright <2025> <Happy Vertical Corporation>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # @happyvertical/smrt-scanner
2
+
3
+ High-performance TypeScript AST scanner using [OXC](https://oxc-project.github.io/) for SMRT manifest generation. Extracts class, field, method, and decorator metadata from source files without executing them.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @happyvertical/smrt-scanner
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { OxcScanner, InheritanceResolver, ManifestAdapter } from '@happyvertical/smrt-scanner';
15
+ import { parseFile, parseSource, extractSmrtImports } from '@happyvertical/smrt-scanner';
16
+
17
+ // Scan a single file
18
+ const result = parseFile('/path/to/Product.ts');
19
+ // result.classes → RawClassDefinition[]
20
+ // result.smrtImports → Map of SMRT package imports
21
+
22
+ // Scan from source string
23
+ const source = `
24
+ @smrt({ api: true })
25
+ class Product extends SmrtObject {
26
+ name: string = '';
27
+ price: number = 0.0;
28
+ }
29
+ `;
30
+ const parsed = parseSource(source, 'Product.ts');
31
+
32
+ // Full scanner with glob support
33
+ const scanner = new OxcScanner({ include: ['src/**/*.ts'] });
34
+ const results = await scanner.scan();
35
+
36
+ // Resolve inheritance across files
37
+ const resolver = new InheritanceResolver();
38
+ resolver.addClasses(results.classes);
39
+ const resolved = resolver.resolveAll();
40
+
41
+ // Convert to SMRT manifest format
42
+ const adapter = new ManifestAdapter();
43
+ const manifest = adapter.toManifest(resolved);
44
+ ```
45
+
46
+ ### CLI
47
+
48
+ ```bash
49
+ # Scan and output manifest
50
+ smrt-scan src/**/*.ts
51
+ ```
52
+
53
+ ## API
54
+
55
+ ### Classes
56
+
57
+ | Export | Description |
58
+ |--------|------------|
59
+ | `OxcScanner` | Scans TypeScript files for `@smrt()` decorated classes |
60
+ | `InheritanceResolver` | Resolves class inheritance chains across files |
61
+ | `ManifestAdapter` | Converts raw scan results to SMRT manifest format |
62
+
63
+ ### Functions
64
+
65
+ | Export | Description |
66
+ |--------|------------|
67
+ | `parseFile` | Parse a single TypeScript file and extract metadata |
68
+ | `parseSource` | Parse a TypeScript source string |
69
+ | `extractSmrtImports` | Extract SMRT-related imports from a file |
70
+
71
+ ### Key Types
72
+
73
+ `RawClassDefinition`, `RawFieldDefinition`, `RawMethodDefinition`, `RawDecoratorConfig`, `ResolvedClassDefinition`, `ScanResults`, `FileScanResult`, `OxcScannerOptions`, `InferredFieldType`, `FieldTypeInference`
74
+
75
+ ## Dependencies
76
+
77
+ - Peer (optional): `@happyvertical/smrt-core`
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from 'node:child_process';
4
+ import { existsSync } from 'node:fs';
5
+ import { dirname, resolve } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
9
+ const distEntry = resolve(packageRoot, 'dist/cli.js');
10
+ const sourceEntry = resolve(packageRoot, 'src/cli.ts');
11
+
12
+ const command = existsSync(distEntry)
13
+ ? [distEntry, ...process.argv.slice(2)]
14
+ : ['--import', 'tsx', sourceEntry, ...process.argv.slice(2)];
15
+
16
+ const result = spawnSync(process.execPath, command, { stdio: 'inherit' });
17
+
18
+ if (result.error) {
19
+ throw result.error;
20
+ }
21
+
22
+ if (result.signal) {
23
+ process.kill(process.pid, result.signal);
24
+ }
25
+
26
+ process.exit(result.status ?? 1);