@vertz/compiler 0.2.12 → 0.2.14

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +75 -39
  2. package/dist/index.js +1242 -1027
  3. package/package.json +1 -1
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" | "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";
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" | "ENTITY_MODEL_NOT_REGISTERED";
3
3
  interface SourceContext {
4
4
  lines: {
5
5
  number: number;
@@ -38,6 +38,7 @@ interface AppIR {
38
38
  middleware: MiddlewareIR[];
39
39
  schemas: SchemaIR[];
40
40
  entities: EntityIR[];
41
+ databases: DatabaseIR[];
41
42
  dependencyGraph: DependencyGraphIR;
42
43
  diagnostics: Diagnostic[];
43
44
  }
@@ -163,6 +164,9 @@ interface ResolvedField {
163
164
  tsType: "string" | "number" | "boolean" | "date" | "unknown";
164
165
  optional: boolean;
165
166
  }
167
+ interface DatabaseIR extends SourceLocation {
168
+ modelKeys: string[];
169
+ }
166
170
  interface EntityIR extends SourceLocation {
167
171
  name: string;
168
172
  modelRef: EntityModelRef;
@@ -208,6 +212,8 @@ interface EntityActionIR extends SourceLocation {
208
212
  }
209
213
  interface EntityRelationIR {
210
214
  name: string;
215
+ type?: "one" | "many";
216
+ entity?: string;
211
217
  selection: "all" | string[];
212
218
  }
213
219
  interface ModuleDefContext {
@@ -291,6 +297,24 @@ declare class AppAnalyzer extends BaseAnalyzer<AppAnalyzerResult> {
291
297
  private extractRegistrations;
292
298
  private extractOptions;
293
299
  }
300
+ interface DatabaseAnalyzerResult {
301
+ databases: DatabaseIR[];
302
+ }
303
+ declare class DatabaseAnalyzer extends BaseAnalyzer<DatabaseAnalyzerResult> {
304
+ analyze(): Promise<DatabaseAnalyzerResult>;
305
+ private findCreateDbCalls;
306
+ private extractDatabase;
307
+ /**
308
+ * Resolves an expression to an ObjectLiteralExpression.
309
+ * Handles inline object literals and variable references.
310
+ */
311
+ private resolveObjectLiteral;
312
+ /**
313
+ * Extracts property keys from a models object, emitting warnings for
314
+ * spread assignments and computed property names that can't be resolved.
315
+ */
316
+ private extractModelKeys;
317
+ }
294
318
  interface DependencyGraphInput {
295
319
  modules: ModuleIR[];
296
320
  middleware: MiddlewareIR[];
@@ -312,43 +336,6 @@ declare class DependencyGraphAnalyzer extends BaseAnalyzer<DependencyGraphResult
312
336
  private emitUnresolvedInjectDiagnostics;
313
337
  private warnUnresolvedInjects;
314
338
  }
315
- interface EnvAnalyzerResult {
316
- env: EnvIR | undefined;
317
- }
318
- declare class EnvAnalyzer extends BaseAnalyzer<EnvAnalyzerResult> {
319
- analyze(): Promise<EnvAnalyzerResult>;
320
- }
321
- interface MiddlewareAnalyzerResult {
322
- middleware: MiddlewareIR[];
323
- }
324
- declare class MiddlewareAnalyzer extends BaseAnalyzer<MiddlewareAnalyzerResult> {
325
- analyze(): Promise<MiddlewareAnalyzerResult>;
326
- private resolveSchemaRef;
327
- }
328
- import { Expression, ObjectLiteralExpression } from "ts-morph";
329
- interface ModuleAnalyzerResult {
330
- modules: ModuleIR[];
331
- }
332
- declare class ModuleAnalyzer extends BaseAnalyzer<ModuleAnalyzerResult> {
333
- analyze(): Promise<ModuleAnalyzerResult>;
334
- }
335
- declare function parseImports(obj: ObjectLiteralExpression): ImportRef[];
336
- declare function extractIdentifierNames(expr: Expression): string[];
337
- interface RouteAnalyzerResult {
338
- routers: RouterIR[];
339
- }
340
- declare class RouteAnalyzer extends BaseAnalyzer<RouteAnalyzerResult> {
341
- analyze(): Promise<RouteAnalyzerResult>;
342
- analyzeForModules(context: ModuleDefContext): Promise<RouteAnalyzerResult>;
343
- private detectUnknownRouterCalls;
344
- private extractRoutes;
345
- private findChainedHttpCalls;
346
- private chainResolvesToVariable;
347
- private extractRoute;
348
- private resolveSchemaRef;
349
- private extractMiddlewareRefs;
350
- private generateOperationId;
351
- }
352
339
  interface EntityAnalyzerResult {
353
340
  entities: EntityIR[];
354
341
  }
@@ -391,6 +378,53 @@ declare class EntityAnalyzer extends BaseAnalyzer<EntityAnalyzerResult> {
391
378
  private extractActions;
392
379
  private resolveSchemaFromExpression;
393
380
  private extractRelations;
381
+ /**
382
+ * Resolve relation types from the model's TypeScript type.
383
+ * Navigates ModelDef.relations to extract _type ('one'/'many') for each relation.
384
+ */
385
+ private resolveModelRelationTypes;
386
+ /**
387
+ * Post-processing: resolve relation `entity` fields by matching
388
+ * each relation's _target return type to the table type of known entities.
389
+ */
390
+ private resolveRelationEntities;
391
+ }
392
+ interface EnvAnalyzerResult {
393
+ env: EnvIR | undefined;
394
+ }
395
+ declare class EnvAnalyzer extends BaseAnalyzer<EnvAnalyzerResult> {
396
+ analyze(): Promise<EnvAnalyzerResult>;
397
+ }
398
+ interface MiddlewareAnalyzerResult {
399
+ middleware: MiddlewareIR[];
400
+ }
401
+ declare class MiddlewareAnalyzer extends BaseAnalyzer<MiddlewareAnalyzerResult> {
402
+ analyze(): Promise<MiddlewareAnalyzerResult>;
403
+ private resolveSchemaRef;
404
+ }
405
+ import { Expression, ObjectLiteralExpression } from "ts-morph";
406
+ interface ModuleAnalyzerResult {
407
+ modules: ModuleIR[];
408
+ }
409
+ declare class ModuleAnalyzer extends BaseAnalyzer<ModuleAnalyzerResult> {
410
+ analyze(): Promise<ModuleAnalyzerResult>;
411
+ }
412
+ declare function parseImports(obj: ObjectLiteralExpression): ImportRef[];
413
+ declare function extractIdentifierNames(expr: Expression): string[];
414
+ interface RouteAnalyzerResult {
415
+ routers: RouterIR[];
416
+ }
417
+ declare class RouteAnalyzer extends BaseAnalyzer<RouteAnalyzerResult> {
418
+ analyze(): Promise<RouteAnalyzerResult>;
419
+ analyzeForModules(context: ModuleDefContext): Promise<RouteAnalyzerResult>;
420
+ private detectUnknownRouterCalls;
421
+ private extractRoutes;
422
+ private findChainedHttpCalls;
423
+ private chainResolvesToVariable;
424
+ private extractRoute;
425
+ private resolveSchemaRef;
426
+ private extractMiddlewareRefs;
427
+ private generateOperationId;
394
428
  }
395
429
  import { Expression as Expression2, SourceFile } from "ts-morph";
396
430
  interface SchemaAnalyzerResult {
@@ -439,6 +473,7 @@ interface CompilerDependencies {
439
473
  module: Analyzer<ModuleAnalyzerResult>;
440
474
  app: Analyzer<AppAnalyzerResult>;
441
475
  entity: Analyzer<EntityAnalyzerResult>;
476
+ database: Analyzer<DatabaseAnalyzerResult>;
442
477
  dependencyGraph: Analyzer<DependencyGraphResult>;
443
478
  };
444
479
  validators: Validator[];
@@ -799,6 +834,7 @@ declare class CompletenessValidator implements Validator {
799
834
  private checkRoutePathFormat;
800
835
  private checkPathParamMatch;
801
836
  private checkDuplicateRoutes;
837
+ private checkEntityModelRegistration;
802
838
  private checkCtxKeyCollisions;
803
839
  }
804
840
  declare class ModuleValidator implements Validator {
@@ -824,4 +860,4 @@ declare class PlacementValidator implements Validator {
824
860
  private checkFileLocation;
825
861
  private checkMixedExports;
826
862
  }
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 };
863
+ 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, DatabaseIR, DatabaseAnalyzerResult, DatabaseAnalyzer, CreateDiagnosticOptions, CompletenessValidator, CompilerDependencies, CompilerConfig, Compiler, CompileResult, CategorizedChanges, CategorizeOptions, BootModuleEntry, BootMiddlewareEntry, BootManifest, BootGenerator, BaseGenerator, BaseAnalyzer, AppManifest, AppIR, AppDefinition, AppAnalyzerResult, AppAnalyzer, Analyzer };