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/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * @batadata/turbine
3
+ * turbine-orm
4
4
  *
5
5
  * Turbine TypeScript SDK — type-safe Postgres queries with nested relations
6
6
  * and pipeline batching. Feels like Prisma, runs at raw-SQL speed.
@@ -34,42 +34,65 @@
34
34
  * ```
35
35
  */
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.schemaPush = exports.schemaDiff = exports.schemaToSQLString = exports.schemaToSQL = exports.ColumnBuilder = exports.column = exports.table = exports.defineSchema = exports.generate = exports.introspect = exports.pgArrayType = exports.isDateType = exports.pgTypeToTs = exports.singularize = exports.snakeToPascal = exports.camelToSnake = exports.snakeToCamel = exports.executePipeline = exports.QueryInterface = exports.TransactionClient = exports.TurbineClient = void 0;
37
+ exports.turbineHttp = exports.schemaToSQLString = exports.schemaToSQL = exports.schemaPush = exports.schemaDiff = exports.table = exports.defineSchema = exports.column = exports.ColumnBuilder = exports.snakeToPascal = exports.snakeToCamel = exports.singularize = exports.pgTypeToTs = exports.pgArrayType = exports.isDateType = exports.camelToSnake = exports.QueryInterface = exports.executePipeline = exports.introspect = exports.generate = exports.wrapPgError = exports.ValidationError = exports.UniqueConstraintError = exports.TurbineErrorCode = exports.TurbineError = exports.TimeoutError = exports.setErrorMessageMode = exports.SerializationFailureError = exports.RelationError = exports.NotNullViolationError = exports.NotFoundError = exports.MigrationError = exports.getErrorMessageMode = exports.ForeignKeyError = exports.DeadlockError = exports.ConnectionError = exports.CircularRelationError = exports.CheckConstraintError = exports.TurbineClient = exports.TransactionClient = void 0;
38
38
  // Client
39
39
  var client_js_1 = require("./client.js");
40
- Object.defineProperty(exports, "TurbineClient", { enumerable: true, get: function () { return client_js_1.TurbineClient; } });
41
40
  Object.defineProperty(exports, "TransactionClient", { enumerable: true, get: function () { return client_js_1.TransactionClient; } });
42
- // Query builder
43
- var query_js_1 = require("./query.js");
44
- Object.defineProperty(exports, "QueryInterface", { enumerable: true, get: function () { return query_js_1.QueryInterface; } });
41
+ Object.defineProperty(exports, "TurbineClient", { enumerable: true, get: function () { return client_js_1.TurbineClient; } });
42
+ // Error types
43
+ var errors_js_1 = require("./errors.js");
44
+ Object.defineProperty(exports, "CheckConstraintError", { enumerable: true, get: function () { return errors_js_1.CheckConstraintError; } });
45
+ Object.defineProperty(exports, "CircularRelationError", { enumerable: true, get: function () { return errors_js_1.CircularRelationError; } });
46
+ Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_js_1.ConnectionError; } });
47
+ Object.defineProperty(exports, "DeadlockError", { enumerable: true, get: function () { return errors_js_1.DeadlockError; } });
48
+ Object.defineProperty(exports, "ForeignKeyError", { enumerable: true, get: function () { return errors_js_1.ForeignKeyError; } });
49
+ Object.defineProperty(exports, "getErrorMessageMode", { enumerable: true, get: function () { return errors_js_1.getErrorMessageMode; } });
50
+ Object.defineProperty(exports, "MigrationError", { enumerable: true, get: function () { return errors_js_1.MigrationError; } });
51
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
52
+ Object.defineProperty(exports, "NotNullViolationError", { enumerable: true, get: function () { return errors_js_1.NotNullViolationError; } });
53
+ Object.defineProperty(exports, "RelationError", { enumerable: true, get: function () { return errors_js_1.RelationError; } });
54
+ Object.defineProperty(exports, "SerializationFailureError", { enumerable: true, get: function () { return errors_js_1.SerializationFailureError; } });
55
+ Object.defineProperty(exports, "setErrorMessageMode", { enumerable: true, get: function () { return errors_js_1.setErrorMessageMode; } });
56
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_js_1.TimeoutError; } });
57
+ Object.defineProperty(exports, "TurbineError", { enumerable: true, get: function () { return errors_js_1.TurbineError; } });
58
+ Object.defineProperty(exports, "TurbineErrorCode", { enumerable: true, get: function () { return errors_js_1.TurbineErrorCode; } });
59
+ Object.defineProperty(exports, "UniqueConstraintError", { enumerable: true, get: function () { return errors_js_1.UniqueConstraintError; } });
60
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_js_1.ValidationError; } });
61
+ Object.defineProperty(exports, "wrapPgError", { enumerable: true, get: function () { return errors_js_1.wrapPgError; } });
62
+ // Code generation
63
+ var generate_js_1 = require("./generate.js");
64
+ Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_js_1.generate; } });
65
+ // Introspection
66
+ var introspect_js_1 = require("./introspect.js");
67
+ Object.defineProperty(exports, "introspect", { enumerable: true, get: function () { return introspect_js_1.introspect; } });
45
68
  // Pipeline
46
69
  var pipeline_js_1 = require("./pipeline.js");
47
70
  Object.defineProperty(exports, "executePipeline", { enumerable: true, get: function () { return pipeline_js_1.executePipeline; } });
71
+ // Query builder
72
+ var query_js_1 = require("./query.js");
73
+ Object.defineProperty(exports, "QueryInterface", { enumerable: true, get: function () { return query_js_1.QueryInterface; } });
48
74
  // Schema utilities
49
75
  var schema_js_1 = require("./schema.js");
50
- Object.defineProperty(exports, "snakeToCamel", { enumerable: true, get: function () { return schema_js_1.snakeToCamel; } });
51
76
  Object.defineProperty(exports, "camelToSnake", { enumerable: true, get: function () { return schema_js_1.camelToSnake; } });
52
- Object.defineProperty(exports, "snakeToPascal", { enumerable: true, get: function () { return schema_js_1.snakeToPascal; } });
53
- Object.defineProperty(exports, "singularize", { enumerable: true, get: function () { return schema_js_1.singularize; } });
54
- Object.defineProperty(exports, "pgTypeToTs", { enumerable: true, get: function () { return schema_js_1.pgTypeToTs; } });
55
77
  Object.defineProperty(exports, "isDateType", { enumerable: true, get: function () { return schema_js_1.isDateType; } });
56
78
  Object.defineProperty(exports, "pgArrayType", { enumerable: true, get: function () { return schema_js_1.pgArrayType; } });
57
- // Introspection
58
- var introspect_js_1 = require("./introspect.js");
59
- Object.defineProperty(exports, "introspect", { enumerable: true, get: function () { return introspect_js_1.introspect; } });
60
- // Code generation
61
- var generate_js_1 = require("./generate.js");
62
- Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_js_1.generate; } });
79
+ Object.defineProperty(exports, "pgTypeToTs", { enumerable: true, get: function () { return schema_js_1.pgTypeToTs; } });
80
+ Object.defineProperty(exports, "singularize", { enumerable: true, get: function () { return schema_js_1.singularize; } });
81
+ Object.defineProperty(exports, "snakeToCamel", { enumerable: true, get: function () { return schema_js_1.snakeToCamel; } });
82
+ Object.defineProperty(exports, "snakeToPascal", { enumerable: true, get: function () { return schema_js_1.snakeToPascal; } });
63
83
  // Schema builder — define schemas in TypeScript
64
84
  var schema_builder_js_1 = require("./schema-builder.js");
85
+ Object.defineProperty(exports, "ColumnBuilder", { enumerable: true, get: function () { return schema_builder_js_1.ColumnBuilder; } });
86
+ Object.defineProperty(exports, "column", { enumerable: true, get: function () { return schema_builder_js_1.column; } });
65
87
  Object.defineProperty(exports, "defineSchema", { enumerable: true, get: function () { return schema_builder_js_1.defineSchema; } });
66
88
  // Legacy compat (deprecated — use object format with defineSchema)
67
89
  Object.defineProperty(exports, "table", { enumerable: true, get: function () { return schema_builder_js_1.table; } });
68
- Object.defineProperty(exports, "column", { enumerable: true, get: function () { return schema_builder_js_1.column; } });
69
- Object.defineProperty(exports, "ColumnBuilder", { enumerable: true, get: function () { return schema_builder_js_1.ColumnBuilder; } });
70
90
  // Schema SQL — generate DDL, diff, and push
71
91
  var schema_sql_js_1 = require("./schema-sql.js");
72
- Object.defineProperty(exports, "schemaToSQL", { enumerable: true, get: function () { return schema_sql_js_1.schemaToSQL; } });
73
- Object.defineProperty(exports, "schemaToSQLString", { enumerable: true, get: function () { return schema_sql_js_1.schemaToSQLString; } });
74
92
  Object.defineProperty(exports, "schemaDiff", { enumerable: true, get: function () { return schema_sql_js_1.schemaDiff; } });
75
93
  Object.defineProperty(exports, "schemaPush", { enumerable: true, get: function () { return schema_sql_js_1.schemaPush; } });
94
+ Object.defineProperty(exports, "schemaToSQL", { enumerable: true, get: function () { return schema_sql_js_1.schemaToSQL; } });
95
+ Object.defineProperty(exports, "schemaToSQLString", { enumerable: true, get: function () { return schema_sql_js_1.schemaToSQLString; } });
96
+ // Serverless / edge factory
97
+ var serverless_js_1 = require("./serverless.js");
98
+ Object.defineProperty(exports, "turbineHttp", { enumerable: true, get: function () { return serverless_js_1.turbineHttp; } });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * @batadata/turbine — Schema introspection
3
+ * turbine-orm — Schema introspection
4
4
  *
5
5
  * Connects to a live Postgres database, reads information_schema + pg_catalog,
6
6
  * and produces a SchemaMetadata object describing every table, column, relation,
@@ -105,7 +105,7 @@ async function introspect(options) {
105
105
  });
106
106
  try {
107
107
  // Run all information_schema queries in parallel
108
- const [tablesResult, columnsResult, pkResult, fkResult, uniqueResult, indexResult, enumResult,] = await Promise.all([
108
+ const [tablesResult, columnsResult, pkResult, fkResult, uniqueResult, indexResult, enumResult] = await Promise.all([
109
109
  pool.query(SQL_TABLES, [schema]),
110
110
  pool.query(SQL_COLUMNS, [schema]),
111
111
  pool.query(SQL_PRIMARY_KEYS, [schema]),
@@ -178,9 +178,7 @@ async function introspect(options) {
178
178
  const isUnique = row.indexdef.includes('UNIQUE');
179
179
  // Extract column names from indexdef (e.g. "CREATE INDEX idx ON tbl USING btree (col1, col2)")
180
180
  const colMatch = row.indexdef.match(/\((.+)\)/);
181
- const columns = colMatch
182
- ? colMatch[1].split(',').map((c) => c.trim().replace(/ (ASC|DESC)/i, ''))
183
- : [];
181
+ const columns = colMatch ? colMatch[1].split(',').map((c) => c.trim().replace(/ (ASC|DESC)/i, '')) : [];
184
182
  indexesByTable.get(row.tablename).push({
185
183
  name: row.indexname,
186
184
  columns,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * @batadata/turbine — Pipeline execution
3
+ * turbine-orm — Pipeline execution
4
4
  *
5
5
  * Pipelines batch multiple independent queries into a single database round-trip.
6
6
  * Instead of N sequential awaits (N round-trips), you get 1 round-trip for all N queries.
@@ -18,6 +18,7 @@
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.executePipeline = executePipeline;
21
+ const errors_js_1 = require("./errors.js");
21
22
  // ---------------------------------------------------------------------------
22
23
  // Pipeline executor
23
24
  // ---------------------------------------------------------------------------
@@ -55,7 +56,13 @@ async function executePipeline(pool, queries) {
55
56
  // Future: use actual Postgres pipeline protocol for true pipelining.
56
57
  const results = [];
57
58
  for (const q of queries) {
58
- const raw = await client.query(q.sql, q.params);
59
+ let raw;
60
+ try {
61
+ raw = await client.query(q.sql, q.params);
62
+ }
63
+ catch (err) {
64
+ throw (0, errors_js_1.wrapPgError)(err);
65
+ }
59
66
  results.push(q.transform(raw));
60
67
  }
61
68
  await client.query('COMMIT');