@nooh-ts/compiler 0.1.1 → 0.2.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/dist/index.d.mts CHANGED
@@ -10,6 +10,7 @@ interface SourceSnapshot {
10
10
  }
11
11
  interface ModuleLoader {
12
12
  loadDefault: (modulePath: string) => Promise<unknown>;
13
+ loadModule?: (modulePath: string) => Promise<Record<string, unknown>>;
13
14
  }
14
15
  interface CompileOptions {
15
16
  readonly outputRoot?: string;
@@ -22,9 +23,11 @@ interface CompileInput {
22
23
  readonly sources: SourceSnapshot;
23
24
  }
24
25
  interface RuntimeConfig {
26
+ readonly dependencies?: string | undefined;
25
27
  readonly routes?: string | undefined;
26
28
  }
27
29
  interface LoadedConfig {
30
+ readonly dependenciesRoot: string;
28
31
  readonly root: string;
29
32
  readonly routesRoot: string;
30
33
  readonly source: string;
@@ -45,6 +48,7 @@ interface DiscoveredGroup {
45
48
  }
46
49
  interface DiscoveredProject {
47
50
  readonly config: LoadedConfig;
51
+ readonly dependencies: readonly SourceFile[];
48
52
  readonly endpoints: readonly DiscoveredEndpoint[];
49
53
  readonly groups: readonly DiscoveredGroup[];
50
54
  }
@@ -84,6 +88,40 @@ interface RouteModel {
84
88
  readonly routeSegments: readonly RouteSegment[];
85
89
  readonly source: string;
86
90
  }
91
+ type DependencyScope = "value" | "singleton" | "request" | "transient";
92
+ interface DependencyDeclaration {
93
+ readonly dependencies: readonly string[];
94
+ readonly id: string;
95
+ readonly name: string;
96
+ readonly scope: DependencyScope;
97
+ readonly source: string;
98
+ }
99
+ interface DependencyNode {
100
+ readonly declaration: DependencyDeclaration;
101
+ }
102
+ interface DependencyGraph {
103
+ readonly nodes: ReadonlyMap<string, DependencyNode>;
104
+ readonly order: readonly string[];
105
+ readonly references: ReadonlyMap<object, string>;
106
+ }
107
+ interface RouteDependencyModel {
108
+ readonly closure: readonly string[];
109
+ readonly roots: readonly string[];
110
+ readonly routeId: string;
111
+ }
112
+ interface CompilationIntrospection {
113
+ readonly dependencies: DependencyGraph;
114
+ readonly routeDependencies: readonly RouteDependencyModel[];
115
+ }
116
+ interface IntrospectionInput {
117
+ readonly compilation: Compilation;
118
+ readonly dependencySources: readonly SourceFile[];
119
+ readonly loader: ModuleLoader;
120
+ }
121
+ interface IntrospectionResult {
122
+ readonly diagnostics: readonly Diagnostic[];
123
+ readonly introspection: CompilationIntrospection | null;
124
+ }
87
125
  interface RouteGroup {
88
126
  readonly children: readonly string[];
89
127
  readonly configSource?: string;
@@ -94,7 +132,9 @@ interface RouteGroup {
94
132
  }
95
133
  interface ProjectModel {
96
134
  readonly config: LoadedConfig;
135
+ readonly dependencies: DependencyGraph;
97
136
  readonly groups: readonly RouteGroup[];
137
+ readonly routeDependencies: readonly RouteDependencyModel[];
98
138
  readonly routes: readonly RouteModel[];
99
139
  }
100
140
  type DiagnosticSeverity = "error" | "warning" | "info";
@@ -104,7 +144,7 @@ interface Diagnostic {
104
144
  readonly message: string;
105
145
  readonly severity: DiagnosticSeverity;
106
146
  }
107
- type ModuleKind = "types" | "router" | "middleware" | "group" | "app";
147
+ type ModuleKind = "types" | "router" | "middleware" | "group" | "di" | "error" | "app";
108
148
  interface ModulePlan {
109
149
  readonly groupId?: string;
110
150
  readonly id: string;
@@ -112,8 +152,10 @@ interface ModulePlan {
112
152
  readonly routeId?: string;
113
153
  }
114
154
  interface CompilationPlan {
155
+ readonly dependencies: DependencyGraph;
115
156
  readonly modules: readonly ModulePlan[];
116
157
  readonly outputRoot: string;
158
+ readonly routeDependencies: readonly RouteDependencyModel[];
117
159
  }
118
160
  interface GeneratedModule {
119
161
  readonly code: string;
@@ -130,13 +172,14 @@ interface Compilation {
130
172
  readonly plan: CompilationPlan | null;
131
173
  }
132
174
  interface NoohCompiler {
133
- analyze: (parsed: ParsedProject, config: LoadedConfig) => {
175
+ analyze: (parsed: ParsedProject, config: LoadedConfig, dependencies?: DependencyGraph) => {
134
176
  model: ProjectModel;
135
177
  diagnostics: readonly Diagnostic[];
136
178
  };
137
179
  compile: (input: CompileInput) => Promise<Compilation>;
138
180
  discover: (sources: CompileInput["sources"], config: LoadedConfig) => DiscoveredProject;
139
181
  generate: (plan: CompilationPlan, model: ProjectModel) => GeneratedOutput;
182
+ generateRouteIntrospection: (plan: CompilationPlan, model: ProjectModel) => GeneratedOutput;
140
183
  loadConfig: (input: CompileInput) => Promise<ConfigLoadResult>;
141
184
  parse: (project: DiscoveredProject) => ParsedProject;
142
185
  plan: (model: ProjectModel, outputRoot?: string) => CompilationPlan;
@@ -160,15 +203,33 @@ export declare const compile: (input: CompileInput) => Promise<Compilation>;
160
203
  //#endregion
161
204
  //#region src/compiler.d.ts
162
205
  export declare const createCompiler: () => NoohCompiler;
206
+ export declare const introspect: (input: IntrospectionInput) => Promise<IntrospectionResult>;
163
207
  //#endregion
164
208
  //#region src/diff.d.ts
165
209
  export declare const diff: (previous: GeneratedOutput, next: GeneratedOutput) => OutputDiff;
166
210
  //#endregion
211
+ //#region src/finalize.d.ts
212
+ export declare const finalizeCompilation: (compilation: Compilation, introspection: CompilationIntrospection) => Compilation;
213
+ //#endregion
167
214
  //#region src/generate/index.d.ts
168
215
  export declare const generate: (plan: CompilationPlan, model: ProjectModel) => GeneratedOutput;
216
+ export declare const generateRouteIntrospection: (plan: CompilationPlan, model: ProjectModel) => GeneratedOutput;
217
+ //#endregion
218
+ //#region src/introspect.d.ts
219
+ export declare const NOOH_ROUTE_METADATA: unique symbol;
220
+ interface RouteMetadata {
221
+ readonly dependencies: readonly unknown[];
222
+ readonly kind: "route";
223
+ }
224
+ export declare const readRouteMetadata: (value: unknown) => RouteMetadata | null;
225
+ export declare const introspectRoute: (route: RouteModel, loader: IntrospectionInput["loader"]) => Promise<{
226
+ readonly diagnostics: readonly Diagnostic[];
227
+ readonly metadata?: RouteMetadata | undefined;
228
+ }>;
229
+ export declare const introspectCompilation: (input: IntrospectionInput) => Promise<IntrospectionResult>;
169
230
  //#endregion
170
231
  //#region src/pipeline/analyze.d.ts
171
- export declare const analyze: (parsed: ParsedProject, config: LoadedConfig) => {
232
+ export declare const analyze: (parsed: ParsedProject, config: LoadedConfig, dependencies?: DependencyGraph) => {
172
233
  model: ProjectModel;
173
234
  diagnostics: readonly Diagnostic[];
174
235
  };
@@ -176,6 +237,17 @@ export declare const analyze: (parsed: ParsedProject, config: LoadedConfig) => {
176
237
  //#region src/pipeline/config.d.ts
177
238
  export declare const loadConfig: (input: CompileInput) => Promise<ConfigLoadResult>;
178
239
  //#endregion
240
+ //#region src/pipeline/dependencies.d.ts
241
+ export declare const createDependencyGraph: (declarations: readonly DependencyDeclaration[], references?: ReadonlyMap<object, string>) => {
242
+ readonly diagnostics: readonly Diagnostic[];
243
+ readonly graph: DependencyGraph;
244
+ };
245
+ export declare const loadDependencyGraph: (sources: readonly SourceFile[], loader: ModuleLoader) => Promise<{
246
+ readonly diagnostics: readonly Diagnostic[];
247
+ readonly graph: DependencyGraph;
248
+ }>;
249
+ export declare const dependencyClosure: (graph: DependencyGraph, roots: readonly string[]) => readonly string[];
250
+ //#endregion
179
251
  //#region src/pipeline/discover.d.ts
180
252
  export declare const discover: (snapshot: SourceSnapshot, config: LoadedConfig) => DiscoveredProject;
181
253
  //#endregion
@@ -188,5 +260,5 @@ export declare const plan: (model: ProjectModel, outputRoot?: string) => Compila
188
260
  //#region src/recompile.d.ts
189
261
  export declare const recompile: (input: RecompileInput) => Promise<Compilation>;
190
262
  //#endregion
191
- export type { Compilation, CompilationPlan, CompileInput, CompileOptions, ConfigLoadResult, Diagnostic, DiscoveredEndpoint, DiscoveredProject, GeneratedModule, GeneratedOutput, LoadedConfig, ModuleKind, ModuleLoader, ModulePlan, NoohCompiler, OutputDiff, ParsedProject, ParsedRoute, ProjectModel, RecompileInput, RouteGroup, RouteMethod, RouteModel, RouteSegment, RuntimeConfig, SourceFile, SourceSnapshot };
263
+ export type { Compilation, CompilationIntrospection, CompilationPlan, CompileInput, CompileOptions, ConfigLoadResult, DependencyDeclaration, DependencyGraph, DependencyNode, DependencyScope, Diagnostic, DiscoveredEndpoint, DiscoveredProject, GeneratedModule, GeneratedOutput, IntrospectionInput, IntrospectionResult, LoadedConfig, ModuleKind, ModuleLoader, ModulePlan, NoohCompiler, OutputDiff, ParsedProject, ParsedRoute, ProjectModel, RecompileInput, RouteDependencyModel, RouteGroup, RouteMetadata, RouteMethod, RouteModel, RouteSegment, RuntimeConfig, SourceFile, SourceSnapshot };
192
264
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/compile.ts","../src/compiler.ts","../src/diff.ts","../src/generate/index.ts","../src/pipeline/analyze.ts","../src/pipeline/config.ts","../src/pipeline/discover.ts","../src/pipeline/parse.ts","../src/pipeline/plan.ts","../src/recompile.ts"],"mappings":";cAAa;KAWD,sBAAsB;UAEjB;WACN;WACA;;UAGM;WACN,gBAAgB;;UAGV;EACf,cAAc,uBAAuB;;UAGtB;WACN;;UAGM;WACN;WACA,QAAQ;WACR,UAAU;WACV;WACA,SAAS;;UAGH;WACN;;UAGM;WACN;WACA;WACA;WACA,OAAO;;UAGD;WACN,SAAS;WACT,sBAAsB;;UAGhB;WACN;WACA;WACA;;UAGM;WACN;WACA;;UAGM;WACN,QAAQ;WACR,oBAAoB;WACpB,iBAAiB;;KAGhB;WAEG;WACA;;WAGA;WACA;;WAGA;WACA;;UAGE;WACN;WACA,QAAQ;WACR;WACA,mBAAmB;WACnB;;UAGM;WACN;WACA;;UAGM;WACN,sBAAsB;WACtB,iBAAiB;WACjB,iBAAiB;;UAGX;WACN;WAEA;WACA;WAEA;WAEA,QAAQ;WAER;WACA,wBAAwB;WACxB;;UAGM;WACN;WACA;WACA;WACA;WACA;WACA;;UAGM;WACN,QAAQ;WACR,iBAAiB;WACjB,iBAAiB;;KAGhB;UAEK;WACN;WACA;WACA;WACA,UAAU;;KAGT;UAEK;WACN;WACA;WACA,MAAM;WACN;;UAGM;WACN,kBAAkB;WAClB;;UAGM;WACN;WACA;WACA,MAAM;;UAGA;WACN,kBAAkB;;UAGZ;WACN,sBAAsB;WACtB,OAAO;WACP,QAAQ;WACR,MAAM;;UAGA;EACf,UACE,QAAQ,eACR,QAAQ;IAER,OAAO;IACP,sBAAsB;;EAExB,UAAU,OAAO,iBAAiB,QAAQ;EAC1C,WACE,SAAS,yBACT,QAAQ,iBACL;EACL,WAAW,MAAM,iBAAiB,OAAO,iBAAiB;EAC1D,aAAa,OAAO,iBAAiB,QAAQ;EAC7C,QAAQ,SAAS,sBAAsB;EACvC,OAAO,OAAO,cAAc,wBAAwB;;UAGrC;WACN,gBAAgB;WAChB,kBAAkB;WAClB;WACA,oBAAoB;;UAGd;WACN;WACA,QAAQ;WACR,UAAU;WACV,UAAU;WACV,UAAU;;;;qBC1MR,UAAW,OAAO,iBAAe,QAAQ;;;qBCOzC,sBAAqB;;;qBCRrB,OACX,UAAU,iBACV,MAAM,oBACL;;;qBCQU,WACX,MAAM,iBACN,OAAO,iBACN;;;qBC4MU,UACX,QAAQ,eACR,QAAQ;EAER,OAAO;EACP,sBAAsB;;;;qBCvNX,aACX,OAAO,iBACN,QAAQ;;;qBCkEE,WACX,UAAU,gBACV,QAAQ,iBACP;;;qBCxEU,QAAS,SAAS,sBAAoB;;;qBCDtC,OACX,OAAO,cACP,wBACC;;;qBCRU,YAAa,OAAO,mBAAiB,QAAQ"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/compile.ts","../src/compiler.ts","../src/diff.ts","../src/finalize.ts","../src/generate/index.ts","../src/introspect.ts","../src/pipeline/analyze.ts","../src/pipeline/config.ts","../src/pipeline/dependencies.ts","../src/pipeline/discover.ts","../src/pipeline/parse.ts","../src/pipeline/plan.ts","../src/recompile.ts"],"mappings":";cAAa;KAWD,sBAAsB;UAEjB;WACN;WACA;;UAGM;WACN,gBAAgB;;UAGV;EACf,cAAc,uBAAuB;EACrC,cAAc,uBAAuB,QAAQ;;UAG9B;WACN;;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