@nooh-ts/compiler 0.1.0 → 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;
@@ -35,7 +38,6 @@ interface ConfigLoadResult {
35
38
  readonly diagnostics: readonly Diagnostic[];
36
39
  }
37
40
  interface DiscoveredEndpoint {
38
- readonly endpointsRoot: string;
39
41
  readonly groupPath: string;
40
42
  readonly localPath: string;
41
43
  readonly source: string;
@@ -46,6 +48,7 @@ interface DiscoveredGroup {
46
48
  }
47
49
  interface DiscoveredProject {
48
50
  readonly config: LoadedConfig;
51
+ readonly dependencies: readonly SourceFile[];
49
52
  readonly endpoints: readonly DiscoveredEndpoint[];
50
53
  readonly groups: readonly DiscoveredGroup[];
51
54
  }
@@ -85,6 +88,40 @@ interface RouteModel {
85
88
  readonly routeSegments: readonly RouteSegment[];
86
89
  readonly source: string;
87
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
+ }
88
125
  interface RouteGroup {
89
126
  readonly children: readonly string[];
90
127
  readonly configSource?: string;
@@ -95,7 +132,9 @@ interface RouteGroup {
95
132
  }
96
133
  interface ProjectModel {
97
134
  readonly config: LoadedConfig;
135
+ readonly dependencies: DependencyGraph;
98
136
  readonly groups: readonly RouteGroup[];
137
+ readonly routeDependencies: readonly RouteDependencyModel[];
99
138
  readonly routes: readonly RouteModel[];
100
139
  }
101
140
  type DiagnosticSeverity = "error" | "warning" | "info";
@@ -105,7 +144,7 @@ interface Diagnostic {
105
144
  readonly message: string;
106
145
  readonly severity: DiagnosticSeverity;
107
146
  }
108
- type ModuleKind = "types" | "router" | "middleware" | "group" | "app";
147
+ type ModuleKind = "types" | "router" | "middleware" | "group" | "di" | "error" | "app";
109
148
  interface ModulePlan {
110
149
  readonly groupId?: string;
111
150
  readonly id: string;
@@ -113,8 +152,10 @@ interface ModulePlan {
113
152
  readonly routeId?: string;
114
153
  }
115
154
  interface CompilationPlan {
155
+ readonly dependencies: DependencyGraph;
116
156
  readonly modules: readonly ModulePlan[];
117
157
  readonly outputRoot: string;
158
+ readonly routeDependencies: readonly RouteDependencyModel[];
118
159
  }
119
160
  interface GeneratedModule {
120
161
  readonly code: string;
@@ -131,13 +172,14 @@ interface Compilation {
131
172
  readonly plan: CompilationPlan | null;
132
173
  }
133
174
  interface NoohCompiler {
134
- analyze: (parsed: ParsedProject, config: LoadedConfig) => {
175
+ analyze: (parsed: ParsedProject, config: LoadedConfig, dependencies?: DependencyGraph) => {
135
176
  model: ProjectModel;
136
177
  diagnostics: readonly Diagnostic[];
137
178
  };
138
179
  compile: (input: CompileInput) => Promise<Compilation>;
139
180
  discover: (sources: CompileInput["sources"], config: LoadedConfig) => DiscoveredProject;
140
181
  generate: (plan: CompilationPlan, model: ProjectModel) => GeneratedOutput;
182
+ generateRouteIntrospection: (plan: CompilationPlan, model: ProjectModel) => GeneratedOutput;
141
183
  loadConfig: (input: CompileInput) => Promise<ConfigLoadResult>;
142
184
  parse: (project: DiscoveredProject) => ParsedProject;
143
185
  plan: (model: ProjectModel, outputRoot?: string) => CompilationPlan;
@@ -161,15 +203,33 @@ export declare const compile: (input: CompileInput) => Promise<Compilation>;
161
203
  //#endregion
162
204
  //#region src/compiler.d.ts
163
205
  export declare const createCompiler: () => NoohCompiler;
206
+ export declare const introspect: (input: IntrospectionInput) => Promise<IntrospectionResult>;
164
207
  //#endregion
165
208
  //#region src/diff.d.ts
166
209
  export declare const diff: (previous: GeneratedOutput, next: GeneratedOutput) => OutputDiff;
167
210
  //#endregion
211
+ //#region src/finalize.d.ts
212
+ export declare const finalizeCompilation: (compilation: Compilation, introspection: CompilationIntrospection) => Compilation;
213
+ //#endregion
168
214
  //#region src/generate/index.d.ts
169
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>;
170
230
  //#endregion
171
231
  //#region src/pipeline/analyze.d.ts
172
- export declare const analyze: (parsed: ParsedProject, config: LoadedConfig) => {
232
+ export declare const analyze: (parsed: ParsedProject, config: LoadedConfig, dependencies?: DependencyGraph) => {
173
233
  model: ProjectModel;
174
234
  diagnostics: readonly Diagnostic[];
175
235
  };
@@ -177,6 +237,17 @@ export declare const analyze: (parsed: ParsedProject, config: LoadedConfig) => {
177
237
  //#region src/pipeline/config.d.ts
178
238
  export declare const loadConfig: (input: CompileInput) => Promise<ConfigLoadResult>;
179
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
180
251
  //#region src/pipeline/discover.d.ts
181
252
  export declare const discover: (snapshot: SourceSnapshot, config: LoadedConfig) => DiscoveredProject;
182
253
  //#endregion
@@ -189,5 +260,5 @@ export declare const plan: (model: ProjectModel, outputRoot?: string) => Compila
189
260
  //#region src/recompile.d.ts
190
261
  export declare const recompile: (input: RecompileInput) => Promise<Compilation>;
191
262
  //#endregion
192
- 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 };
193
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;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;;;;qBC3MR,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;;;qBC8GE,WACX,UAAU,gBACV,QAAQ,iBACP;;;qBCpHU,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;;UAGM;WACN;WACA,QAAQ;WACR,UAAU;WACV;WACA,SAAS;;UAGH;WACN;WACA;;UAGM;WACN;WACA;WACA;WACA;WACA,OAAO;;UAGD;WACN,SAAS;WACT,sBAAsB;;UAGhB;WACN;WACA;WACA;;UAGM;WACN;WACA;;UAGM;WACN,QAAQ;WACR,uBAAuB;WACvB,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;;KAGC;UAEK;WACN;WACA;WACA;WACA,OAAO;WACP;;UAGM;WACN,aAAa;;UAGP;WACN,OAAO,oBAAoB;WAC3B;WACA,YAAY;;UAGN;WACN;WACA;WACA;;UAGM;WACN,cAAc;WACd,4BAA4B;;UAGtB;WACN,aAAa;WACb,4BAA4B;WAC5B,QAAQ;;UAGF;WACN,sBAAsB;WACtB,eAAe;;UAGT;WACN;WACA;WACA;WACA;WACA;WACA;;UAGM;WACN,QAAQ;WACR,cAAc;WACd,iBAAiB;WACjB,4BAA4B;WAC5B,iBAAiB;;KAGhB;UAEK;WACN;WACA;WACA;WACA,UAAU;;KAGT;UASK;WACN;WACA;WACA,MAAM;WACN;;UAGM;WACN,cAAc;WACd,kBAAkB;WAClB;WACA,4BAA4B;;UAGtB;WACN;WACA;WACA,MAAM;;UAGA;WACN,kBAAkB;;UAGZ;WACN,sBAAsB;WACtB,OAAO;WACP,QAAQ;WACR,MAAM;;UAGA;EACf,UAC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