@nestbridge/core 0.1.0 → 0.1.1

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 ADDED
@@ -0,0 +1,72 @@
1
+ # @nestbridge/core
2
+
3
+ [![CI](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml/badge.svg)](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@nestbridge/core.svg)](https://www.npmjs.com/package/@nestbridge/core)
5
+
6
+ Static analysis of NestJS controllers, and generation of the client-facing
7
+ `.d.ts` declarations that make them safely importable from the browser.
8
+
9
+ This package has no runtime dependency on NestJS, Vite, or the DOM — it reads
10
+ TypeScript source text via the TypeScript Compiler API and never executes
11
+ your code. It's the engine behind `@nestbridge/vite` and is not usually
12
+ installed directly; see the [repository README](../../README.md) for the
13
+ full picture of how the pieces fit together.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ yarn add @nestbridge/core
19
+ ```
20
+
21
+ ## API
22
+
23
+ ### `analyzeControllers(filePaths)`
24
+
25
+ Parses each file, finds classes decorated with `@Controller(...)`, and
26
+ extracts a plain `ControllerDefinition` per controller — its base path, and
27
+ each `@Get`/`@Post`/`@Put`/`@Patch`/`@Delete` method's HTTP method, route
28
+ path, and `@Param`/`@Query`/`@Body`/`@Headers` parameter mapping. Anything it
29
+ can't safely resolve statically (a non-literal route path, an unsupported
30
+ decorator) becomes a `NestBridgeDiagnostic` instead of a guess.
31
+
32
+ ```ts
33
+ import { analyzeControllers } from '@nestbridge/core';
34
+
35
+ const { controllers, diagnostics } = analyzeControllers([
36
+ 'src/users/users.controller.ts',
37
+ ]);
38
+ ```
39
+
40
+ ### `generateControllerDeclaration(controller, outputFilePath)`
41
+
42
+ Turns a `ControllerDefinition` into the text of a `.d.ts` file. The generated
43
+ class re-declares each method using a type-only reference back to the real
44
+ controller (`Parameters<__ServerX['method']>` / `RemoteResult<...>`), so
45
+ argument and return types are projected from the real controller's own type —
46
+ never re-derived from the AST.
47
+
48
+ ```ts
49
+ import { generateControllerDeclaration } from '@nestbridge/core';
50
+
51
+ const source = generateControllerDeclaration(controller, outputPath);
52
+ ```
53
+
54
+ ### Diagnostics
55
+
56
+ ```ts
57
+ import { formatDiagnostic, NestBridgeDiagnosticError } from '@nestbridge/core';
58
+ ```
59
+
60
+ `formatDiagnostic` renders a `NestBridgeDiagnostic` as a human-readable
61
+ string (file, position, message). `NestBridgeDiagnosticError` wraps one or
62
+ more diagnostics as a thrown `Error`.
63
+
64
+ ### Types
65
+
66
+ `ControllerDefinition`, `ControllerMethodDefinition`,
67
+ `ControllerParameterDefinition`, `HttpMethod`, `ParameterSourceKind`,
68
+ `NestBridgeDiagnostic`, `NestBridgeDiagnosticCode`.
69
+
70
+ ## License
71
+
72
+ MIT
@@ -348,7 +348,7 @@ class NestBridgeDiagnosticError extends Error {
348
348
  }
349
349
  }
350
350
 
351
- const version = "0.1.0";
351
+ const version = "0.1.1";
352
352
 
353
353
  const VERSION = version;
354
354
 
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@nestbridge/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/MDReal32/nestbridge.git",
9
+ "directory": "packages/core"
10
+ },
6
11
  "main": "./build/nestbridge.core.js",
7
12
  "types": "./build/nestbridge.core.d.ts",
8
13
  "exports": {