@dbsp/nql 1.6.0 → 1.8.0

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.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CompiledNqlQuery } from '@dbsp/types';
1
+ import { ColumnType, CompiledNqlQuery } from '@dbsp/types';
2
2
  export { CompiledNqlQuery, DeleteIntent, ExpressionIntent, IncludeIntent, InsertIntent, MutationIntent, OrderByIntent, QueryIntent, SelectAllIntent, SelectFieldsIntent, SelectIntent, SelectWithExpressionsIntent, UpdateIntent, UpsertIntent, WhereAndIntent, WhereComparisonIntent, WhereInIntent, WhereIntent, WhereLikeIntent, WhereNotIntent, WhereNullIntent, WhereOrIntent, WhereRangeIntent } from '@dbsp/types';
3
3
  import * as chevrotain from 'chevrotain';
4
4
  import { Lexer, CstParser, CstNode, IToken } from 'chevrotain';
@@ -402,21 +402,73 @@ interface NqlAssignment {
402
402
  value: NqlExpression;
403
403
  }
404
404
 
405
+ /**
406
+ * NQL Error Types
407
+ *
408
+ * Structured error types for lexer, parser, and semantic errors.
409
+ */
410
+ /** Source location for error reporting */
411
+ interface SourceLocation {
412
+ line: number;
413
+ column: number;
414
+ offset: number;
415
+ }
416
+ /** Base error interface for all NQL errors */
417
+ interface NqlError {
418
+ code: string;
419
+ message: string;
420
+ location?: SourceLocation | undefined;
421
+ suggestion?: string | undefined;
422
+ }
423
+ /** Parser errors (syntax errors) */
424
+ interface NqlParseError extends NqlError {
425
+ code: `ERR-PARSE-${string}`;
426
+ expected?: string[] | undefined;
427
+ found?: string | undefined;
428
+ }
429
+ /** Semantic errors (validation failures) */
430
+ interface NqlSemanticError extends NqlError {
431
+ code: `ERR-SEM-${string}`;
432
+ relatedSymbol?: string | undefined;
433
+ }
434
+ /** Warning (non-fatal issues) */
435
+ interface NqlWarning {
436
+ code: string;
437
+ message: string;
438
+ location?: SourceLocation | undefined;
439
+ suggestion?: string | undefined;
440
+ }
441
+
405
442
  type CompileResult = CompiledNqlQuery;
406
443
 
407
444
  /**
408
445
  * Duck-type interface for schema-based column validation.
409
446
  * Loose coupling: ModelIR from @dbsp/core satisfies this shape without direct import.
410
447
  */
448
+ interface ColumnValidatorPseudoColumn {
449
+ readonly table?: string;
450
+ readonly foreignKeyColumn?: string;
451
+ readonly targetColumn?: string;
452
+ readonly parentRole: string;
453
+ readonly childRole: string;
454
+ readonly ascendantKeyword?: string;
455
+ readonly descendantKeyword?: string;
456
+ }
457
+ /**
458
+ * Duck-type column shape carried by `ColumnValidatorSchema.getTable()`.
459
+ * `type`/`originalDbType` are optional so hand-authored test schemas that
460
+ * only supply `name` remain valid — absence makes a column's type
461
+ * unresolvable (untypeable), never silently mismatched.
462
+ */
463
+ interface ColumnValidatorTableColumn {
464
+ readonly name: string;
465
+ readonly type?: ColumnType;
466
+ readonly originalDbType?: string;
467
+ }
411
468
  interface ColumnValidatorSchema {
412
469
  getTable(name: string): {
413
- readonly columns: readonly {
414
- readonly name: string;
415
- }[];
416
- readonly pseudoColumns?: readonly {
417
- readonly parentRole: string;
418
- readonly childRole: string;
419
- }[];
470
+ readonly columns: readonly ColumnValidatorTableColumn[];
471
+ readonly pseudoColumns?: readonly ColumnValidatorPseudoColumn[];
420
472
  } | undefined;
421
473
  getRelationsFrom(sourceTable: string): readonly ColumnValidatorRelation[];
422
474
  getRelation?(qualifiedName: string): ColumnValidatorRelation | undefined;
@@ -428,7 +480,7 @@ interface ColumnValidatorRelation {
428
480
  readonly type?: 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany';
429
481
  readonly foreignKey?: string | readonly string[] | undefined;
430
482
  readonly through?: string | undefined;
431
- readonly otherKey?: string | undefined;
483
+ readonly otherKey?: string | readonly string[] | undefined;
432
484
  readonly throughSourceKey?: string | undefined;
433
485
  readonly throughTargetKey?: string | undefined;
434
486
  readonly recursive?: unknown;
@@ -475,6 +527,15 @@ declare class NqlCompiler {
475
527
  private registerQueryBindingOutputSchema;
476
528
  private canonicalizeMutationBinding;
477
529
  private getMutationBindingOutputSchema;
530
+ /**
531
+ * Build `columnTypes`/`columnTypesUnavailable` for a mutation-RETURNING
532
+ * binding. #213 B2: detection consumes `ctx.lastMutationReturningItems`
533
+ * (alias-aware, positional) — NEVER the collapsed `columns` names — so an
534
+ * alias colliding with a real column (`returning email as name`) is
535
+ * flagged 'aliased-returning' rather than silently mistyped as the
536
+ * colliding column's type.
537
+ */
538
+ private buildMutationReturningColumnTypes;
478
539
  private compileSingleStatement;
479
540
  }
480
541
  /**
@@ -482,43 +543,6 @@ declare class NqlCompiler {
482
543
  */
483
544
  declare function createCompiler(options?: NqlCompilerOptions, schema?: ColumnValidatorSchema): NqlCompiler;
484
545
 
485
- /**
486
- * NQL Error Types
487
- *
488
- * Structured error types for lexer, parser, and semantic errors.
489
- */
490
- /** Source location for error reporting */
491
- interface SourceLocation {
492
- line: number;
493
- column: number;
494
- offset: number;
495
- }
496
- /** Base error interface for all NQL errors */
497
- interface NqlError {
498
- code: string;
499
- message: string;
500
- location?: SourceLocation | undefined;
501
- suggestion?: string | undefined;
502
- }
503
- /** Parser errors (syntax errors) */
504
- interface NqlParseError extends NqlError {
505
- code: `ERR-PARSE-${string}`;
506
- expected?: string[] | undefined;
507
- found?: string | undefined;
508
- }
509
- /** Semantic errors (validation failures) */
510
- interface NqlSemanticError extends NqlError {
511
- code: `ERR-SEM-${string}`;
512
- relatedSymbol?: string | undefined;
513
- }
514
- /** Warning (non-fatal issues) */
515
- interface NqlWarning {
516
- code: string;
517
- message: string;
518
- location?: SourceLocation | undefined;
519
- suggestion?: string | undefined;
520
- }
521
-
522
546
  declare const allTokens: chevrotain.TokenType[];
523
547
  declare const NqlLexer: Lexer;
524
548