turbine-orm 0.9.2 → 0.11.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 (45) hide show
  1. package/README.md +34 -16
  2. package/dist/adapters/cockroachdb.d.ts +40 -0
  3. package/dist/adapters/cockroachdb.js +172 -0
  4. package/dist/adapters/index.d.ts +107 -0
  5. package/dist/adapters/index.js +83 -0
  6. package/dist/adapters/yugabytedb.d.ts +52 -0
  7. package/dist/adapters/yugabytedb.js +156 -0
  8. package/dist/cjs/adapters/cockroachdb.js +174 -0
  9. package/dist/cjs/adapters/index.js +87 -0
  10. package/dist/cjs/adapters/yugabytedb.js +158 -0
  11. package/dist/cjs/cli/index.js +2 -1
  12. package/dist/cjs/cli/migrate.js +18 -12
  13. package/dist/cjs/cli/studio.js +5 -4
  14. package/dist/cjs/client.js +1 -0
  15. package/dist/cjs/dialect.js +57 -0
  16. package/dist/cjs/generate.js +8 -1
  17. package/dist/cjs/index.js +12 -3
  18. package/dist/cjs/introspect.js +46 -18
  19. package/dist/cjs/query/builder.js +129 -96
  20. package/dist/cjs/query/index.js +4 -1
  21. package/dist/cjs/query/utils.js +18 -0
  22. package/dist/cjs/schema.js +8 -0
  23. package/dist/cli/config.d.ts +11 -0
  24. package/dist/cli/index.js +2 -1
  25. package/dist/cli/migrate.d.ts +3 -0
  26. package/dist/cli/migrate.js +16 -10
  27. package/dist/cli/studio.d.ts +4 -0
  28. package/dist/cli/studio.js +5 -4
  29. package/dist/client.d.ts +3 -0
  30. package/dist/client.js +1 -0
  31. package/dist/dialect.d.ts +61 -0
  32. package/dist/dialect.js +55 -0
  33. package/dist/generate.js +8 -1
  34. package/dist/index.d.ts +5 -1
  35. package/dist/index.js +3 -1
  36. package/dist/introspect.js +46 -18
  37. package/dist/query/builder.d.ts +9 -1
  38. package/dist/query/builder.js +130 -97
  39. package/dist/query/index.d.ts +3 -1
  40. package/dist/query/index.js +2 -1
  41. package/dist/query/utils.d.ts +8 -0
  42. package/dist/query/utils.js +17 -0
  43. package/dist/schema.d.ts +6 -4
  44. package/dist/schema.js +7 -0
  45. package/package.json +8 -3
@@ -6,8 +6,10 @@
6
6
  * former monolithic `import { … } from './query.js'`.
7
7
  */
8
8
  export type { AggregateArgs, AggregateResult, ArrayFilter, CountArgs, CreateArgs, CreateManyArgs, DeleteArgs, DeleteManyArgs, FindManyArgs, FindManyStreamArgs, FindUniqueArgs, GroupByArgs, JsonFilter, OrderDirection, RelationDescriptor, RelationFilter, TypedWithClause, UpdateArgs, UpdateInput, UpdateManyArgs, UpdateOperatorInput, UpsertArgs, WhereClause, WhereOperator, WhereValue, WithClause, WithOptions, WithResult, } from './types.js';
9
+ export type { Dialect } from '../dialect.js';
10
+ export { postgresDialect } from '../dialect.js';
9
11
  export type { SqlCacheEntry } from './utils.js';
10
- export { escapeLike, escSingleQuote, fnv1a64Hex, LRUCache, OPERATOR_KEYS, quoteIdent, sqlToPreparedName, } from './utils.js';
12
+ export { buildCorrelation, escapeLike, escSingleQuote, fnv1a64Hex, LRUCache, OPERATOR_KEYS, quoteIdent, sqlToPreparedName, } from './utils.js';
11
13
  export type { DeferredQuery, MiddlewareFn, QueryInterfaceOptions } from './builder.js';
12
14
  export { QueryInterface } from './builder.js';
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -5,6 +5,7 @@
5
5
  * `import { … } from './query/index.js'` is a drop-in replacement for the
6
6
  * former monolithic `import { … } from './query.js'`.
7
7
  */
