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.
- package/README.md +4 -1
- package/dist/adapters/cockroachdb.d.ts +0 -1
- package/dist/adapters/cockroachdb.js +0 -1
- package/dist/adapters/index.d.ts +0 -1
- package/dist/adapters/index.js +0 -1
- package/dist/adapters/yugabytedb.d.ts +0 -1
- package/dist/adapters/yugabytedb.js +0 -1
- package/dist/cjs/cli/config.js +14 -0
- package/dist/cjs/cli/index.js +60 -0
- package/dist/cjs/schema-builder.js +29 -1
- package/dist/cjs/schema-sql.js +19 -5
- package/dist/cli/config.d.ts +14 -1
- package/dist/cli/config.js +13 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +61 -2
- package/dist/cli/loader.d.ts +0 -1
- package/dist/cli/loader.js +0 -1
- package/dist/cli/migrate.d.ts +0 -1
- package/dist/cli/migrate.js +0 -1
- package/dist/cli/observe-ui.d.ts +0 -1
- package/dist/cli/observe-ui.js +0 -1
- package/dist/cli/observe.d.ts +0 -1
- package/dist/cli/observe.js +0 -1
- package/dist/cli/studio-ui.generated.d.ts +0 -1
- package/dist/cli/studio-ui.generated.js +0 -1
- package/dist/cli/studio.d.ts +0 -1
- package/dist/cli/studio.js +0 -1
- package/dist/cli/ui.d.ts +0 -1
- package/dist/cli/ui.js +0 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.js +0 -1
- package/dist/dialect.d.ts +0 -1
- package/dist/dialect.js +0 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -1
- package/dist/generate.d.ts +0 -1
- package/dist/generate.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/introspect.d.ts +0 -1
- package/dist/introspect.js +0 -1
- package/dist/mssql.d.ts +0 -1
- package/dist/mssql.js +0 -1
- package/dist/mysql.d.ts +0 -1
- package/dist/mysql.js +0 -1
- package/dist/nested-write.d.ts +0 -1
- package/dist/nested-write.js +0 -1
- package/dist/observe.d.ts +0 -1
- package/dist/observe.js +0 -1
- package/dist/pipeline-submittable.d.ts +0 -1
- package/dist/pipeline-submittable.js +0 -1
- package/dist/pipeline.d.ts +0 -1
- package/dist/pipeline.js +0 -1
- package/dist/powdb.d.ts +0 -1
- package/dist/powdb.js +0 -1
- package/dist/powql.d.ts +0 -1
- package/dist/powql.js +0 -1
- package/dist/query/builder.d.ts +0 -1
- package/dist/query/builder.js +0 -1
- package/dist/query/index.d.ts +0 -1
- package/dist/query/index.js +0 -1
- package/dist/query/types.d.ts +0 -1
- package/dist/query/types.js +0 -1
- package/dist/query/utils.d.ts +0 -1
- package/dist/query/utils.js +0 -1
- package/dist/realtime.d.ts +0 -1
- package/dist/realtime.js +0 -1
- package/dist/schema-builder.d.ts +6 -4
- package/dist/schema-builder.js +29 -2
- package/dist/schema-sql.d.ts +0 -1
- package/dist/schema-sql.js +19 -6
- package/dist/schema.d.ts +0 -1
- package/dist/schema.js +0 -1
- package/dist/serverless.d.ts +0 -1
- package/dist/serverless.js +0 -1
- package/dist/sqlite.d.ts +0 -1
- package/dist/sqlite.js +0 -1
- package/dist/typed-sql.d.ts +0 -1
- package/dist/typed-sql.js +0 -1
- package/package.json +4 -4
package/dist/schema-builder.d.ts
CHANGED
|
@@ -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
|
package/dist/schema-builder.js
CHANGED
|
@@ -24,16 +24,28 @@
|
|
|
24
24
|
*/
|
|
25
25
|
/** Maps shorthand names to actual Postgres type strings */
|
|
26
26
|
const TYPE_MAP = {
|
|
27
|
-
serial
|
|
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
|
package/dist/schema-sql.d.ts
CHANGED
|
@@ -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
|
package/dist/schema-sql.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
package/dist/serverless.d.ts
CHANGED
|
@@ -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
|
package/dist/serverless.js
CHANGED
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
package/dist/typed-sql.d.ts
CHANGED
package/dist/typed-sql.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turbine-orm",
|
|
3
|
-
"version": "0.
|
|
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": "^
|
|
105
|
+
"@types/node": "^26.1.0",
|
|
106
106
|
"c8": "^11.0.0",
|
|
107
107
|
"husky": "^9.1.7",
|
|
108
|
-
"lint-staged": "^
|
|
108
|
+
"lint-staged": "^17.0.8",
|
|
109
109
|
"@zvndev/powdb-client": "^0.8.0",
|
|
110
110
|
"@zvndev/powdb-embedded": "^0.8.0",
|
|
111
|
-
"mssql": "^
|
|
111
|
+
"mssql": "^12.7.0",
|
|
112
112
|
"mysql2": "^3.22.5",
|
|
113
113
|
"size-limit": "^12.1.0",
|
|
114
114
|
"tsx": "^4.19.0",
|