turbine-orm 0.4.0 → 0.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/README.md +243 -26
- package/dist/cjs/cli/config.js +151 -0
- package/dist/cjs/cli/index.js +1176 -0
- package/dist/cjs/cli/migrate.js +446 -0
- package/dist/cjs/cli/ui.js +233 -0
- package/dist/cjs/client.js +512 -0
- package/dist/cjs/errors.js +293 -0
- package/dist/cjs/generate.js +321 -0
- package/dist/cjs/index.js +94 -0
- package/dist/cjs/introspect.js +287 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pipeline.js +78 -0
- package/dist/cjs/query.js +1891 -0
- package/dist/cjs/schema-builder.js +238 -0
- package/dist/cjs/schema-sql.js +509 -0
- package/dist/cjs/schema.js +140 -0
- package/dist/cjs/serverless.js +110 -0
- package/dist/cli/config.js +6 -16
- package/dist/cli/index.js +256 -49
- package/dist/cli/migrate.d.ts +35 -6
- package/dist/cli/migrate.js +124 -76
- package/dist/cli/ui.js +5 -9
- package/dist/client.d.ts +87 -3
- package/dist/client.js +122 -46
- package/dist/errors.d.ts +138 -0
- package/dist/errors.js +278 -0
- package/dist/generate.js +37 -11
- package/dist/index.d.ts +10 -8
- package/dist/index.js +15 -11
- package/dist/introspect.js +3 -5
- package/dist/pipeline.js +8 -1
- package/dist/query.d.ts +310 -45
- package/dist/query.js +565 -237
- package/dist/schema-builder.js +91 -23
- package/dist/schema-sql.d.ts +6 -2
- package/dist/schema-sql.js +180 -26
- package/dist/schema.js +4 -1
- package/dist/serverless.d.ts +91 -139
- package/dist/serverless.js +86 -173
- package/package.json +44 -21
- package/dist/cli/config.d.ts.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/migrate.d.ts.map +0 -1
- package/dist/cli/ui.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/generate.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/introspect.d.ts.map +0 -1
- package/dist/pipeline.d.ts.map +0 -1
- package/dist/query.d.ts.map +0 -1
- package/dist/schema-builder.d.ts.map +0 -1
- package/dist/schema-sql.d.ts.map +0 -1
- package/dist/schema.d.ts.map +0 -1
- package/dist/serverless.d.ts.map +0 -1
- package/dist/types.d.ts +0 -93
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -126
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* turbine-orm/serverless — edge / serverless driver integration
|
|
4
|
+
*
|
|
5
|
+
* Turbine runs on any Postgres driver that speaks the node-postgres API.
|
|
6
|
+
* This module exposes a thin factory (`turbineHttp`) that binds an external
|
|
7
|
+
* pg-compatible pool to a schema, so you can use Turbine on Vercel Edge,
|
|
8
|
+
* Cloudflare Workers, Deno Deploy, Netlify Edge, or any other environment
|
|
9
|
+
* where a direct TCP connection is unavailable.
|
|
10
|
+
*
|
|
11
|
+
* ## Supported drivers
|
|
12
|
+
*
|
|
13
|
+
* Any driver whose `Pool` satisfies `PgCompatPool` will work. The ones
|
|
14
|
+
* below are verified:
|
|
15
|
+
*
|
|
16
|
+
* - **Neon** (`@neondatabase/serverless`) — HTTP and WebSocket transports
|
|
17
|
+
* - **Vercel Postgres** (`@vercel/postgres`) — wraps Neon
|
|
18
|
+
* - **Cloudflare Hyperdrive** — exposes a pg-compatible driver
|
|
19
|
+
* - **Supabase** — use the regular `pg` package; Supabase is Postgres-native
|
|
20
|
+
*
|
|
21
|
+
* Turbine does NOT bundle any of these — install whichever you need and
|
|
22
|
+
* pass its pool directly.
|
|
23
|
+
*
|
|
24
|
+
* ## Limitations over HTTP
|
|
25
|
+
*
|
|
26
|
+
* - **Streaming cursors** (`findManyStream`, `findManyCursor`) require
|
|
27
|
+
* server-side `DECLARE CURSOR`, which most HTTP drivers do not support.
|
|
28
|
+
* If you call these on an HTTP pool the underlying driver will error.
|
|
29
|
+
* - **LISTEN/NOTIFY** is not available over HTTP.
|
|
30
|
+
* - **Transactions** are supported but each transaction holds an HTTP
|
|
31
|
+
* connection for its duration — keep them short.
|
|
32
|
+
*
|
|
33
|
+
* ## Example — Neon on Vercel Edge
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* // app/api/users/route.ts
|
|
37
|
+
* import { Pool } from '@neondatabase/serverless';
|
|
38
|
+
* import { turbineHttp } from 'turbine-orm/serverless';
|
|
39
|
+
* import { schema } from '@/generated/turbine/metadata';
|
|
40
|
+
*
|
|
41
|
+
* export const runtime = 'edge';
|
|
42
|
+
*
|
|
43
|
+
* const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
44
|
+
* const db = turbineHttp(pool, schema);
|
|
45
|
+
*
|
|
46
|
+
* export async function GET() {
|
|
47
|
+
* const users = await db.table('users').findMany({ limit: 10 });
|
|
48
|
+
* return Response.json(users);
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* ## Example — Supabase (direct Postgres, no HTTP proxy needed)
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { TurbineClient } from 'turbine-orm';
|
|
56
|
+
* import { schema } from './generated/turbine/metadata.js';
|
|
57
|
+
*
|
|
58
|
+
* const db = new TurbineClient({
|
|
59
|
+
* connectionString: process.env.SUPABASE_DB_URL,
|
|
60
|
+
* ssl: { rejectUnauthorized: false },
|
|
61
|
+
* }, schema);
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* ## Example — Cloudflare Workers
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* // Use the Neon HTTP driver which works in Workers runtime
|
|
68
|
+
* import { Pool } from '@neondatabase/serverless';
|
|
69
|
+
* import { turbineHttp } from 'turbine-orm/serverless';
|
|
70
|
+
*
|
|
71
|
+
* export default {
|
|
72
|
+
* async fetch(req: Request, env: Env) {
|
|
73
|
+
* const pool = new Pool({ connectionString: env.DATABASE_URL });
|
|
74
|
+
* const db = turbineHttp(pool, schema);
|
|
75
|
+
* const users = await db.table('users').findMany({ limit: 10 });
|
|
76
|
+
* return Response.json(users);
|
|
77
|
+
* }
|
|
78
|
+
* };
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
82
|
+
exports.turbineHttp = turbineHttp;
|
|
83
|
+
const client_js_1 = require("./client.js");
|
|
84
|
+
/**
|
|
85
|
+
* Create a TurbineClient bound to an external pg-compatible pool.
|
|
86
|
+
*
|
|
87
|
+
* Use this for serverless/edge environments where Turbine should NOT
|
|
88
|
+
* manage its own `pg.Pool`. The caller retains ownership of the pool's
|
|
89
|
+
* lifecycle — `db.disconnect()` is a no-op.
|
|
90
|
+
*
|
|
91
|
+
* @param pool - Any pg-compatible pool (Neon, Vercel Postgres, etc.)
|
|
92
|
+
* @param schema - Introspected or hand-written schema metadata
|
|
93
|
+
* @param options - Optional logging / defaultLimit / warnOnUnlimited
|
|
94
|
+
* @returns A TurbineClient instance
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { Pool } from '@neondatabase/serverless';
|
|
99
|
+
* import { turbineHttp } from 'turbine-orm/serverless';
|
|
100
|
+
* import { schema } from './generated/turbine/metadata.js';
|
|
101
|
+
*
|
|
102
|
+
* const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
103
|
+
* const db = turbineHttp(pool, schema);
|
|
104
|
+
*
|
|
105
|
+
* const users = await db.table('users').findMany({ limit: 10 });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function turbineHttp(pool, schema, options = {}) {
|
|
109
|
+
return new client_js_1.TurbineClient({ pool, ...options }, schema);
|
|
110
|
+
}
|
package/dist/cli/config.js
CHANGED
|
@@ -5,17 +5,12 @@
|
|
|
5
5
|
* Falls back to CLI args and environment variables.
|
|
6
6
|
*/
|
|
7
7
|
import { existsSync } from 'node:fs';
|
|
8
|
-
import {
|
|
8
|
+
import { join, resolve } from 'node:path';
|
|
9
9
|
import { pathToFileURL } from 'node:url';
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
11
|
// Config file names, in priority order
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
|
-
const CONFIG_FILES = [
|
|
14
|
-
'turbine.config.ts',
|
|
15
|
-
'turbine.config.mts',
|
|
16
|
-
'turbine.config.js',
|
|
17
|
-
'turbine.config.mjs',
|
|
18
|
-
];
|
|
13
|
+
const CONFIG_FILES = ['turbine.config.ts', 'turbine.config.mts', 'turbine.config.js', 'turbine.config.mjs'];
|
|
19
14
|
// ---------------------------------------------------------------------------
|
|
20
15
|
// Load config
|
|
21
16
|
// ---------------------------------------------------------------------------
|
|
@@ -67,10 +62,7 @@ export function findConfigFile(cwd) {
|
|
|
67
62
|
*/
|
|
68
63
|
export function resolveConfig(fileConfig, overrides) {
|
|
69
64
|
return {
|
|
70
|
-
url: overrides.url ??
|
|
71
|
-
process.env['DATABASE_URL'] ??
|
|
72
|
-
fileConfig.url ??
|
|
73
|
-
'',
|
|
65
|
+
url: overrides.url ?? process.env.DATABASE_URL ?? fileConfig.url ?? '',
|
|
74
66
|
out: overrides.out ?? fileConfig.out ?? './generated/turbine',
|
|
75
67
|
schema: overrides.schema ?? fileConfig.schema ?? 'public',
|
|
76
68
|
include: overrides.include ?? fileConfig.include ?? [],
|
|
@@ -84,15 +76,13 @@ export function resolveConfig(fileConfig, overrides) {
|
|
|
84
76
|
// Config file template (for `turbine init`)
|
|
85
77
|
// ---------------------------------------------------------------------------
|
|
86
78
|
export function configTemplate(connectionString) {
|
|
87
|
-
const
|
|
88
|
-
const urlLine = connectionString
|
|
89
|
-
? ` url: '${connectionString}',`
|
|
90
|
-
: ` url: process.env.DATABASE_URL,`;
|
|
79
|
+
const _url = connectionString ?? 'process.env.DATABASE_URL';
|
|
80
|
+
const urlLine = connectionString ? ` url: '${connectionString}',` : ` url: process.env.DATABASE_URL,`;
|
|
91
81
|
return `import type { TurbineCliConfig } from 'turbine-orm/cli';
|
|
92
82
|
|
|
93
83
|
/**
|
|
94
84
|
* Turbine configuration
|
|
95
|
-
* @see https://
|
|
85
|
+
* @see https://turbineorm.dev
|
|
96
86
|
*/
|
|
97
87
|
const config: TurbineCliConfig = {
|
|
98
88
|
/** Postgres connection string */
|