turbine-orm 0.5.0 → 0.7.1

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 (50) hide show
  1. package/README.md +292 -26
  2. package/dist/cjs/cli/config.js +5 -15
  3. package/dist/cjs/cli/index.js +311 -43
  4. package/dist/cjs/cli/loader.js +129 -0
  5. package/dist/cjs/cli/migrate.js +96 -47
  6. package/dist/cjs/cli/ui.js +5 -9
  7. package/dist/cjs/client.js +158 -49
  8. package/dist/cjs/errors.js +424 -0
  9. package/dist/cjs/generate.js +145 -14
  10. package/dist/cjs/index.js +43 -20
  11. package/dist/cjs/introspect.js +3 -5
  12. package/dist/cjs/pipeline.js +9 -2
  13. package/dist/cjs/query.js +544 -115
  14. package/dist/cjs/schema-builder.js +150 -30
  15. package/dist/cjs/schema-sql.js +241 -37
  16. package/dist/cjs/schema.js +5 -2
  17. package/dist/cjs/serverless.js +88 -176
  18. package/dist/cli/config.js +6 -16
  19. package/dist/cli/index.js +316 -48
  20. package/dist/cli/loader.d.ts +45 -0
  21. package/dist/cli/loader.js +91 -0
  22. package/dist/cli/migrate.d.ts +13 -2
  23. package/dist/cli/migrate.js +97 -48
  24. package/dist/cli/ui.d.ts +1 -1
  25. package/dist/cli/ui.js +5 -9
  26. package/dist/client.d.ts +92 -4
  27. package/dist/client.js +158 -49
  28. package/dist/errors.d.ts +225 -0
  29. package/dist/errors.js +405 -0
  30. package/dist/generate.d.ts +7 -1
  31. package/dist/generate.js +148 -18
  32. package/dist/index.d.ts +11 -9
  33. package/dist/index.js +16 -12
  34. package/dist/introspect.d.ts +1 -1
  35. package/dist/introspect.js +4 -6
  36. package/dist/pipeline.d.ts +1 -1
  37. package/dist/pipeline.js +9 -2
  38. package/dist/query.d.ts +374 -38
  39. package/dist/query.js +545 -116
  40. package/dist/schema-builder.d.ts +38 -5
  41. package/dist/schema-builder.js +150 -31
  42. package/dist/schema-sql.d.ts +7 -3
  43. package/dist/schema-sql.js +241 -37
  44. package/dist/schema.d.ts +1 -1
  45. package/dist/schema.js +5 -2
  46. package/dist/serverless.d.ts +92 -139
  47. package/dist/serverless.js +87 -173
  48. package/package.json +33 -16
  49. package/dist/types.d.ts +0 -93
  50. package/dist/types.js +0 -126
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @batadata/turbine
2
+ * turbine-orm
3
3
  *
4
4
  * Turbine TypeScript SDK — type-safe Postgres queries with nested relations
5
5
  * and pipeline batching. Feels like Prisma, runs at raw-SQL speed.
@@ -32,13 +32,15 @@
32
32
  * await db.disconnect();