8
- export { escapeLike, escSingleQuote, fnv1a64Hex, LRUCache, OPERATOR_KEYS, quoteIdent, sqlToPreparedName, } from './utils.js';
8
+ export { postgresDialect } from '../dialect.js';
9
+ export { buildCorrelation, escapeLike, escSingleQuote, fnv1a64Hex, LRUCache, OPERATOR_KEYS, quoteIdent, sqlToPreparedName, } from './utils.js';
9
10
  export { QueryInterface } from './builder.js';
10
11
  //# sourceMappingURL=index.js.map
@@ -57,4 +57,12 @@ export declare function fnv1a64Hex(s: string): string;
57
57
  export declare function sqlToPreparedName(sql: string): string;
58
58
  /** Known operator keys — used to detect operator objects vs plain values */
59
59
  export declare const OPERATOR_KEYS: Set<string>;
60
+ /**
61
+ * Build a correlation clause joining columns between two table references.
62
+ * Handles both single-column (string) and multi-column (string[]) foreign keys.
63
+ *
64
+ * For single-column: `"alias"."col" = "parent"."col"`
65
+ * For multi-column: `"alias"."col_a" = "parent"."ref_a" AND "alias"."col_b" = "parent"."ref_b"`
66
+ */
67
+ export declare function buildCorrelation(leftRef: string, leftColumns: string | string[], rightRef: string, rightColumns: string | string[]): string;
60
68
  //# sourceMappingURL=utils.d.ts.map
@@ -111,4 +111,21 @@ export const OPERATOR_KEYS = new Set([
111
111
  'endsWith',
112
112
  'mode',
113
113
  ]);
114
+ // ---------------------------------------------------------------------------
115
+ // Composite key correlation helper
116
+ // ---------------------------------------------------------------------------
117
+ /**
118
+ * Build a correlation clause joining columns between two table references.
119
+ * Handles both single-column (string) and multi-column (string[]) foreign keys.
120
+ *
121
+ * For single-column: `"alias"."col" = "parent"."col"`
122
+ * For multi-column: `"alias"."col_a" = "parent"."ref_a" AND "alias"."col_b" = "parent"."ref_b"`
123
+ */
124
+ export function buildCorrelation(leftRef, leftColumns, rightRef, rightColumns) {
125
+ const leftCols = Array.isArray(leftColumns) ? leftColumns : [leftColumns];
126
+ const rightCols = Array.isArray(rightColumns) ? rightColumns : [rightColumns];
127
+ return leftCols
128
+ .map((col, i) => `${leftRef}.${quoteIdent(col)} = ${rightRef}.${quoteIdent(rightCols[i])}`)
129
+ .join(' AND ');
130
+ }
114
131
  //# sourceMappingURL=utils.js.map
package/dist/schema.d.ts CHANGED
@@ -62,11 +62,13 @@ export interface RelationDef {
62
62
  from: string;
63
63
  /** Target table */
64
64
  to: string;
65
- /** FK column on the "many" / "child" side (snake_case) */
66
- foreignKey: string;
67
- /** Referenced column on the "one" / "parent" side (snake_case) */
68
- referenceKey: string;
65
+ /** FK column(s) on the "many" / "child" side (snake_case). Array for composite FKs. */
66
+ foreignKey: string | string[];
67
+ /** Referenced column(s) on the "one" / "parent" side (snake_case). Array for composite FKs. */
68
+ referenceKey: string | string[];
69
69
  }
70
+ /** Normalize foreignKey/referenceKey to always be an array for uniform processing */
71
+ export declare function normalizeKeyColumns(key: string | string[]): string[];
70
72
  export interface IndexMetadata {
71
73
  name: string;
72
74
  columns: string[];
package/dist/schema.js CHANGED
@@ -5,6 +5,13 @@
5
5
  * They're used by the query builder, code generator, and CLI.
6
6
  */
7
7
  // ---------------------------------------------------------------------------
8
+ // Helpers for composite key handling
9
+ // ---------------------------------------------------------------------------
10
+ /** Normalize foreignKey/referenceKey to always be an array for uniform processing */
11
+ export function normalizeKeyColumns(key) {
12
+ return Array.isArray(key) ? key : [key];
13
+ }
14
+ // ---------------------------------------------------------------------------
8
15
  // Type mapping: Postgres → TypeScript
9
16
  // ---------------------------------------------------------------------------
10
17
  const PG_TO_TS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turbine-orm",
3
- "version": "0.9.2",
3
+ "version": "0.11.0",
4
4
  "description": "Postgres-native TypeScript ORM — runs on Neon, Vercel Postgres, Cloudflare, Supabase. Streaming cursors, typed errors, single-query nested relations. 1 dependency, ~110KB",
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,6 +18,11 @@
18
18
  "import": "./dist/cli/config.js",
19
19
  "require": "./dist/cjs/cli/config.js",
20
20
  "types": "./dist/cli/config.d.ts"
21
+ },
22
+ "./adapters": {
23
+ "import": "./dist/adapters/index.js",
24
+ "require": "./dist/cjs/adapters/index.js",
25
+ "types": "./dist/adapters/index.d.ts"
21
26
  }
