turbine-orm 0.19.2 → 0.22.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 (53) hide show
  1. package/README.md +99 -18
  2. package/dist/adapters/cockroachdb.js +4 -9
  3. package/dist/cjs/adapters/cockroachdb.js +4 -9
  4. package/dist/cjs/cli/index.js +6 -3
  5. package/dist/cjs/cli/observe-ui.js +12 -2
  6. package/dist/cjs/cli/observe.js +6 -7
  7. package/dist/cjs/cli/studio.js +6 -7
  8. package/dist/cjs/client.js +44 -22
  9. package/dist/cjs/dialect.js +116 -0
  10. package/dist/cjs/errors.js +19 -1
  11. package/dist/cjs/generate.js +4 -0
  12. package/dist/cjs/index.js +3 -2
  13. package/dist/cjs/introspect.js +20 -0
  14. package/dist/cjs/mssql.js +1338 -0
  15. package/dist/cjs/mysql.js +1052 -0
  16. package/dist/cjs/powdb.js +851 -0
  17. package/dist/cjs/powql.js +903 -0
  18. package/dist/cjs/query/builder.js +293 -73
  19. package/dist/cjs/sqlite.js +849 -0
  20. package/dist/cjs/typed-sql.js +9 -7
  21. package/dist/cli/index.js +6 -3
  22. package/dist/cli/observe-ui.d.ts +1 -1
  23. package/dist/cli/observe-ui.js +12 -2
  24. package/dist/cli/observe.js +7 -8
  25. package/dist/cli/studio.js +7 -8
  26. package/dist/cli/ui.d.ts +1 -1
  27. package/dist/client.d.ts +23 -1
  28. package/dist/client.js +45 -23
  29. package/dist/dialect.d.ts +258 -1
  30. package/dist/dialect.js +83 -0
  31. package/dist/errors.d.ts +12 -0
  32. package/dist/errors.js +17 -0
  33. package/dist/generate.js +4 -0
  34. package/dist/index.d.ts +3 -3
  35. package/dist/index.js +1 -1
  36. package/dist/introspect.d.ts +18 -0
  37. package/dist/introspect.js +19 -0
  38. package/dist/mssql.d.ts +233 -0
  39. package/dist/mssql.js +1298 -0
  40. package/dist/mysql.d.ts +174 -0
  41. package/dist/mysql.js +1012 -0
  42. package/dist/powdb.d.ts +338 -0
  43. package/dist/powdb.js +802 -0
  44. package/dist/powql.d.ts +153 -0
  45. package/dist/powql.js +900 -0
  46. package/dist/query/builder.d.ts +105 -0
  47. package/dist/query/builder.js +294 -74
  48. package/dist/query/index.d.ts +1 -1
  49. package/dist/sqlite.d.ts +144 -0
  50. package/dist/sqlite.js +842 -0
  51. package/dist/typed-sql.d.ts +7 -5
  52. package/dist/typed-sql.js +9 -7
  53. package/package.json +45 -1