33
33
  * ```
34
34
  */
35
- export { TurbineClient, TransactionClient, type TurbineConfig, type TransactionOptions, type Middleware, type MiddlewareParams, type MiddlewareNext, } from './client.js';
36
- export { QueryInterface, type DeferredQuery, type FindUniqueArgs, type FindManyArgs, type CreateArgs, type CreateManyArgs, type UpdateArgs, type UpdateManyArgs, type DeleteArgs, type DeleteManyArgs, type UpsertArgs, type CountArgs, type GroupByArgs, type AggregateArgs, type AggregateResult, type RelationFilter, type JsonFilter, type ArrayFilter, type WithClause, type WithOptions, type OrderDirection, } from './query.js';
35
+ export { type Middleware, type MiddlewareNext, type MiddlewareParams, type PgCompatPool, type PgCompatPoolClient, type PgCompatQueryResult, TransactionClient, type TransactionOptions, TurbineClient, type TurbineConfig, } from './client.js';
36
+ export { CheckConstraintError, CircularRelationError, ConnectionError, DeadlockError, type ErrorMessageMode, ForeignKeyError, getErrorMessageMode, MigrationError, NotFoundError, NotNullViolationError, RelationError, SerializationFailureError, setErrorMessageMode, TimeoutError, TurbineError, TurbineErrorCode, UniqueConstraintError, ValidationError, wrapPgError, } from './errors.js';
37
+ export { type GenerateOptions, generate } from './generate.js';
38
+ export { type IntrospectOptions, introspect } from './introspect.js';
37
39
  export { executePipeline, type PipelineResults } from './pipeline.js';
38
- export type { SchemaMetadata, TableMetadata, ColumnMetadata, RelationDef, IndexMetadata, } from './schema.js';
39
- export { snakeToCamel, camelToSnake, snakeToPascal, singularize, pgTypeToTs, isDateType, pgArrayType, } from './schema.js';
40
- export { introspect, type IntrospectOptions } from './introspect.js';
41
- export { generate, type GenerateOptions } from './generate.js';
42
- export { defineSchema, table, column, ColumnBuilder, type ColumnDef, type ColumnTypeName, type ColumnConfig, type ColumnType, type TableDef, type SchemaDef, } from './schema-builder.js';
43
- export { schemaToSQL, schemaToSQLString, schemaDiff, schemaPush, type DiffResult, type AlterDef, type AlterColumnDef, type PushResult, } from './schema-sql.js';
40
+ export { type AggregateArgs, type AggregateResult, type ArrayFilter, type CountArgs, type CreateArgs, type CreateManyArgs, type DeferredQuery, type DeleteArgs, type DeleteManyArgs, type FindManyArgs, type FindManyStreamArgs, type FindUniqueArgs, type GroupByArgs, type JsonFilter, type OrderDirection, QueryInterface, type RelationDescriptor, type RelationFilter, type TypedWithClause, type UpdateArgs, type UpdateInput, type UpdateManyArgs, type UpdateOperatorInput, type UpsertArgs, type WithClause, type WithOptions, type WithResult, } from './query.js';
41
+ export type { ColumnMetadata, IndexMetadata, RelationDef, SchemaMetadata, TableMetadata, } from './schema.js';
42
+ export { camelToSnake, isDateType, pgArrayType, pgTypeToTs, singularize, snakeToCamel, snakeToPascal, } from './schema.js';
43
+ export { ColumnBuilder, type ColumnConfig, type ColumnDef, type ColumnType, type ColumnTypeName, column, defineSchema, type SchemaDef, type TableDef, table, } from './schema-builder.js';
44
+ export { type AlterColumnDef, type AlterDef, type DiffResult, type PushResult, schemaDiff, schemaPush, schemaToSQL, schemaToSQLString, } from './schema-sql.js';
45
+ export { type TurbineHttpOptions, turbineHttp } from './serverless.js';
44
46
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @batadata/turbine
2
+ * turbine-orm
3
3
  *
4
4
  * Turbine TypeScript SDK — type-safe Postgres queries with nested relations
5
5
  * and pipeline batching. Feels like Prisma, runs at raw-SQL speed.
@@ -33,21 +33,25 @@
33
33
  * ```
34
34
  */
35
35
  // Client
36
- export { TurbineClient, TransactionClient, } from './client.js';
37
- // Query builder
38
- export { QueryInterface, } from './query.js';
36
+ export { TransactionClient, TurbineClient, } from './client.js';
37
+ // Error types
38
+ export { CheckConstraintError, CircularRelationError, ConnectionError, DeadlockError, ForeignKeyError, getErrorMessageMode, MigrationError, NotFoundError, NotNullViolationError, RelationError, SerializationFailureError, setErrorMessageMode, TimeoutError, TurbineError, TurbineErrorCode, UniqueConstraintError, ValidationError, wrapPgError, } from './errors.js';
39
+ // Code generation
40
+ export { generate } from './generate.js';
41
+ // Introspection
42
+ export { introspect } from './introspect.js';
39
43
  // Pipeline
40
44
  export { executePipeline } from './pipeline.js';
45
+ // Query builder
46
+ export { QueryInterface, } from './query.js';
41
47
  // Schema utilities
42
- export { snakeToCamel, camelToSnake, snakeToPascal, singularize, pgTypeToTs, isDateType, pgArrayType, } from './schema.js';
43
- // Introspection
44
- export { introspect } from './introspect.js';
45
- // Code generation
46
- export { generate } from './generate.js';
48
+ export { camelToSnake, isDateType, pgArrayType, pgTypeToTs, singularize, snakeToCamel, snakeToPascal, } from './schema.js';
47
49
  // Schema builder — define schemas in TypeScript
48
- export { defineSchema,
50
+ export { ColumnBuilder, column, defineSchema,
49
51
  // Legacy compat (deprecated — use object format with defineSchema)
50
- table, column, ColumnBuilder, } from './schema-builder.js';
52
+ table, } from './schema-builder.js';
51
53
  // Schema SQL — generate DDL, diff, and push
