@vertz/compiler 0.2.0 → 0.2.3
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 +8 -700
- package/dist/index.d.ts +104 -2
- package/dist/index.js +650 -6
- package/package.json +10 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type DiagnosticSeverity = "error" | "warning" | "info";
|
|
2
|
-
type DiagnosticCode = "VERTZ_SCHEMA_NAMING" | "VERTZ_SCHEMA_PLACEMENT" | "VERTZ_SCHEMA_EXECUTION" | "VERTZ_SCHEMA_MISSING_ID" | "VERTZ_SCHEMA_DYNAMIC_NAME" | "VERTZ_MODULE_CIRCULAR" | "VERTZ_MODULE_EXPORT_INVALID" | "VERTZ_MODULE_IMPORT_MISSING" | "VERTZ_MODULE_DUPLICATE_NAME" | "VERTZ_MODULE_DYNAMIC_NAME" | "VERTZ_MODULE_OPTIONS_INVALID" | "VERTZ_MODULE_WRONG_OWNERSHIP" | "VERTZ_SERVICE_INJECT_MISSING" | "VERTZ_SERVICE_UNUSED" | "VERTZ_SERVICE_DYNAMIC_NAME" | "VERTZ_ENV_MISSING_DEFAULT" | "VERTZ_ENV_DUPLICATE" | "VERTZ_ENV_DYNAMIC_CONFIG" | "VERTZ_MW_MISSING_NAME" | "VERTZ_MW_MISSING_HANDLER" | "VERTZ_MW_DYNAMIC_NAME" | "VERTZ_MW_NON_OBJECT_CONFIG" | "VERTZ_MW_REQUIRES_UNSATISFIED" | "VERTZ_MW_PROVIDES_COLLISION" | "VERTZ_MW_ORDER_INVALID" | "VERTZ_RT_UNKNOWN_MODULE_DEF" | "VERTZ_RT_DYNAMIC_PATH" | "VERTZ_RT_MISSING_HANDLER" | "VERTZ_RT_MISSING_PREFIX" | "VERTZ_RT_DYNAMIC_CONFIG" | "VERTZ_RT_INVALID_PATH" | "VERTZ_ROUTE_DUPLICATE" | "VERTZ_ROUTE_PARAM_MISMATCH" | "VERTZ_ROUTE_MISSING_RESPONSE" | "VERTZ_APP_MISSING" | "VERTZ_APP_NOT_FOUND" | "VERTZ_APP_DUPLICATE" | "VERTZ_APP_BASEPATH_FORMAT" | "VERTZ_APP_INLINE_MODULE" | "VERTZ_DEP_CYCLE" | "VERTZ_DEP_CIRCULAR" | "VERTZ_DEP_UNRESOLVED_INJECT" | "VERTZ_DEP_INIT_ORDER" | "VERTZ_CTX_COLLISION" | "VERTZ_DEAD_CODE";
|
|
2
|
+
type DiagnosticCode = "VERTZ_SCHEMA_NAMING" | "VERTZ_SCHEMA_PLACEMENT" | "VERTZ_SCHEMA_EXECUTION" | "VERTZ_SCHEMA_MISSING_ID" | "VERTZ_SCHEMA_DYNAMIC_NAME" | "VERTZ_MODULE_CIRCULAR" | "VERTZ_MODULE_EXPORT_INVALID" | "VERTZ_MODULE_IMPORT_MISSING" | "VERTZ_MODULE_DUPLICATE_NAME" | "VERTZ_MODULE_DYNAMIC_NAME" | "VERTZ_MODULE_OPTIONS_INVALID" | "VERTZ_MODULE_WRONG_OWNERSHIP" | "VERTZ_SERVICE_INJECT_MISSING" | "VERTZ_SERVICE_UNUSED" | "VERTZ_SERVICE_DYNAMIC_NAME" | "VERTZ_ENV_MISSING_DEFAULT" | "VERTZ_ENV_DUPLICATE" | "VERTZ_ENV_DYNAMIC_CONFIG" | "VERTZ_MW_MISSING_NAME" | "VERTZ_MW_MISSING_HANDLER" | "VERTZ_MW_DYNAMIC_NAME" | "VERTZ_MW_NON_OBJECT_CONFIG" | "VERTZ_MW_REQUIRES_UNSATISFIED" | "VERTZ_MW_PROVIDES_COLLISION" | "VERTZ_MW_ORDER_INVALID" | "VERTZ_RT_UNKNOWN_MODULE_DEF" | "VERTZ_RT_DYNAMIC_PATH" | "VERTZ_RT_MISSING_HANDLER" | "VERTZ_RT_MISSING_PREFIX" | "VERTZ_RT_DYNAMIC_CONFIG" | "VERTZ_RT_INVALID_PATH" | "VERTZ_ROUTE_DUPLICATE" | "VERTZ_ROUTE_PARAM_MISMATCH" | "VERTZ_ROUTE_MISSING_RESPONSE" | "VERTZ_APP_MISSING" | "VERTZ_APP_NOT_FOUND" | "VERTZ_APP_DUPLICATE" | "VERTZ_APP_BASEPATH_FORMAT" | "VERTZ_APP_INLINE_MODULE" | "VERTZ_DEP_CYCLE" | "VERTZ_DEP_CIRCULAR" | "VERTZ_DEP_UNRESOLVED_INJECT" | "VERTZ_DEP_INIT_ORDER" | "VERTZ_CTX_COLLISION" | "VERTZ_DEAD_CODE" | "ENTITY_MISSING_ARGS" | "ENTITY_NON_LITERAL_NAME" | "ENTITY_INVALID_NAME" | "ENTITY_DUPLICATE_NAME" | "ENTITY_CONFIG_NOT_OBJECT" | "ENTITY_MISSING_MODEL" | "ENTITY_MODEL_UNRESOLVABLE" | "ENTITY_ACTION_NAME_COLLISION" | "ENTITY_ACTION_MISSING_SCHEMA" | "ENTITY_ACTION_INVALID_METHOD" | "ENTITY_UNKNOWN_ACCESS_OP" | "ENTITY_UNRESOLVED_IMPORT" | "ENTITY_ROUTE_COLLISION" | "ENTITY_NO_ROUTES";
|
|
3
3
|
interface SourceContext {
|
|
4
4
|
lines: {
|
|
5
5
|
number: number;
|
|
@@ -37,6 +37,7 @@ interface AppIR {
|
|
|
37
37
|
modules: ModuleIR[];
|
|
38
38
|
middleware: MiddlewareIR[];
|
|
39
39
|
schemas: SchemaIR[];
|
|
40
|
+
entities: EntityIR[];
|
|
40
41
|
dependencyGraph: DependencyGraphIR;
|
|
41
42
|
diagnostics: Diagnostic[];
|
|
42
43
|
}
|
|
@@ -154,6 +155,60 @@ interface InlineSchemaRef {
|
|
|
154
155
|
kind: "inline";
|
|
155
156
|
sourceFile: string;
|
|
156
157
|
jsonSchema?: Record<string, unknown>;
|
|
158
|
+
resolvedFields?: ResolvedField[];
|
|
159
|
+
}
|
|
160
|
+
/** Structured field info extracted from resolved TypeScript types. */
|
|
161
|
+
interface ResolvedField {
|
|
162
|
+
name: string;
|
|
163
|
+
tsType: "string" | "number" | "boolean" | "date" | "unknown";
|
|
164
|
+
optional: boolean;
|
|
165
|
+
}
|
|
166
|
+
interface EntityIR extends SourceLocation {
|
|
167
|
+
name: string;
|
|
168
|
+
modelRef: EntityModelRef;
|
|
169
|
+
access: EntityAccessIR;
|
|
170
|
+
hooks: EntityHooksIR;
|
|
171
|
+
actions: EntityActionIR[];
|
|
172
|
+
relations: EntityRelationIR[];
|
|
173
|
+
}
|
|
174
|
+
interface EntityModelRef {
|
|
175
|
+
variableName: string;
|
|
176
|
+
importSource?: string;
|
|
177
|
+
tableName?: string;
|
|
178
|
+
schemaRefs: EntityModelSchemaRefs;
|
|
179
|
+
}
|
|
180
|
+
interface EntityModelSchemaRefs {
|
|
181
|
+
response?: SchemaRef;
|
|
182
|
+
createInput?: SchemaRef;
|
|
183
|
+
updateInput?: SchemaRef;
|
|
184
|
+
resolved: boolean;
|
|
185
|
+
}
|
|
186
|
+
interface EntityAccessIR {
|
|
187
|
+
list: EntityAccessRuleKind;
|
|
188
|
+
get: EntityAccessRuleKind;
|
|
189
|
+
create: EntityAccessRuleKind;
|
|
190
|
+
update: EntityAccessRuleKind;
|
|
191
|
+
delete: EntityAccessRuleKind;
|
|
192
|
+
custom: Record<string, EntityAccessRuleKind>;
|
|
193
|
+
}
|
|
194
|
+
type EntityAccessRuleKind = "none" | "false" | "function";
|
|
195
|
+
interface EntityHooksIR {
|
|
196
|
+
before: ("create" | "update")[];
|
|
197
|
+
after: ("create" | "update" | "delete")[];
|
|
198
|
+
}
|
|
199
|
+
interface EntityActionIR extends SourceLocation {
|
|
200
|
+
name: string;
|
|
201
|
+
method: HttpMethod;
|
|
202
|
+
path?: string;
|
|
203
|
+
params?: SchemaRef;
|
|
204
|
+
query?: SchemaRef;
|
|
205
|
+
headers?: SchemaRef;
|
|
206
|
+
body?: SchemaRef;
|
|
207
|
+
response?: SchemaRef;
|
|
208
|
+
}
|
|
209
|
+
interface EntityRelationIR {
|
|
210
|
+
name: string;
|
|
211
|
+
selection: "all" | string[];
|
|
157
212
|
}
|
|
158
213
|
interface ModuleDefContext {
|
|
159
214
|
moduleDefVariables: Map<string, string>;
|
|
@@ -216,6 +271,7 @@ declare function defineConfig(config: VertzConfig): VertzConfig;
|
|
|
216
271
|
declare function resolveConfig(config?: VertzConfig): ResolvedConfig;
|
|
217
272
|
interface Analyzer<T> {
|
|
218
273
|
analyze(): Promise<T>;
|
|
274
|
+
getDiagnostics(): Diagnostic[];
|
|
219
275
|
}
|
|
220
276
|
declare abstract class BaseAnalyzer<T> implements Analyzer<T> {
|
|
221
277
|
protected readonly project: Project;
|
|
@@ -293,6 +349,49 @@ declare class RouteAnalyzer extends BaseAnalyzer<RouteAnalyzerResult> {
|
|
|
293
349
|
private extractMiddlewareRefs;
|
|
294
350
|
private generateOperationId;
|
|
295
351
|
}
|
|
352
|
+
interface EntityAnalyzerResult {
|
|
353
|
+
entities: EntityIR[];
|
|
354
|
+
}
|
|
355
|
+
declare class EntityAnalyzer extends BaseAnalyzer<EntityAnalyzerResult> {
|
|
356
|
+
private debug;
|
|
357
|
+
analyze(): Promise<EntityAnalyzerResult>;
|
|
358
|
+
private findEntityCalls;
|
|
359
|
+
private extractEntity;
|
|
360
|
+
private extractModelRef;
|
|
361
|
+
private findImportForIdentifier;
|
|
362
|
+
private resolveModelSchemas;
|
|
363
|
+
private extractSchemaType;
|
|
364
|
+
/**
|
|
365
|
+
* Build JSON Schema from resolved fields.
|
|
366
|
+
* Maps tsType ('string' | 'number' | 'boolean' | 'date' | 'unknown') to JSON Schema types.
|
|
367
|
+
*/
|
|
368
|
+
private buildJsonSchema;
|
|
369
|
+
/**
|
|
370
|
+
* Map tsType to JSON Schema type.
|
|
371
|
+
* Handles column types like text → string, boolean → boolean, uuid → string with format,
|
|
372
|
+
* timestamp with time zone → string with date-time format, integer → integer, real/float → number.
|
|
373
|
+
*/
|
|
374
|
+
private tsTypeToJsonSchema;
|
|
375
|
+
/**
|
|
376
|
+
* Navigate through SchemaLike<T> to extract T's field info.
|
|
377
|
+
* SchemaLike<T>.parse() returns { ok: true; data: T } | { ok: false; error: Error }.
|
|
378
|
+
* We unwrap the Result union to get T from the success branch's `data` property.
|
|
379
|
+
*/
|
|
380
|
+
private resolveFieldsFromSchemaType;
|
|
381
|
+
/**
|
|
382
|
+
* Unwrap a Result type to extract T from the success branch.
|
|
383
|
+
* Handles: { ok: true; data: T } | { ok: false; error: Error } → T
|
|
384
|
+
* Falls back to the type itself if it's not a Result union (backward compat).
|
|
385
|
+
*/
|
|
386
|
+
private unwrapResultType;
|
|
387
|
+
private mapTsType;
|
|
388
|
+
private extractAccess;
|
|
389
|
+
private classifyAccessRule;
|
|
390
|
+
private extractHooks;
|
|
391
|
+
private extractActions;
|
|
392
|
+
private resolveSchemaFromExpression;
|
|
393
|
+
private extractRelations;
|
|
394
|
+
}
|
|
296
395
|
import { Expression as Expression2, SourceFile } from "ts-morph";
|
|
297
396
|
interface SchemaAnalyzerResult {
|
|
298
397
|
schemas: SchemaIR[];
|
|
@@ -339,6 +438,7 @@ interface CompilerDependencies {
|
|
|
339
438
|
middleware: Analyzer<MiddlewareAnalyzerResult>;
|
|
340
439
|
module: Analyzer<ModuleAnalyzerResult>;
|
|
341
440
|
app: Analyzer<AppAnalyzerResult>;
|
|
441
|
+
entity: Analyzer<EntityAnalyzerResult>;
|
|
342
442
|
dependencyGraph: Analyzer<DependencyGraphResult>;
|
|
343
443
|
};
|
|
344
444
|
validators: Validator[];
|
|
@@ -630,6 +730,8 @@ declare class IncrementalCompiler {
|
|
|
630
730
|
declare function createEmptyDependencyGraph(): DependencyGraphIR;
|
|
631
731
|
declare function createEmptyAppIR(): AppIR;
|
|
632
732
|
declare function addDiagnosticsToIR(ir: AppIR, diagnostics: readonly Diagnostic[]): AppIR;
|
|
733
|
+
declare function injectEntityRoutes(ir: AppIR): void;
|
|
734
|
+
declare function detectRouteCollisions(ir: AppIR): Diagnostic[];
|
|
633
735
|
declare function mergeIR(base: AppIR, partial: Partial<AppIR>): AppIR;
|
|
634
736
|
import { ChildProcess } from "node:child_process";
|
|
635
737
|
interface TypecheckDiagnostic {
|
|
@@ -722,4 +824,4 @@ declare class PlacementValidator implements Validator {
|
|
|
722
824
|
private checkFileLocation;
|
|
723
825
|
private checkMixedExports;
|
|
724
826
|
}
|
|
725
|
-
export { typecheckWatch, typecheck, resolveImportPath, resolveIdentifier, resolveExport, resolveConfig, renderSchemaRegistryFile, renderRouteTableFile, renderBootFile, parseWatchBlock, parseTscOutput, parseSchemaName2 as parseSchemaName, parseInjectRefs, parseImports, mergeIR, mergeDiagnostics, isSchemaFile, isSchemaExpression, isFromImport, hasErrors, getVariableNameForCall, getStringValue, getSourceLocation, getPropertyValue, getProperties, getNumberValue, getBooleanValue, getArrayElements, findMethodCallsOnVariable, findCallExpressions, findAffectedModules, filterBySeverity, extractSchemaId, extractObjectLiteral, extractMethodSignatures, extractIdentifierNames, defineConfig, createSchemaExecutor, createNamedSchemaRef, createInlineSchemaRef, createEmptyDependencyGraph, createEmptyAppIR, createDiagnosticFromLocation, createDiagnostic, createCompiler, categorizeChanges, buildSchemaRegistry, buildRouteTable, buildManifest, buildBootManifest, addDiagnosticsToIR, VertzConfig, Validator, ValidationConfig, ValidPart, ValidOperation, TypecheckWatchOptions, TypecheckResult, TypecheckOptions, TypecheckDiagnostic, SourceLocation, SourceContext, ServiceMethodParam, ServiceMethodIR, ServiceIR, ServiceAnalyzerResult, ServiceAnalyzer, SchemaRegistryManifest, SchemaRegistryGenerator, SchemaRegistryEntry, SchemaRef, SchemaNameParts, SchemaIR, SchemaExecutor, SchemaExecutionResult, SchemaConfig, SchemaAnalyzerResult, SchemaAnalyzer, RouterIR, RouteTableSchemas, RouteTableManifest, RouteTableGenerator, RouteTableEntry, RouteIR, RouteAnalyzerResult, RouteAnalyzer, ResolvedImport, ResolvedConfig, PlacementValidator, ParsedSchemaName, OpenAPITag, OpenAPIServer, OpenAPIResponse, OpenAPIRequestBody, OpenAPIPathItem, OpenAPIParameter, OpenAPIOperation, OpenAPIInfo, OpenAPIGenerator, OpenAPIDocument, OpenAPIConfig, NamingValidator, NamedSchemaRef, ModuleValidator, ModuleRegistration, ModuleIR, ModuleDefContext, ModuleAnalyzerResult, ModuleAnalyzer, MiddlewareRef, MiddlewareIR, MiddlewareAnalyzerResult, MiddlewareAnalyzer, ManifestRoute, ManifestModule, ManifestMiddleware, ManifestGenerator, ManifestDiagnostic, ManifestDependencyEdge, JSONSchemaObject, InlineSchemaRef, InjectRef, IncrementalResult, IncrementalCompiler, ImportRef, HttpMethod, Generator, FileChange, FileCategory, EnvVariableIR, EnvIR, EnvAnalyzerResult, EnvAnalyzer, DiagnosticSeverity, DiagnosticCode, Diagnostic, DependencyNodeKind, DependencyNode, DependencyGraphResult, DependencyGraphInput, DependencyGraphIR, DependencyGraphAnalyzer, DependencyEdgeKind, DependencyEdge, CreateDiagnosticOptions, CompletenessValidator, CompilerDependencies, CompilerConfig, Compiler, CompileResult, CategorizedChanges, CategorizeOptions, BootModuleEntry, BootMiddlewareEntry, BootManifest, BootGenerator, BaseGenerator, BaseAnalyzer, AppManifest, AppIR, AppDefinition, AppAnalyzerResult, AppAnalyzer, Analyzer };
|
|
827
|
+
export { typecheckWatch, typecheck, resolveImportPath, resolveIdentifier, resolveExport, resolveConfig, renderSchemaRegistryFile, renderRouteTableFile, renderBootFile, parseWatchBlock, parseTscOutput, parseSchemaName2 as parseSchemaName, parseInjectRefs, parseImports, mergeIR, mergeDiagnostics, isSchemaFile, isSchemaExpression, isFromImport, injectEntityRoutes, hasErrors, getVariableNameForCall, getStringValue, getSourceLocation, getPropertyValue, getProperties, getNumberValue, getBooleanValue, getArrayElements, findMethodCallsOnVariable, findCallExpressions, findAffectedModules, filterBySeverity, extractSchemaId, extractObjectLiteral, extractMethodSignatures, extractIdentifierNames, detectRouteCollisions, defineConfig, createSchemaExecutor, createNamedSchemaRef, createInlineSchemaRef, createEmptyDependencyGraph, createEmptyAppIR, createDiagnosticFromLocation, createDiagnostic, createCompiler, categorizeChanges, buildSchemaRegistry, buildRouteTable, buildManifest, buildBootManifest, addDiagnosticsToIR, VertzConfig, Validator, ValidationConfig, ValidPart, ValidOperation, TypecheckWatchOptions, TypecheckResult, TypecheckOptions, TypecheckDiagnostic, SourceLocation, SourceContext, ServiceMethodParam, ServiceMethodIR, ServiceIR, ServiceAnalyzerResult, ServiceAnalyzer, SchemaRegistryManifest, SchemaRegistryGenerator, SchemaRegistryEntry, SchemaRef, SchemaNameParts, SchemaIR, SchemaExecutor, SchemaExecutionResult, SchemaConfig, SchemaAnalyzerResult, SchemaAnalyzer, RouterIR, RouteTableSchemas, RouteTableManifest, RouteTableGenerator, RouteTableEntry, RouteIR, RouteAnalyzerResult, RouteAnalyzer, ResolvedImport, ResolvedConfig, PlacementValidator, ParsedSchemaName, OpenAPITag, OpenAPIServer, OpenAPIResponse, OpenAPIRequestBody, OpenAPIPathItem, OpenAPIParameter, OpenAPIOperation, OpenAPIInfo, OpenAPIGenerator, OpenAPIDocument, OpenAPIConfig, NamingValidator, NamedSchemaRef, ModuleValidator, ModuleRegistration, ModuleIR, ModuleDefContext, ModuleAnalyzerResult, ModuleAnalyzer, MiddlewareRef, MiddlewareIR, MiddlewareAnalyzerResult, MiddlewareAnalyzer, ManifestRoute, ManifestModule, ManifestMiddleware, ManifestGenerator, ManifestDiagnostic, ManifestDependencyEdge, JSONSchemaObject, InlineSchemaRef, InjectRef, IncrementalResult, IncrementalCompiler, ImportRef, HttpMethod, Generator, FileChange, FileCategory, EnvVariableIR, EnvIR, EnvAnalyzerResult, EnvAnalyzer, EntityRelationIR, EntityModelSchemaRefs, EntityModelRef, EntityIR, EntityHooksIR, EntityAnalyzerResult, EntityAnalyzer, EntityActionIR, EntityAccessRuleKind, EntityAccessIR, DiagnosticSeverity, DiagnosticCode, Diagnostic, DependencyNodeKind, DependencyNode, DependencyGraphResult, DependencyGraphInput, DependencyGraphIR, DependencyGraphAnalyzer, DependencyEdgeKind, DependencyEdge, CreateDiagnosticOptions, CompletenessValidator, CompilerDependencies, CompilerConfig, Compiler, CompileResult, CategorizedChanges, CategorizeOptions, BootModuleEntry, BootMiddlewareEntry, BootManifest, BootGenerator, BaseGenerator, BaseAnalyzer, AppManifest, AppIR, AppDefinition, AppAnalyzerResult, AppAnalyzer, Analyzer };
|