turbine-orm 0.23.1 → 0.24.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.
Files changed (80) hide show
  1. package/README.md +4 -1
  2. package/dist/adapters/cockroachdb.d.ts +0 -1
  3. package/dist/adapters/cockroachdb.js +0 -1
  4. package/dist/adapters/index.d.ts +0 -1
  5. package/dist/adapters/index.js +0 -1
  6. package/dist/adapters/yugabytedb.d.ts +0 -1
  7. package/dist/adapters/yugabytedb.js +0 -1
  8. package/dist/cjs/cli/config.js +14 -0
  9. package/dist/cjs/cli/index.js +60 -0
  10. package/dist/cjs/schema-builder.js +29 -1
  11. package/dist/cjs/schema-sql.js +19 -5
  12. package/dist/cli/config.d.ts +14 -1
  13. package/dist/cli/config.js +13 -1
  14. package/dist/cli/index.d.ts +0 -1
  15. package/dist/cli/index.js +61 -2
  16. package/dist/cli/loader.d.ts +0 -1
  17. package/dist/cli/loader.js +0 -1
  18. package/dist/cli/migrate.d.ts +0 -1
  19. package/dist/cli/migrate.js +0 -1
  20. package/dist/cli/observe-ui.d.ts +0 -1
  21. package/dist/cli/observe-ui.js +0 -1
  22. package/dist/cli/observe.d.ts +0 -1
  23. package/dist/cli/observe.js +0 -1
  24. package/dist/cli/studio-ui.generated.d.ts +0 -1
  25. package/dist/cli/studio-ui.generated.js +0 -1
  26. package/dist/cli/studio.d.ts +0 -1
  27. package/dist/cli/studio.js +0 -1
  28. package/dist/cli/ui.d.ts +0 -1
  29. package/dist/cli/ui.js +0 -1
  30. package/dist/client.d.ts +0 -1
  31. package/dist/client.js +0 -1
  32. package/dist/dialect.d.ts +0 -1
  33. package/dist/dialect.js +0 -1
  34. package/dist/errors.d.ts +0 -1
  35. package/dist/errors.js +0 -1
  36. package/dist/generate.d.ts +0 -1
  37. package/dist/generate.js +0 -1
  38. package/dist/index.d.ts +0 -1
  39. package/dist/index.js +0 -1
  40. package/dist/introspect.d.ts +0 -1
  41. package/dist/introspect.js +0 -1
  42. package/dist/mssql.d.ts +0 -1
  43. package/dist/mssql.js +0 -1
  44. package/dist/mysql.d.ts +0 -1
  45. package/dist/mysql.js +0 -1
  46. package/dist/nested-write.d.ts +0 -1
  47. package/dist/nested-write.js +0 -1
  48. package/dist/observe.d.ts +0 -1
  49. package/dist/observe.js +0 -1
  50. package/dist/pipeline-submittable.d.ts +0 -1
  51. package/dist/pipeline-submittable.js +0 -1
  52. package/dist/pipeline.d.ts +0 -1
  53. package/dist/pipeline.js +0 -1
  54. package/dist/powdb.d.ts +0 -1
  55. package/dist/powdb.js +0 -1
  56. package/dist/powql.d.ts +0 -1
  57. package/dist/powql.js +0 -1
  58. package/dist/query/builder.d.ts +0 -1
  59. package/dist/query/builder.js +0 -1
  60. package/dist/query/index.d.ts +0 -1
  61. package/dist/query/index.js +0 -1
  62. package/dist/query/types.d.ts +0 -1
  63. package/dist/query/types.js +0 -1
  64. package/dist/query/utils.d.ts +0 -1
  65. package/dist/query/utils.js +0 -1
  66. package/dist/realtime.d.ts +0 -1
  67. package/dist/realtime.js +0 -1
  68. package/dist/schema-builder.d.ts +6 -4
  69. package/dist/schema-builder.js +29 -2
  70. package/dist/schema-sql.d.ts +0 -1
  71. package/dist/schema-sql.js +19 -6
  72. package/dist/schema.d.ts +0 -1
  73. package/dist/schema.js +0 -1
  74. package/dist/serverless.d.ts +0 -1
  75. package/dist/serverless.js +0 -1
  76. package/dist/sqlite.d.ts +0 -1
  77. package/dist/sqlite.js +0 -1
  78. package/dist/typed-sql.d.ts +0 -1
  79. package/dist/typed-sql.js +0 -1
  80. package/package.json +4 -4
