@vibeorm/runtime 2.0.0-alpha.5 → 2.0.0-alpha.7

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/adapter.d.ts CHANGED
@@ -103,7 +103,13 @@ export type DatabaseAdapter = {
103
103
  transaction<T>(fn: (txAdapter: DatabaseAdapter) => Promise<T>, options?: TransactionOptions): Promise<T>;
104
104
  /** Eagerly open/verify connectivity (pool warm-up or first connection). */
105
105
  connect(): Promise<void>;
106
- /** Gracefully close all connections. */
106
+ /**
107
+ * Gracefully close the connections open right now. NOT terminal: every
108
+ * adapter constructs its pool/connection lazily, so a query issued after
109
+ * `disconnect()` transparently opens a NEW connection and succeeds — the
110
+ * documented contract (symmetric with lazy construction, and with Prisma's
111
+ * `$disconnect()`-then-query semantics), not an accident.
112
+ */
107
113
  disconnect(): Promise<void>;
108
114
  /**
109
115
  * Convert a JS array into the driver's preferred representation for a
@@ -117,7 +123,29 @@ export type SqlExecutor = (params: {
117
123
  text: string;
118
124
  values?: unknown[];
119
125
  }) => Promise<Record<string, unknown>[]>;
120
- /** Bridge a DatabaseAdapter to the migrate package's SqlExecutor shape. */
126
+ /**
127
+ * Bridge a DatabaseAdapter to the migrate package's SqlExecutor shape.
128
+ *
129
+ * NO SESSION AFFINITY — this bridge pins nothing. Every call goes through
130
+ * `adapter.executeUnsafe`, which a pooled adapter runs on whatever connection
131
+ * the pool hands out. @vibeorm/migrate's executor contract requires the
132
+ * opposite (`packages/migrate/src/types.ts`): its session-scoped statements
133
+ * (`BEGIN`/`COMMIT`, `PRAGMA foreign_keys`, `pg_advisory_lock` / `GET_LOCK`)
134
+ * must all reach ONE session. pglite and sqlite satisfy that by construction;
135
+ * a POOLED adapter (pg, mysql, bun) used for migrate must be constructed with
136
+ * a single-connection pool (`max: 1`; mysql `connectionLimit: 1`), as the
137
+ * `vibeorm` CLI does, or the caller must pin a connection another way —
138
+ * otherwise the advisory lock is taken on one connection while each
139
+ * migration's `BEGIN` runs on another, and a driver that reaps the idle
140
+ * lock-holding connection (node-postgres does, after 10s by default) releases
141
+ * the migration lock mid-run, silently.
142
+ *
143
+ * RE-ENTRANCY HAZARD: `pg_advisory_lock` is re-entrant per SESSION, so two
144
+ * concurrent `applyMigrations` calls sharing one adapter (hence one pool) can
145
+ * both "acquire" it on the same underlying connection and get zero mutual
146
+ * exclusion — separate CLI processes never collide this way, a programmatic
147
+ * caller sharing one adapter can.
148
+ */
121
149
  export declare function toSqlExecutor(params: {
122
150
  adapter: DatabaseAdapter;
123
151
  }): SqlExecutor;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAEjF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAIF,uEAAuE;AACvE,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAChC,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAIF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC;IAE7B;;;;OAIG;IACH,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EzG,2EAA2E;IAC3E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;;;;OAMG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;CAC9C,CAAC;AAIF,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,GAAG,WAAW,CAS/E"}
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ function isDbNow(value) {
31
31
  return false;
32
32
  }
33
33
  const candidate = value;
34
- return candidate.__vibeDbNow === true && typeof candidate.offsetSeconds === "number" && Number.isInteger(candidate.offsetSeconds);
34
+ return candidate.__vibeDbNow === true && typeof candidate.offsetSeconds === "number" && Number.isFinite(candidate.offsetSeconds);
35
35
  }
36
36
  // packages/runtime/src/model-meta.ts
37
37
  import { VibeError as VibeError2, isEnumType, validateComputedConfig } from "@vibeorm/schema";
@@ -178,10 +178,10 @@ function buildModelMeta(params) {
178
178
  }
179
179
  return resolved;
180
180
  };
181
- const addCompound = (names, nullsNotDistinct) => {
181
+ const addCompound = (names, nullsNotDistinct, clientName) => {
182
182
  if (names.length < 2)
183
183
  return;
184
- const key = names.join("_");
184
+ const key = clientName ?? names.join("_");
185
185
  if (compoundUniques.has(key))
186
186
  return;
187
187
  const resolved = resolveFields(names);
@@ -189,8 +189,14 @@ function buildModelMeta(params) {
189
189
  return;
190
190
  compoundUniques.set(key, { fields: resolved, nullsNotDistinct });
191
191
  };
192
- if (primaryKey.length > 1)
193
- addCompound(primaryKey.map((field) => field.name), false);
192
+ if (primaryKey.length > 1) {
193
+ addCompound(primaryKey.map((field) => field.name), false, model.primaryKey?.clientName);
194
+ } else {
195
+ const only = primaryKey[0];
196
+ if (only !== undefined && !only.isId && !only.isUnique) {
197
+ singleIndexUniques.push({ fields: [only], nullsNotDistinct: false });
198
+ }
199
+ }
194
200
  for (const index of model.indexes) {
195
201
  if (index.kind !== "unique" || index.where !== undefined)
196
202
  continue;
@@ -204,7 +210,7 @@ function buildModelMeta(params) {
204
210
  continue;
205
211
  singleIndexUniques.push({ fields: [field], nullsNotDistinct });
206
212
  } else {
207
- addCompound(names, nullsNotDistinct);
213
+ addCompound(names, nullsNotDistinct, index.clientName);
208
214
  }
209
215
  }
210
216
  const computedSpecs = params.computed;
@@ -7029,4 +7035,4 @@ export {
7029
7035
  COUNT_ALIAS
7030
7036
  };
7031
7037
 
7032
- //# debugId=0C003BB2F334C66D64756E2164756E21
7038
+ //# debugId=96AA73705B84E72364756E2164756E21