52
- export { schemaToSQL, schemaToSQLString, schemaDiff, schemaPush, } from './schema-sql.js';
54
+ export { schemaDiff, schemaPush, schemaToSQL, schemaToSQLString, } from './schema-sql.js';
55
+ // Serverless / edge factory
56
+ export { turbineHttp } from './serverless.js';
53
57
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @batadata/turbine — Schema introspection
2
+ * turbine-orm — Schema introspection
3
3
  *
4
4
  * Connects to a live Postgres database, reads information_schema + pg_catalog,
5
5
  * and produces a SchemaMetadata object describing every table, column, relation,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @batadata/turbine — Schema introspection
2
+ * turbine-orm — Schema introspection
3
3
  *
4
4
  * Connects to a live Postgres database, reads information_schema + pg_catalog,
5
5
  * and produces a SchemaMetadata object describing every table, column, relation,
@@ -8,7 +8,7 @@
8
8
  * This is the foundation of `npx turbine generate`.
9
9
  */
10
10
  import pg from 'pg';
11
- import { pgTypeToTs, isDateType, pgArrayType, snakeToCamel, singularize, } from './schema.js';
11
+ import { isDateType, pgArrayType, pgTypeToTs, singularize, snakeToCamel, } from './schema.js';
12
12
  // ---------------------------------------------------------------------------
13
13
  // SQL queries (all parameterized, no interpolation)
14
14
  // ---------------------------------------------------------------------------
@@ -99,7 +99,7 @@ export async function introspect(options) {
99
99
  });
100
100
  try {
101
101
  // Run all information_schema queries in parallel
102
- const [tablesResult, columnsResult, pkResult, fkResult, uniqueResult, indexResult, enumResult,] = await Promise.all([
102
+ const [tablesResult, columnsResult, pkResult, fkResult, uniqueResult, indexResult, enumResult] = await Promise.all([
103
103
  pool.query(SQL_TABLES, [schema]),
104
104
  pool.query(SQL_COLUMNS, [schema]),
105
105
  pool.query(SQL_PRIMARY_KEYS, [schema]),
@@ -172,9 +172,7 @@ export async function introspect(options) {
172
172
  const isUnique = row.indexdef.includes('UNIQUE');
173
173
  // Extract column names from indexdef (e.g. "CREATE INDEX idx ON tbl USING btree (col1, col2)")
174
174
  const colMatch = row.indexdef.match(/\((.+)\)/);
175
- const columns = colMatch
176
- ? colMatch[1].split(',').map((c) => c.trim().replace(/ (ASC|DESC)/i, ''))
177
- : [];
175
+ const columns = colMatch ? colMatch[1].split(',').map((c) => c.trim().replace(/ (ASC|DESC)/i, '')) : [];
178
176
  indexesByTable.get(row.tablename).push({
179
177
  name: row.indexname,
180
178
  columns,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @batadata/turbine — Pipeline execution
2
+ * turbine-orm — Pipeline execution
3
3
  *
4
4
  * Pipelines batch multiple independent queries into a single database round-trip.
5
5
  * Instead of N sequential awaits (N round-trips), you get 1 round-trip for all N queries.
package/dist/pipeline.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @batadata/turbine — Pipeline execution
2
+ * turbine-orm — Pipeline execution
3
3
  *
4
4
  * Pipelines batch multiple independent queries into a single database round-trip.
5
5
  * Instead of N sequential awaits (N round-trips), you get 1 round-trip for all N queries.
@@ -15,6 +15,7 @@
15
15
  * we simulate it by running queries concurrently on a single connection or via
16
16
  * a multi-statement batch.
17
17
  */
18
+ import { wrapPgError } from './errors.js';
18
19
  // ---------------------------------------------------------------------------
19
20
  // Pipeline executor
20
21
  // ---------------------------------------------------------------------------
@@ -52,7 +53,13 @@ export async function executePipeline(pool, queries) {
52
53
  // Future: use actual Postgres pipeline protocol for true pipelining.
53
54
  const results = [];
54
55
  for (const q of queries) {
55
- const raw = await client.query(q.sql, q.params);
56
+ let raw;
57
+ try {
58
+ raw = await client.query(q.sql, q.params);
59
+ }
60
+ catch (err) {
61
+ throw wrapPgError(err);
62
+ }
56
63
  results.push(q.transform(raw));
57
64
  }
58
65
  await client.query('COMMIT');