@dbsp/core 1.9.0 → 1.10.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
@@ -1693,13 +1693,14 @@ declare class UnsupportedStrategyError extends Error {
1693
1693
  */
1694
1694
  declare class ModelIRImpl implements ModelIR {
1695
1695
  readonly tables: ReadonlyMap<string, TableIR>;
1696
+ readonly externalTables: ReadonlySet<string>;
1696
1697
  readonly relations: ReadonlyMap<string, RelationIR>;
1697
1698
  readonly enums?: ReadonlyMap<string, EnumIR>;
1698
1699
  readonly extensions?: readonly string[];
1699
1700
  readonly sequences?: ReadonlyMap<string, SequenceIR>;
1700
1701
  private readonly relationsBySource;
1701
1702
  private readonly relationsByTarget;
1702
- constructor(tables: Map<string, TableIR>, relations: Map<string, RelationIR>, enums?: Map<string, EnumIR>, extensions?: readonly string[], sequences?: Map<string, SequenceIR>);
1703
+ constructor(tables: Map<string, TableIR>, relations: Map<string, RelationIR>, enums?: Map<string, EnumIR>, extensions?: readonly string[], sequences?: Map<string, SequenceIR>, externalTables?: Iterable<string>);
1703
1704
  /**
1704
1705
  * Get table by name
1705
1706
  */
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ import * as types_star from "@dbsp/types";
60
60
  // src/model-impl.ts
61
61
  var ModelIRImpl = class {
62
62
  tables;
63
+ externalTables;
63
64
  relations;
64
65
  enums;
65
66
  extensions;
@@ -67,8 +68,11 @@ var ModelIRImpl = class {
67
68
  // Pre-computed indexes for efficient lookups
68
69
  relationsBySource;
69
70
  relationsByTarget;
70
- constructor(tables, relations, enums, extensions, sequences) {
71
+ constructor(tables, relations, enums, extensions, sequences, externalTables) {
71
72
  this.tables = Object.freeze(new Map(tables));
73
+ this.externalTables = Object.freeze(
74
+ new Set(externalTables)
75
+ );
72
76
  this.relations = Object.freeze(new Map(relations));
73
77
  if (enums) {
74
78
  this.enums = Object.freeze(new Map(enums));
@@ -156,6 +160,11 @@ var ModelIRImpl = class {
156
160
  validate() {
157
161
  const errors = [];
158
162
  for (const table of this.tables.values()) {
163
+ if (this.externalTables.has(table.name)) {
164
+ errors.push(
165
+ `Table "${table.name}" cannot be both managed and external`
166
+ );
167
+ }
159
168
  if (table.primaryKey) {
160
169
  const pkCols = Array.isArray(table.primaryKey) ? table.primaryKey : [table.primaryKey];
161
170
  for (const pk of pkCols) {
@@ -169,7 +178,7 @@ var ModelIRImpl = class {
169
178
  }
170
179
  for (const table of this.tables.values()) {
171
180
  for (const fk of table.foreignKeys) {
172
- if (!this.tables.has(fk.references.table)) {
181
+ if (!this.tables.has(fk.references.table) && !this.externalTables.has(fk.references.table)) {
173
182
  errors.push(
174
183
  `Table "${table.name}" has FK referencing non-existent table "${fk.references.table}"`
175
184
  );
@@ -10240,6 +10249,9 @@ function generateCreateIndexSQL(tableName, schemaName, opts) {
10240
10249
  `INCLUDE (${opts.include.map((c) => quoteIdent(c)).join(", ")})`
10241
10250
  );
10242
10251
  }
10252
+ if (opts.unique && opts.nullsNotDistinct) {
10253
+ parts.push("NULLS NOT DISTINCT");
10254
+ }
10243
10255
  if (opts.with && Object.keys(opts.with).length > 0) {
10244
10256
  const withClauses = Object.entries(opts.with).map(([k, v2]) => `${k} = ${v2}`).join(", ");
10245
10257
  parts.push(`WITH (${withClauses})`);