22
27
  },
23
28
  "main": "./dist/cjs/index.js",
@@ -44,8 +49,8 @@
44
49
  "status": "tsx src/cli/index.ts status",
45
50
  "examples": "tsx examples/examples.ts",
46
51
  "test": "tsx --test src/test/*.test.ts",
47
- "test:unit": "tsx --test src/test/schema-builder.test.ts src/test/errors.test.ts src/test/stress.test.ts src/test/migrate.test.ts src/test/update-operators.test.ts src/test/empty-where-guard.test.ts src/test/cli.test.ts src/test/serverless.test.ts src/test/pipeline.test.ts src/test/pipeline-submittable.test.ts src/test/with-inference.test.ts src/test/operator-validation.test.ts src/test/unlimited-warning.test.ts src/test/generate-relations.test.ts src/test/stream-and-parse.test.ts src/test/sql-cache.test.ts src/test/studio.test.ts src/test/sql-injection.test.ts src/test/cli-flags.test.ts",
48
- "test:coverage": "c8 tsx --test src/test/schema-builder.test.ts src/test/errors.test.ts src/test/stress.test.ts src/test/migrate.test.ts src/test/update-operators.test.ts src/test/empty-where-guard.test.ts src/test/cli.test.ts src/test/serverless.test.ts src/test/pipeline.test.ts src/test/pipeline-submittable.test.ts src/test/with-inference.test.ts src/test/operator-validation.test.ts src/test/unlimited-warning.test.ts src/test/generate-relations.test.ts src/test/stream-and-parse.test.ts src/test/sql-cache.test.ts src/test/studio.test.ts src/test/sql-injection.test.ts src/test/cli-flags.test.ts",
52
+ "test:unit": "tsx --test src/test/schema-builder.test.ts src/test/errors.test.ts src/test/stress.test.ts src/test/migrate.test.ts src/test/update-operators.test.ts src/test/empty-where-guard.test.ts src/test/cli.test.ts src/test/serverless.test.ts src/test/pipeline.test.ts src/test/pipeline-submittable.test.ts src/test/with-inference.test.ts src/test/operator-validation.test.ts src/test/unlimited-warning.test.ts src/test/generate-relations.test.ts src/test/stream-and-parse.test.ts src/test/sql-cache.test.ts src/test/dialect.test.ts src/test/studio.test.ts src/test/sql-injection.test.ts src/test/cli-flags.test.ts src/test/cockroachdb-adapter.test.ts src/test/yugabytedb-adapter.test.ts src/test/pg-compat.test.ts src/test/relation-filter-validation.test.ts src/test/client-coverage.test.ts src/test/schema-diff.test.ts src/test/composite-fk.test.ts",
53
+ "test:coverage": "c8 tsx --test src/test/schema-builder.test.ts src/test/errors.test.ts src/test/stress.test.ts src/test/migrate.test.ts src/test/update-operators.test.ts src/test/empty-where-guard.test.ts src/test/cli.test.ts src/test/serverless.test.ts src/test/pipeline.test.ts src/test/pipeline-submittable.test.ts src/test/with-inference.test.ts src/test/operator-validation.test.ts src/test/unlimited-warning.test.ts src/test/generate-relations.test.ts src/test/stream-and-parse.test.ts src/test/sql-cache.test.ts src/test/dialect.test.ts src/test/studio.test.ts src/test/sql-injection.test.ts src/test/cli-flags.test.ts",
49
54
  "lint": "biome check src/",
50
55
  "lint:fix": "biome check --write src/",
51
56
  "format": "biome format --write src/",