@@ -24,7 +24,7 @@
24
24
  */
25
25
  import type { SchemaMetadata } from './schema.js';
26
26
  /** Shorthand type names that map to Postgres column types */
27
- export type ColumnTypeName = 'serial' | 'bigint' | 'integer' | 'smallint' | 'text' | 'varchar' | 'boolean' | 'timestamp' | 'date' | 'json' | 'uuid' | 'real' | 'double' | 'numeric' | 'bytea';
27
+ export type ColumnTypeName = 'serial' | 'bigserial' | 'bigint' | 'integer' | 'smallint' | 'text' | 'varchar' | 'boolean' | 'timestamp' | 'timestamptz' | 'date' | 'json' | 'jsonb' | 'uuid' | 'real' | 'double' | 'numeric' | 'bytea';
28
28
  /** Column definition as a plain object. This is what users write. */
29
29
  export interface ColumnDef {
30
30
  /** Column type (required) */
@@ -45,7 +45,7 @@ export interface ColumnDef {
45
45
  maxLength?: number;
46
46
  }
47
47
  /** Postgres-level column type (uppercase, as used in DDL) */
48
- export type ColumnType = 'BIGSERIAL' | 'BIGINT' | 'INTEGER' | 'SMALLINT' | 'TEXT' | 'BOOLEAN' | 'TIMESTAMPTZ' | 'JSONB' | 'UUID' | 'REAL' | 'DOUBLE PRECISION' | 'NUMERIC' | 'BYTEA' | 'DATE' | 'VARCHAR';
48
+ export type ColumnType = 'SERIAL' | 'BIGSERIAL' | 'BIGINT' | 'INTEGER' | 'SMALLINT' | 'TEXT' | 'BOOLEAN' | 'TIMESTAMPTZ' | 'JSONB' | 'UUID' | 'REAL' | 'DOUBLE PRECISION' | 'NUMERIC' | 'BYTEA' | 'DATE' | 'VARCHAR';
49
49
  export interface ColumnConfig {
50
50
  type: ColumnType;
51
51
  isPrimaryKey: boolean;
@@ -164,6 +164,7 @@ export declare class ColumnBuilder {
164
164
  private _config;
165
165
  constructor();
166
166
  serial(): this;
167
+ bigserial(): this;
167
168
  bigint(): this;
168
169
  integer(): this;
169
170
  smallint(): this;
@@ -171,8 +172,10 @@ export declare class ColumnBuilder {
171
172
  varchar(length: number): this;
172
173
  boolean(): this;
173
174
  timestamp(): this;
175
+ timestamptz(): this;
174
176
  date(): this;
175
177
  json(): this;
178
+ jsonb(): this;
176
179
  uuid(): this;
177
180
  real(): this;
178
181
  doublePrecision(): this;
@@ -188,7 +191,7 @@ export declare class ColumnBuilder {
188
191
  }
189
192
  /** @deprecated Use defineSchema() with plain objects instead */
190
193
  type ColumnProxy = {
191
- [K in 'serial' | 'bigint' | 'integer' | 'smallint' | 'text' | 'boolean' | 'timestamp' | 'date' | 'json' | 'uuid' | 'real' | 'doublePrecision' | 'numeric' | 'bytea']: () => ColumnBuilder;
194
+ [K in 'serial' | 'bigserial' | 'bigint' | 'integer' | 'smallint' | 'text' | 'boolean' | 'timestamp' | 'timestamptz' | 'date' | 'json' | 'jsonb' | 'uuid' | 'real' | 'doublePrecision' | 'numeric' | 'bytea']: () => ColumnBuilder;
192
195
  } & {
193
196
  varchar: (length: number) => ColumnBuilder;
194
197
  };
@@ -224,4 +227,3 @@ export declare function table(columns: Record<string, ColumnBuilder>): TableDef;
224
227
  */
225
228
  export declare function applyManyToManyRelations(meta: SchemaMetadata, def: SchemaDef): SchemaMetadata;
226
229
  export { camelToSnake } from './schema.js';
227
- //# sourceMappingURL=schema-builder.d.ts.map
@@ -24,16 +24,28 @@
24
24
  */
25
25
  /** Maps shorthand names to actual Postgres type strings */
26
26
  const TYPE_MAP = {
27
- serial: 'BIGSERIAL',
27
+ // `serial` maps to SERIAL (int4). Its values fit in a JS `number` and pg
28
+ // returns them as numbers — so the generated `number` type is accurate.
29
+ // For 64-bit auto-increment keys use `bigserial` (int8), noting that values
30
+ // above Number.MAX_SAFE_INTEGER read back as string. (Changed in 0.24.0;
31
+ // `serial` previously emitted BIGSERIAL.)
32
+ serial: 'SERIAL',
33
+ bigserial: 'BIGSERIAL',
28
34
  bigint: 'BIGINT',
29
35
  integer: 'INTEGER',
30
36
  smallint: 'SMALLINT',
31
37
  text: 'TEXT',
32
38
  varchar: 'VARCHAR',
33
39
  boolean: 'BOOLEAN',
40
+ // `timestamp` is an honest alias for TIMESTAMPTZ (timezone-aware) — Turbine
41
+ // has always emitted TIMESTAMPTZ for it. `timestamptz` is the explicit spelling.
34
42
  timestamp: 'TIMESTAMPTZ',
43
+ timestamptz: 'TIMESTAMPTZ',
35
44
  date: 'DATE',
45
+ // `json` is an alias for JSONB (Turbine has always emitted JSONB). `jsonb`
46
+ // is the explicit spelling.
36
47
  json: 'JSONB',
48
+ jsonb: 'JSONB',
37
49
  uuid: 'UUID',
38
50
  real: 'REAL',
39
51
  double: 'DOUBLE PRECISION',
@@ -178,6 +190,11 @@ export class ColumnBuilder {
178
190
  };
179
191
  }
180
192
  serial() {
193
+ // See TYPE_MAP: `serial` is SERIAL (int4) as of 0.24.0. Use bigserial() for 64-bit.
194
+ this._config.type = 'SERIAL';
195
+ return this;
196
+ }
197
+ bigserial() {
181
198
  this._config.type = 'BIGSERIAL';
182
199
  return this;
183
200
  }
@@ -210,6 +227,10 @@ export class ColumnBuilder {
210
227
  this._config.type = 'TIMESTAMPTZ';
211
228
  return this;
212
229
  }
230
+ timestamptz() {
231
+ this._config.type = 'TIMESTAMPTZ';
232
+ return this;
233
+ }
213
234
  date() {
214
235
  this._config.type = 'DATE';
215
236
  return this;
@@ -218,6 +239,10 @@ export class ColumnBuilder {
218
239
  this._config.type = 'JSONB';
219
240
  return this;
220
241
  }
242
+ jsonb() {
243
+ this._config.type = 'JSONB';
244
+ return this;
245
+ }
221
246
  uuid() {
222
247
  this._config.type = 'UUID';
223
248
  return this;
@@ -269,14 +294,17 @@ export class ColumnBuilder {
269
294
  /** Type guard: is `prop` a known nullary ColumnBuilder type method? */
270
295
  function isNullaryColumnType(prop) {
271
296
  return (prop === 'serial' ||
297
+ prop === 'bigserial' ||
272
298
  prop === 'bigint' ||
273
299
  prop === 'integer' ||
274
300
  prop === 'smallint' ||
275
301
  prop === 'text' ||
276
302
  prop === 'boolean' ||
277
303
  prop === 'timestamp' ||
304
+ prop === 'timestamptz' ||
278
305
  prop === 'date' ||
279
306
  prop === 'json' ||
307
+ prop === 'jsonb' ||
280
308
  prop === 'uuid' ||
281
309
  prop === 'real' ||
282
310
  prop === 'doublePrecision' ||
@@ -385,4 +413,3 @@ export function applyManyToManyRelations(meta, def) {
385
413
  // Helpers
386
414
  // ---------------------------------------------------------------------------
387
415
  export { camelToSnake } from './schema.js';
388
- //# sourceMappingURL=schema-builder.js.map
@@ -77,4 +77,3 @@ export declare function schemaPush(schema: SchemaDef, connectionString: string,
77
77
  * Useful for printing or saving to a .sql file.
78
78
  */
79
79
  export declare function schemaToSQLString(schema: SchemaDef, options?: SchemaSqlOptions): string;
80
- //# sourceMappingURL=schema-sql.d.ts.map
@@ -7,6 +7,15 @@
7
7
  import pg from 'pg';
8
8
  import { postgresDialect } from './dialect.js';
9
9
  import { camelToSnake } from './schema.js';
10
+ /**
11
+ * Whether a resolved column type is an auto-increment pseudo-type (SERIAL /
12
+ * BIGSERIAL). These carry an implicit sequence default and NOT NULL, and their
13
+ * underlying integer width (int4 vs int8) is never auto-migrated by diff — a
14
+ * width change on a live PK is destructive and must be done by hand.
15
+ */
16
+ function isSerialType(type) {
17
+ return type === 'SERIAL' || type === 'BIGSERIAL';
18
+ }
10
19
  // ---------------------------------------------------------------------------
11
20
  // SQL Generation — SchemaDef → CREATE TABLE statements
12
21
  // ---------------------------------------------------------------------------
@@ -154,7 +163,7 @@ function generateColumnDef(fieldName, config, resolveRef, dialect = postgresDial
154
163
  // 2. Is a serial (BIGSERIAL implies NOT NULL), OR
155
164
  // 3. Has a primary key (PKs are NOT NULL)
156
165
  // A column is left nullable if .nullable() was called.
157
- const isSerial = config.type === 'BIGSERIAL';
166
+ const isSerial = isSerialType(config.type);
158
167
  const implicitNotNull = isSerial || config.isPrimaryKey;
159
168
  const notNull = config.isNotNull && !implicitNotNull;
160
169
  // DEFAULT
@@ -343,9 +352,13 @@ export async function schemaDiff(schema, connectionString) {
343
352
  result.reverseStatements.unshift(reverseSql);
344
353
  continue;
345
354
  }
346
- // Check type mismatch
355
+ // Check type mismatch. Serial/bigserial columns are exempt: their
356
+ // underlying int4/int8 width must never be auto-altered on a live table
357
+ // (a downcast on a PK loses data / breaks the sequence). This also
358
+ // preserves back-compat for DBs whose `serial` columns were created as
359
+ // BIGSERIAL (int8) before 0.24.0 — `push` won't try to shrink them.
347
360
  const expectedUdt = schemaTypeToUdt(config);
348
- if (expectedUdt && dbCol.udtName !== expectedUdt) {
361
+ if (expectedUdt && !isSerialType(config.type) && dbCol.udtName !== expectedUdt) {
349
362
  const sqlType = config.type === 'VARCHAR' && config.maxLength ? `VARCHAR(${config.maxLength})` : config.type;
350
363
  const oldSqlType = udtToSqlType(dbCol.udtName, dbCol.maxLength);
351
364
  const sql = `ALTER TABLE ${dialect.quoteIdentifier(tableName)} ALTER COLUMN ${dialect.quoteIdentifier(snakeName)} TYPE ${sqlType} USING ${dialect.quoteIdentifier(snakeName)}::${sqlType};`;
@@ -355,7 +368,7 @@ export async function schemaDiff(schema, connectionString) {
355
368
  result.reverseStatements.unshift(reverseSql);
356
369
  }
357
370
  // Check NOT NULL mismatch
358
- const shouldBeNotNull = config.isNotNull || config.isPrimaryKey || config.type === 'BIGSERIAL';
371
+ const shouldBeNotNull = config.isNotNull || config.isPrimaryKey || isSerialType(config.type);
359
372
  const isCurrentlyNullable = dbCol.isNullable;
360
373
  if (shouldBeNotNull && isCurrentlyNullable && !config.isNullable) {
361
374
  const sql = `ALTER TABLE ${dialect.quoteIdentifier(tableName)} ALTER COLUMN ${dialect.quoteIdentifier(snakeName)} SET NOT NULL;`;
@@ -372,7 +385,7 @@ export async function schemaDiff(schema, connectionString) {
372
385
  result.reverseStatements.unshift(reverseSql);
373
386
  }
374
387
  // Check DEFAULT value mismatch
375
- const isSerial = config.type === 'BIGSERIAL';
388
+ const isSerial = isSerialType(config.type);
376
389
  if (!isSerial) {
377
390
  const schemaDefault = config.defaultValue ? normalizeDefault(config.defaultValue) : null;
378
391
  const dbDefault = dbCol.columnDefault;
@@ -451,6 +464,7 @@ export async function schemaDiff(schema, connectionString) {
451
464
  */
452
465
  function schemaTypeToUdt(config) {
453
466
  const map = {
467
+ SERIAL: 'int4',
454
468
  BIGSERIAL: 'int8',
455
469
  BIGINT: 'int8',
456
470
  INTEGER: 'int4',
@@ -567,4 +581,3 @@ export function schemaToSQLString(schema, options) {
567
581
  const statements = schemaToSQL(schema, options);
568
582
  return `${statements.join('\n\n')}\n`;
569
583
  }
570
- //# sourceMappingURL=schema-sql.js.map
package/dist/schema.d.ts CHANGED
@@ -122,4 +122,3 @@ export declare function camelToSnake(s: string): string;
122
122
  export declare function snakeToPascal(s: string): string;
123
123
  /** Naive singularize: "posts" → "post", "categories" → "category" */
124
124
  export declare function singularize(s: string): string;
125
- //# sourceMappingURL=schema.d.ts.map
package/dist/schema.js CHANGED
@@ -146,4 +146,3 @@ export function singularize(s) {
146
146
  return s.slice(0, -1);
147
147
  return s;
148
148
  }
149
- //# sourceMappingURL=schema.js.map
@@ -112,4 +112,3 @@ export interface TurbineHttpOptions extends Pick<TurbineConfig, 'logging' | 'def
112
112
  * ```
113
113
  */
114
114
  export declare function turbineHttp(pool: PgCompatPool, schema: SchemaMetadata, options?: TurbineHttpOptions): TurbineClient;
115
- //# sourceMappingURL=serverless.d.ts.map
@@ -106,4 +106,3 @@ import { TurbineClient } from './client.js';
106
106
  export function turbineHttp(pool, schema, options = {}) {
107
107
  return new TurbineClient({ pool, ...options }, schema);
108
108
  }
109
- //# sourceMappingURL=serverless.js.map
package/dist/sqlite.d.ts CHANGED
@@ -141,4 +141,3 @@ export interface TurbineSqliteOptions extends Pick<TurbineConfig, 'logging' | 'd
141
141
  */
142
142
  export declare function turbineSqlite(target: string | DatabaseSync, schema: SchemaMetadata, options?: TurbineSqliteOptions): TurbineClient;
143
143
  export {};
144
- //# sourceMappingURL=sqlite.d.ts.map
package/dist/sqlite.js CHANGED
@@ -839,4 +839,3 @@ export function turbineSqlite(target, schema, options = {}) {
839
839
  warnOnUnlimited: options.warnOnUnlimited,
840
840
  }, schema);
841
841
  }
842
- //# sourceMappingURL=sqlite.js.map
@@ -100,4 +100,3 @@ export declare class TypedSqlQuery<T extends Record<string, unknown>> implements
100
100
  */
101
101
  scalar<V = T[keyof T]>(): Promise<V | null>;
102
102
  }
103
- //# sourceMappingURL=typed-sql.d.ts.map
package/dist/typed-sql.js CHANGED
@@ -144,4 +144,3 @@ export class TypedSqlQuery {
144
144
  return first[keys[0]];
145
145
  }
146
146
  }
147
- //# sourceMappingURL=typed-sql.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turbine-orm",
3
- "version": "0.23.1",
3
+ "version": "0.24.0",
4
4
  "description": "Postgres-native TypeScript ORM — runs on Neon, Vercel Postgres, Cloudflare, Supabase. Streaming cursors, typed errors, single-query nested relations. One dependency, no WASM engine",
5
5
  "type": "module",
6
6
  "exports": {
@@ -102,13 +102,13 @@
102
102
  "@biomejs/biome": "^2.4.10",
103
103
  "@size-limit/esbuild": "^12.1.0",
104
104
  "@size-limit/file": "^12.1.0",
105
- "@types/node": "^22.10.0",
105
+ "@types/node": "^26.1.0",
106
106
  "c8": "^11.0.0",
107
107
  "husky": "^9.1.7",
108
- "lint-staged": "^16.4.0",
108
+ "lint-staged": "^17.0.8",
109
109
  "@zvndev/powdb-client": "^0.8.0",
110
110
  "@zvndev/powdb-embedded": "^0.8.0",
111
- "mssql": "^11.0.1",
111
+ "mssql": "^12.7.0",
112
112
  "mysql2": "^3.22.5",
113
113
  "size-limit": "^12.1.0",
114
114
  "tsx": "^4.19.0",