@@ -0,0 +1,153 @@
1
+ /**
2
+ * PowqlInterface — Turbine's PowQL query generator (the PowDB analogue of
3
+ * {@link QueryInterface}). It exposes the same public method surface as the SQL
4
+ * `QueryInterface` (`findMany`, `create`, `update`, …) but emits **PowQL** — a
5
+ * pipeline language, not SQL — executed through {@link PowdbPool}.
6
+ *
7
+ * It is a *parallel* implementation rather than a `Dialect` of the SQL builder:
8
+ * PowQL's grammar (`T filter <e> order <k> { .col }`) shares no surface with
9
+ * `SELECT … FROM … WHERE`, so the SQL `Dialect` seam cannot express it. Keeping
10
+ * it separate also means the four SQL engines are untouched.
11
+ *
12
+ * Behavioural deltas from the SQL path, all driven by PowDB's wire reality (see
13
+ * `docs/strategy/powdb-parity-matrix.md`, every row verified against a live
14
+ * server):
15
+ * - `create`/`createMany`/`update`/`delete` use PowDB 0.7.0's trailing
16
+ * `returning` keyword (`RETURNING *`, all columns) to surface affected rows
17
+ * in one round-trip. `upsert` is the lone exception — its statement does not
18
+ * accept `returning`, so it reselects the row by PK.
19
+ * - The PK is generated client-side (UUID) when the column has a default.
20
+ * - `with` (nested relations) degrades to **batched N+1 loaders** — D
21
+ * round-trips for depth D, not one query. manyToMany is Phase B.
22
+ * - pgvector / JSON / array filters and cursor streaming throw
23
+ * {@link UnsupportedFeatureError} (E017) — they have no PowDB equivalent.
24
+ *
25
+ * @module
26
+ */
27
+ import { type PowdbPool } from './powdb.js';
28
+ import type { MiddlewareFn, QueryInterfaceOptions } from './query/index.js';
29
+ import type { AggregateArgs, AggregateResult, CountArgs, CreateArgs, CreateManyArgs, DeleteArgs, DeleteManyArgs, FindManyArgs, FindUniqueArgs, GroupByArgs, UpdateArgs, UpdateManyArgs, UpsertArgs } from './query/types.js';
30
+ import { type SchemaMetadata } from './schema.js';
31
+ /**
32
+ * The PowQL query interface. Constructed by `turbinePowDB` via the
33
+ * `queryInterfaceFactory` seam and cast to `QueryInterface<object>` so
34
+ * `TurbineClient.table()` can return it transparently.
35
+ */
36
+ export declare class PowqlInterface<T extends object = Record<string, unknown>> {
37
+ private readonly pool;
38
+ private readonly table;
39
+ private readonly schema;
40
+ private readonly middlewares;
41
+ private readonly options;
42
+ private readonly meta;
43
+ private readonly defaultLimit?;
44
+ private readonly warnOnUnlimited;
45
+ private readonly onQuery?;
46
+ private currentAction;
47
+ private warnedUnlimited;
48
+ constructor(pool: PowdbPool, table: string, schema: SchemaMetadata, middlewares?: MiddlewareFn[], options?: QueryInterfaceOptions);
49
+ /** Resolve a camelCase field name (or raw snake) to its column metadata. */
50
+ private column;
51
+ /** PowQL column reference (`.snake_name`) for a field. */
52
+ private ref;
53
+ /**
54
+ * Push a value into the param array and return its `$N` placeholder. When the
55
+ * value targets a `float` column it is wrapped in {@link PowdbFloatParam} so
56
+ * the *embedded* literal encoder emits a float-form literal even for an
57
+ * integer value (PowQL's `42` is an int literal, `42.0` a float). The
58
+ * networked driver unwraps the marker back to the plain number in
59
+ * {@link toPowdbParam}, so the wire param is unchanged.
60
+ */
61
+ private param;
62
+ /**
63
+ * Render a value for a write *assignment* (`col := …`). Every value — float
64
+ * columns included — is sent as a positional `$N` param. PowDB ≥ 0.7.0 fixed
65
+ * the int→float UPDATE coercion bug (`score := $n` with an integer param now
66
+ * reads back the integer value, not the raw i64 bits), so the float-literal
67
+ * inlining workaround Turbine carried for ≤ 0.6.2 is gone. Marks the column as
68
+ * float-typed for the *embedded* literal encoder (which materializes params
69
+ * into PowQL text) so an integer-valued float still encodes as a float literal
70
+ * and coercion stays unambiguous. Non-finite floats are still rejected.
71
+ */
72
+ private writeRef;
73
+ private isFloatCol;
74
+ /** A predicate that is always false — the empty-`in` / contradiction sentinel. */
75
+ private alwaysFalse;
76
+ /**
77
+ * Compile a {@link WhereClause} into a PowQL filter expression, pushing every
78
+ * value as a positional `$N` param. Returns `''` when there are no conditions.
79
+ */
80
+ private buildWhere;
81
+ /** Build a single `field: value | operator` condition. */
82
+ private buildFieldCondition;
83
+ /** Bind a value, lowercasing for case-insensitive comparisons. */
84
+ private bind;
85
+ /** Bind a LIKE pattern (already escaped), lowercasing for insensitive mode. */
86
+ private bindLike;
87
+ /** `lhs [not] in ($1, $2, …)` — empty list collapses to a constant. */
88
+ private buildInList;
89
+ /**
90
+ * Relation filter (`some`/`none`/`every`) via the verified IN-subquery form
91
+ * `Outer filter .localKey in (Target filter <e> { .targetKey })`. `exists`
92
+ * correlation is unreliable on PowDB, so it is never used.
93
+ */
94
+ private buildRelationFilter;
95
+ /** Resolve the set of columns to project, honouring `select` / `omit`. */
96
+ private projectedColumns;
97
+ /** `{ .c1, .c2, … }` projection clause. */
98
+ private projection;
99
+ /** `order .c1 asc, .c2 desc` clause (empty string when no orderBy). */
100
+ private buildOrder;
101
+ /** Run PowQL with optional timeout, emitting a query event either way. */
102
+ private exec;
103
+ private emit;
104
+ /** Run a method body through the middleware chain (mirrors QueryInterface). */
105
+ private withMiddleware;
106
+ /** Map raw rows to typed entities. */
107
+ private shape;
108
+ findMany(args?: FindManyArgs<T>): Promise<T[]>;
109
+ /** Build + run the flat findMany select; returns raw rows. */
110
+ private runFind;
111
+ findUnique(args: FindUniqueArgs<T>): Promise<T | null>;
112
+ findFirst(args?: FindManyArgs<T>): Promise<T | null>;
113
+ findUniqueOrThrow(args: FindUniqueArgs<T>): Promise<T>;
114
+ findFirstOrThrow(args?: FindManyArgs<T>): Promise<T>;
115
+ /** Load each requested relation for `parents` and attach it onto each row. */
116
+ private loadRelations;
117
+ /** Split `data` into scalar assignments; reject relation (nested-write) keys. */
118
+ private scalarData;
119
+ /** Fill in a client-generated UUID for a defaulted PK that wasn't supplied. */
120
+ private applyPkDefault;
121
+ create(args: CreateArgs<T>): Promise<T>;
122
+ createMany(args: CreateManyArgs<T>): Promise<T[]>;
123
+ update(args: UpdateArgs<T>): Promise<T>;
124
+ updateMany(args: UpdateManyArgs<T>): Promise<{
125
+ count: number;
126
+ }>;
127
+ /** Compile `data` into PowQL update assignments, including atomic operators. */
128
+ private buildUpdateAssignments;
129
+ delete(args: DeleteArgs<T>): Promise<T>;
130
+ deleteMany(args: DeleteManyArgs<T>): Promise<{
131
+ count: number;
132
+ }>;
133
+ upsert(args: UpsertArgs<T>): Promise<T>;
134
+ count(args?: CountArgs<T>): Promise<number>;
135
+ aggregate(args: AggregateArgs<T>): Promise<AggregateResult<T>>;
136
+ groupBy(args: GroupByArgs<T>): Promise<Record<string, unknown>[]>;
137
+ /** `having <expr>` over group aggregates (count/sum/avg/min/max). */
138
+ private buildHaving;
139
+ findManyStream(): AsyncGenerator<T>;
140
+ /** Reselect a single row by its single-column primary key value. */
141
+ private reselectByPk;
142
+ /**
143
+ * Empty-where guard — blocks accidental whole-table writes. Mirrors the SQL
144
+ * path's `assertMutationHasPredicate` (query/builder.ts): it gates on the
145
+ * *compiled* PowQL filter fragment, NOT the shape of the `where` object. A
146
+ * `where` whose conditions all evaporate during compilation — `{}`,
147
+ * `{ id: undefined }`, `{ OR: [] }`, `{ AND: [] }`, `{ NOT: {} }`,
148
+ * `{ OR: [{ f: undefined }] }` — compiles to the empty string and is refused,
149
+ * because emitting a filter-less write would hit every row.
150
+ */
151
+ private assertCompiledWhere;
152
+ }
153
+ //# sourceMappingURL=powql.d.ts.map