@dbsp/core 1.6.0 → 1.7.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
@@ -3097,10 +3097,6 @@ declare class IntentBuilder<TResult = unknown> {
3097
3097
  * Apply relation hints to includes that don't have explicit `via`.
3098
3098
  */
3099
3099
  applyRelationHints(intent: QueryIntent): QueryIntent;
3100
- /**
3101
- * Apply relation hint to a single include (recursively).
3102
- */
3103
- private applyHintToInclude;
3104
3100
  /**
3105
3101
  * Clone the current state for immutable builder pattern.
3106
3102
  */
@@ -4444,10 +4440,6 @@ declare class QueryBuilderImpl<TResult = unknown> implements QueryBuilder<TResul
4444
4440
  */
4445
4441
  /** @internal — called by stream-impl */
4446
4442
  applyRelationHints(intent: QueryIntent): QueryIntent;
4447
- /**
4448
- * Apply relation hint to a single include (recursively).
4449
- */
4450
- private applyHintToInclude;
4451
4443
  /**
4452
4444
  * Build the QueryIntent from current state.
4453
4445
  * Handles exactOptionalPropertyTypes by only including defined properties.
@@ -6670,6 +6662,19 @@ declare class AmbiguousRelationError extends Error {
6670
6662
  * ```
6671
6663
  */
6672
6664
  declare function findClosestMatch(target: string, candidates: readonly string[]): string | undefined;
6665
+ type TableScopedErrorOptions = {
6666
+ table: string;
6667
+ requested: string;
6668
+ available: readonly string[];
6669
+ };
6670
+ declare abstract class TableScopedError extends Error {
6671
+ readonly table: string;
6672
+ readonly requested: string;
6673
+ readonly available: readonly string[];
6674
+ readonly suggestion?: string;
6675
+ readonly publicMessage: string;
6676
+ protected constructor(opts: TableScopedErrorOptions, genericMessage: string);
6677
+ }
6673
6678
  /**
6674
6679
  * Error thrown when a requested relation does not exist.
6675
6680
  *
@@ -6688,7 +6693,7 @@ declare function findClosestMatch(target: string, candidates: readonly string[])
6688
6693
  * // err.suggestion === 'comments'
6689
6694
  * ```
6690
6695
  */
6691
- declare class RelationNotFoundError extends Error {
6696
+ declare class RelationNotFoundError extends TableScopedError {
6692
6697
  readonly name: "RelationNotFoundError";
6693
6698
  /**
6694
6699
  * The table where the relation was requested.
@@ -6807,7 +6812,7 @@ declare class TableNotFoundError extends Error {
6807
6812
  * // err.suggestion === 'email'
6808
6813
  * ```
6809
6814
  */
6810
- declare class ColumnNotFoundError extends Error {
6815
+ declare class ColumnNotFoundError extends TableScopedError {
6811
6816
  readonly name: "ColumnNotFoundError";
6812
6817
  /**
6813
6818
  * The table where the column was requested.
package/dist/index.js CHANGED
@@ -1803,31 +1803,14 @@ function levenshteinDistance(a, b) {
1803
1803
  const lastRow = matrix[b.length];
1804
1804
  return lastRow ? lastRow[a.length] ?? 0 : 0;
1805
1805
  }
1806
- var RelationNotFoundError = class _RelationNotFoundError extends Error {
1807
- name = "RelationNotFoundError";
1808
- /**
1809
- * The table where the relation was requested.
1810
- */
1806
+ var TableScopedError = class extends Error {
1811
1807
  table;
1812
- /**
1813
- * The relation name that was requested but not found.
1814
- */
1815
1808
  requested;
1816
- /**
1817
- * Available relations on this table.
1818
- */
1819
1809
  available;
1820
- /**
1821
- * Suggested relation name (fuzzy match), if any.
1822
- */
1823
1810
  suggestion;
1824
- /**
1825
- * Public-safe message (no schema enumeration).
1826
- */
1827
1811
  publicMessage;
1828
- constructor(opts) {
1812
+ constructor(opts, genericMessage) {
1829
1813
  const suggestion = findClosestMatch(opts.requested, opts.available);
1830
- const genericMessage = "Relation not found";
1831
1814
  super(genericMessage);
1832
1815
  this.table = opts.table;
1833
1816
  this.requested = opts.requested;
@@ -1836,6 +1819,12 @@ var RelationNotFoundError = class _RelationNotFoundError extends Error {
1836
1819
  if (suggestion !== void 0) {
1837
1820
  this.suggestion = suggestion;
1838
1821
  }
1822
+ }
1823
+ };
1824
+ var RelationNotFoundError = class _RelationNotFoundError extends TableScopedError {
1825
+ name = "RelationNotFoundError";
1826
+ constructor(opts) {
1827
+ super(opts, "Relation not found");
1839
1828
  Object.setPrototypeOf(this, _RelationNotFoundError.prototype);
1840
1829
  }
1841
1830
  };
@@ -1923,39 +1912,10 @@ var TableNotFoundError = class _TableNotFoundError extends Error {
1923
1912
  Object.setPrototypeOf(this, _TableNotFoundError.prototype);
1924
1913
  }
1925
1914
  };
1926
- var ColumnNotFoundError = class _ColumnNotFoundError extends Error {
1915
+ var ColumnNotFoundError = class _ColumnNotFoundError extends TableScopedError {
1927
1916
  name = "ColumnNotFoundError";
1928
- /**
1929
- * The table where the column was requested.
1930
- */
1931
- table;
1932
- /**
1933
- * The column name that was requested but not found.
1934
- */
1935
- requested;
1936
- /**
1937
- * Available columns on this table.
1938
- */
1939
- available;
1940
- /**
1941
- * Suggested column name (fuzzy match), if any.
1942
- */
1943
- suggestion;
1944
- /**
1945
- * Public-safe message (no schema enumeration).
1946
- */
1947
- publicMessage;
1948
1917
  constructor(opts) {
1949
- const suggestion = findClosestMatch(opts.requested, opts.available);
1950
- const genericMessage = "Column not found";
1951
- super(genericMessage);
1952
- this.table = opts.table;
1953
- this.requested = opts.requested;
1954
- this.available = opts.available;
1955
- this.publicMessage = genericMessage;
1956
- if (suggestion !== void 0) {
1957
- this.suggestion = suggestion;
1958
- }
1918
+ super(opts, "Column not found");
1959
1919
  Object.setPrototypeOf(this, _ColumnNotFoundError.prototype);
1960
1920
  }
1961
1921
  };
@@ -4611,6 +4571,32 @@ function createHookManager() {
4611
4571
  return new HookManagerImpl();
4612
4572
  }
4613
4573
 
4574
+ // src/dx/include-hints.ts
4575
+ function applyHintToIncludeRecursive(inc, relationHints) {
4576
+ if (inc.via !== void 0) {
4577
+ if (inc.include && inc.include.length > 0) {
4578
+ return {
4579
+ ...inc,
4580
+ include: inc.include.map(
4581
+ (nested) => applyHintToIncludeRecursive(nested, relationHints)
4582
+ )
4583
+ };
4584
+ }
4585
+ return inc;
4586
+ }
4587
+ const hint = relationHints[inc.relation];
4588
+ const result = hint ? { ...inc, via: hint } : inc;
4589
+ if (result.include && result.include.length > 0) {
4590
+ return {
4591
+ ...result,
4592
+ include: result.include.map(
4593
+ (nested) => applyHintToIncludeRecursive(nested, relationHints)
4594
+ )
4595
+ };
4596
+ }
4597
+ return result;
4598
+ }
4599
+
4614
4600
  // src/dx/subquery-builder.ts
4615
4601
  var SubqueryBuilder = class _SubqueryBuilder {
4616
4602
  _from;
@@ -5258,38 +5244,13 @@ var IntentBuilder = class _IntentBuilder {
5258
5244
  return intent;
5259
5245
  }
5260
5246
  const updatedIncludes = intent.include.map(
5261
- (inc) => this.applyHintToInclude(inc)
5247
+ (inc) => applyHintToIncludeRecursive(inc, this.relationHints)
5262
5248
  );
5263
5249
  return {
5264
5250
  ...intent,
5265
5251
  include: updatedIncludes
5266
5252
  };
5267
5253
  }
5268
- /**
5269
- * Apply relation hint to a single include (recursively).
5270
- */
5271
- applyHintToInclude(inc) {
5272
- if (inc.via !== void 0) {
5273
- if (inc.include && inc.include.length > 0) {
5274
- return {
5275
- ...inc,
5276
- include: inc.include.map((nested) => this.applyHintToInclude(nested))
5277
- };
5278
- }
5279
- return inc;
5280
- }
5281
- const hint = this.relationHints[inc.relation];
5282
- const result = hint ? { ...inc, via: hint } : inc;
5283
- if (result.include && result.include.length > 0) {
5284
- return {
5285
- ...result,
5286
- include: result.include.map(
5287
- (nested) => this.applyHintToInclude(nested)
5288
- )
5289
- };
5290
- }
5291
- return result;
5292
- }
5293
5254
  /**
5294
5255
  * Clone the current state for immutable builder pattern.
5295
5256
  */
@@ -6901,11 +6862,13 @@ function toRuntimeBindingRow(bindName, row, columns, dbCasing) {
6901
6862
  }
6902
6863
  function createRuntimeBinding(bundle, bindName, rows, dbCasing) {
6903
6864
  const columns = requireMutationBindingColumns(bundle, bindName);
6865
+ const columnTypes = bundle.bindingOutputSchemas?.get(bindName)?.columnTypes;
6904
6866
  return {
6905
6867
  columns,
6906
6868
  rows: rows.map(
6907
6869
  (row) => toRuntimeBindingRow(bindName, row, columns, dbCasing)
6908
- )
6870
+ ),
6871
+ ...columnTypes !== void 0 && { columnTypes }
6909
6872
  };
6910
6873
  }
6911
6874
  function bindingEntryIsFinal(compiledIntent, bindName, boundQuery, sourceBundle) {
@@ -7536,6 +7499,14 @@ var NqlBuilderImpl = class {
7536
7499
  const runtimeBindings = /* @__PURE__ */ new Map();
7537
7500
  const sequence = [];
7538
7501
  const steps = createNqlProgramSteps(compiledIntent);
7502
+ const dumpRuntimeBindingPreview = (bindName) => {
7503
+ const columnTypes = sourceBundle.bindingOutputSchemas?.get(bindName)?.columnTypes;
7504
+ return {
7505
+ columns: requireMutationBindingColumns(sourceBundle, bindName),
7506
+ rows: [],
7507
+ ...columnTypes !== void 0 && { columnTypes }
7508
+ };
7509
+ };
7539
7510
  for (const step of steps) {
7540
7511
  if (step.kind === "mutation") {
7541
7512
  const statementBundle = this.createNqlStatementBundle(
@@ -7556,10 +7527,10 @@ var NqlBuilderImpl = class {
7556
7527
  params: compiled.parameters
7557
7528
  });
7558
7529
  if (step.bindName !== void 0) {
7559
- runtimeBindings.set(step.bindName, {
7560
- columns: requireMutationBindingColumns(sourceBundle, step.bindName),
7561
- rows: []
7562
- });
7530
+ runtimeBindings.set(
7531
+ step.bindName,
7532
+ dumpRuntimeBindingPreview(step.bindName)
7533
+ );
7563
7534
  }
7564
7535
  } else {
7565
7536
  const planReport = step.final && isBindingFinalQuery(compiledIntent.bundle) && compiledIntent.kind === "query" ? createBindingFinalPlan(
@@ -7587,10 +7558,10 @@ var NqlBuilderImpl = class {
7587
7558
  params: compiled.parameters
7588
7559
  });
7589
7560
  if (step.snapshot === true && step.bindName !== void 0) {
7590
- runtimeBindings.set(step.bindName, {
7591
- columns: requireMutationBindingColumns(sourceBundle, step.bindName),
7592
- rows: []
7593
- });
7561
+ runtimeBindings.set(
7562
+ step.bindName,
7563
+ dumpRuntimeBindingPreview(step.bindName)
7564
+ );
7594
7565
  }
7595
7566
  }
7596
7567
  if (step.bindName !== void 0) {
@@ -9542,38 +9513,13 @@ var QueryBuilderImpl = class _QueryBuilderImpl {
9542
9513
  return intent;
9543
9514
  }
9544
9515
  const updatedIncludes = intent.include.map(
9545
- (inc) => this.applyHintToInclude(inc)
9516
+ (inc) => applyHintToIncludeRecursive(inc, this.relationHints)
9546
9517
  );
9547
9518
  return {
9548
9519
  ...intent,
9549
9520
  include: updatedIncludes
9550
9521
  };
9551
9522
  }
9552
- /**
9553
- * Apply relation hint to a single include (recursively).
9554
- */
9555
- applyHintToInclude(inc) {
9556
- if (inc.via !== void 0) {
9557
- if (inc.include && inc.include.length > 0) {
9558
- return {
9559
- ...inc,
9560
- include: inc.include.map((nested) => this.applyHintToInclude(nested))
9561
- };
9562
- }
9563
- return inc;
9564
- }
9565
- const hint = this.relationHints[inc.relation];
9566
- const result = hint ? { ...inc, via: hint } : inc;
9567
- if (result.include && result.include.length > 0) {
9568
- return {
9569
- ...result,
9570
- include: result.include.map(
9571
- (nested) => this.applyHintToInclude(nested)
9572
- )
9573
- };
9574
- }
9575
- return result;
9576
- }
9577
9523
  /**
9578
9524
  * Build the QueryIntent from current state.
9579
9525
  * Handles exactOptionalPropertyTypes by only including defined properties.