turbine-orm 0.34.0 → 0.36.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 +18 -16
- package/dist/cjs/cli/index.js +109 -16
- package/dist/cjs/cli/migrate.js +78 -3
- package/dist/cjs/cli/studio-ui.generated.js +1 -1
- package/dist/cjs/cli/studio.js +333 -22
- package/dist/cjs/cli/ui.js +7 -1
- package/dist/cjs/client.js +26 -4
- package/dist/cjs/dialect.js +2 -1
- package/dist/cjs/errors.js +41 -1
- package/dist/cjs/generate.js +23 -2
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/mssql.js +27 -5
- package/dist/cjs/mysql.js +4 -0
- package/dist/cjs/powdb.js +197 -25
- package/dist/cjs/powql.js +515 -51
- package/dist/cjs/query/aggregates.js +683 -0
- package/dist/cjs/query/batched-loader.js +2 -0
- package/dist/cjs/query/builder.js +361 -4508
- package/dist/cjs/query/filters.js +12 -0
- package/dist/cjs/query/relations.js +1698 -0
- package/dist/cjs/query/where-compile.js +180 -0
- package/dist/cjs/query/where.js +1491 -0
- package/dist/cjs/query/writes.js +680 -0
- package/dist/cjs/schema-builder.js +6 -0
- package/dist/cjs/schema-metadata.js +4 -0
- package/dist/cjs/schema-sql.js +265 -3
- package/dist/cjs/sqlite.js +4 -1
- package/dist/cli/index.d.ts +8 -2
- package/dist/cli/index.js +111 -18
- package/dist/cli/migrate.d.ts +24 -1
- package/dist/cli/migrate.js +77 -3
- package/dist/cli/studio-ui.generated.js +1 -1
- package/dist/cli/studio.d.ts +46 -13
- package/dist/cli/studio.js +331 -23
- package/dist/cli/ui.js +7 -1
- package/dist/client.d.ts +32 -5
- package/dist/client.js +26 -4
- package/dist/dialect.d.ts +28 -6
- package/dist/dialect.js +2 -1
- package/dist/errors.d.ts +36 -0
- package/dist/errors.js +39 -0
- package/dist/generate.js +23 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/mssql.js +27 -5
- package/dist/mysql.js +4 -0
- package/dist/powdb.d.ts +135 -9
- package/dist/powdb.js +197 -25
- package/dist/powql.d.ts +166 -4
- package/dist/powql.js +516 -52
- package/dist/query/aggregates.d.ts +74 -0
- package/dist/query/aggregates.js +641 -0
- package/dist/query/batched-loader.d.ts +6 -0
- package/dist/query/batched-loader.js +2 -0
- package/dist/query/builder.d.ts +98 -830
- package/dist/query/builder.js +366 -4513
- package/dist/query/deferred.d.ts +13 -2
- package/dist/query/filters.d.ts +7 -0
- package/dist/query/filters.js +11 -0
- package/dist/query/relations.d.ts +441 -0
- package/dist/query/relations.js +1627 -0
- package/dist/query/types.d.ts +25 -6
- package/dist/query/where-compile.d.ts +139 -0
- package/dist/query/where-compile.js +175 -0
- package/dist/query/where.d.ts +494 -0
- package/dist/query/where.js +1431 -0
- package/dist/query/writes.d.ts +131 -0
- package/dist/query/writes.js +626 -0
- package/dist/schema-builder.d.ts +18 -3
- package/dist/schema-builder.js +6 -0
- package/dist/schema-metadata.js +4 -0
- package/dist/schema-sql.d.ts +60 -3
- package/dist/schema-sql.js +261 -4
- package/dist/schema.d.ts +10 -0
- package/dist/sqlite.js +4 -1
- package/package.json +4 -4
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* turbine-orm: write compilation (extracted from builder.ts)
|
|
3
|
+
*
|
|
4
|
+
* SQL builders for the mutating operations (create / createMany / update /
|
|
5
|
+
* delete / upsert / updateMany / deleteMany) plus the write-projection helpers
|
|
6
|
+
* (writeReturningColumns / writeReselectSelection / parseWriteRow, the PII
|
|
7
|
+
* column set, optimistic-lock and atomic-operator SET clauses). All functions
|
|
8
|
+
* take a {@link BuilderCtx} first argument; WHERE compilation is reused from
|
|
9
|
+
* where.ts (via `whereMod`), and the cache / dialect / row-parse primitives
|
|
10
|
+
* stay class-resident, reached through the ctx. See builder.ts for the thin
|
|
11
|
+
* delegating methods and the async execute wrappers.
|
|
12
|
+
*/
|
|
13
|
+
import type { ReturningSelection } from '../dialect.js';
|
|
14
|
+
import type { TableMetadata } from '../schema.js';
|
|
15
|
+
import type { DeferredQuery } from './deferred.js';
|
|
16
|
+
import type { CreateArgs, CreateManyArgs, DeleteArgs, DeleteManyArgs, UpdateArgs, UpdateManyArgs, UpsertArgs } from './types.js';
|
|
17
|
+
import type { BuilderCtx } from './where.js';
|
|
18
|
+
/**
|
|
19
|
+
* Build a `SELECT * ... WHERE <predicate>` that re-fetches the row(s) matched
|
|
20
|
+
* by a write's `where` clause. Used by the `'reselect'` result strategy to
|
|
21
|
+
* return rows from non-RETURNING engines. Reuses the same parameterized WHERE
|
|
22
|
+
* builder as reads, so no user value is interpolated.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildReselectByWhere(qi: BuilderCtx, whereObj: Record<string, unknown>): {
|
|
25
|
+
sql: string;
|
|
26
|
+
params: unknown[];
|
|
27
|
+
};
|
|
28
|
+
export declare function buildCreate<T extends object>(qi: BuilderCtx, args: CreateArgs<T>): DeferredQuery<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Build the `'reselect'` plan for {@link buildCreate}: run the INSERT, then
|
|
31
|
+
* `SELECT * WHERE pk = ?`. Returns `undefined` (skipped) unless the active
|
|
32
|
+
* dialect's result strategy is `'reselect'`, so the PostgreSQL/RETURNING path
|
|
33
|
+
* pays nothing. Not yet wired to a real non-RETURNING engine.
|
|
34
|
+
*/
|
|
35
|
+
export declare function makeCreateReselect<T extends object>(qi: BuilderCtx, insertSql: string, insertParams: unknown[], data: Record<string, unknown>): DeferredQuery<T>['reselect'];
|
|
36
|
+
export declare function buildCreateMany<T extends object>(qi: BuilderCtx, args: CreateManyArgs<T>): DeferredQuery<T[]>;
|
|
37
|
+
export declare function buildUpdate<T extends object>(qi: BuilderCtx, args: UpdateArgs<T>): DeferredQuery<T>;
|
|
38
|
+
export declare function buildDelete<T extends object>(qi: BuilderCtx, args: DeleteArgs<T>): DeferredQuery<T>;
|
|
39
|
+
export declare function buildUpsert<T extends object>(qi: BuilderCtx, args: UpsertArgs<T>): DeferredQuery<T>;
|
|
40
|
+
export declare function buildUpdateMany<T extends object>(qi: BuilderCtx, args: UpdateManyArgs<T>): DeferredQuery<{
|
|
41
|
+
count: number;
|
|
42
|
+
}>;
|
|
43
|
+
export declare function buildDeleteMany<T extends object>(qi: BuilderCtx, args: DeleteManyArgs<T>): DeferredQuery<{
|
|
44
|
+
count: number;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* The snake_case names of a table's PII-tagged (`defineSchema` `pii: true`)
|
|
48
|
+
* columns. PII columns are excluded from default projections (findMany /
|
|
49
|
+
* findUnique / relation subqueries / batched loads) unless the query opts in
|
|
50
|
+
* via `includePii` or names the column explicitly in `select`. Returns an
|
|
51
|
+
* empty set for any table with no PII column, so untagged schemas keep their
|
|
52
|
+
* byte-identical SQL.
|
|
53
|
+
*/
|
|
54
|
+
export declare function piiColumns(_qi: BuilderCtx, meta: TableMetadata): Set<string>;
|
|
55
|
+
/**
|
|
56
|
+
* The camelCase field names of a table's PII-tagged columns: the read-side
|
|
57
|
+
* counterpart of {@link piiColumns} applied to already-parsed entities.
|
|
58
|
+
* Used to strip PII from a write's RETURNING/reselect row (writes accept no
|
|
59
|
+
* `includePii`/`select`, so their returned row always applies the default
|
|
60
|
+
* exclusion; you may still write PII fields freely).
|
|
61
|
+
*/
|
|
62
|
+
export declare function piiFields(_qi: BuilderCtx, meta: TableMetadata): string[];
|
|
63
|
+
/**
|
|
64
|
+
* The `RETURNING` / `OUTPUT` selection for a write on this table. A table with
|
|
65
|
+
* no PII column returns `'*'` (every column — byte-identical SQL to before);
|
|
66
|
+
* a table WITH PII columns returns an explicit quoted list of every non-PII
|
|
67
|
+
* column so the PII values never leave the database on a write. A PII-tagged
|
|
68
|
+
* PRIMARY KEY column is kept in the projection regardless (the returned row
|
|
69
|
+
* must stay addressable): tag sensitive data, not keys — a PII PK is
|
|
70
|
+
* documented out of scope for stripping. Writes accept no `select`/`includePii`
|
|
71
|
+
* (unlike reads), so this is the whole write-return policy at the SQL level;
|
|
72
|
+
* {@link parseWriteRow} remains as a defense-in-depth strip (a no-op once the
|
|
73
|
+
* SQL already excludes the columns). Derived purely from static per-table
|
|
74
|
+
* schema metadata, so the write SQL cache needs no extra key segment.
|
|
75
|
+
*/
|
|
76
|
+
export declare function writeReturningColumns(qi: BuilderCtx): ReturningSelection;
|
|
77
|
+
/**
|
|
78
|
+
* String form of {@link writeReturningColumns} for a `SELECT` list (the
|
|
79
|
+
* `'reselect'` result strategy re-fetches via a SELECT, not RETURNING).
|
|
80
|
+
* `'*'` when there is no PII column; otherwise the comma-joined quoted list.
|
|
81
|
+
*/
|
|
82
|
+
export declare function writeReselectSelection(qi: BuilderCtx): string;
|
|
83
|
+
/**
|
|
84
|
+
* Parse a write's returned row (create/update/upsert/delete), then strip the
|
|
85
|
+
* table's PII fields: the write-side read policy. On PII-tagged tables the
|
|
86
|
+
* statement's RETURNING/OUTPUT already omits these columns (see
|
|
87
|
+
* {@link writeReturningColumns}), so this strip is defense-in-depth and a
|
|
88
|
+
* no-op. Untagged tables incur only one `for` over a zero-length field list,
|
|
89
|
+
* so behavior is unchanged.
|
|
90
|
+
*/
|
|
91
|
+
export declare function parseWriteRow(qi: BuilderCtx, row: Record<string, unknown>): Record<string, unknown>;
|
|
92
|
+
/**
|
|
93
|
+
* Reject any write against a view (H4). Views are introspected with
|
|
94
|
+
* `isView: true` and are read-only in every engine; a write raises a
|
|
95
|
+
* {@link ValidationError} (E003) rather than emitting SQL Postgres would
|
|
96
|
+
* reject (or, worse, silently applying to an updatable view).
|
|
97
|
+
*/
|
|
98
|
+
export declare function assertWritable(qi: BuilderCtx, operation: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Reject a write whose `data` names a `GENERATED ALWAYS AS (...) STORED`
|
|
101
|
+
* column (H3). Postgres computes these from other columns and errors if you
|
|
102
|
+
* try to write them; we fail early with a clear {@link ValidationError} (E003)
|
|
103
|
+
* instead of surfacing a cryptic driver error. Undefined values are ignored
|
|
104
|
+
* (they're stripped from the statement anyway).
|
|
105
|
+
*/
|
|
106
|
+
export declare function assertNoGeneratedColumns(qi: BuilderCtx, data: Record<string, unknown>, operation: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Build a single SET clause entry for update/updateMany.
|
|
109
|
+
*
|
|
110
|
+
* Supports plain values and atomic operator objects ({ set, increment,
|
|
111
|
+
* decrement, multiply, divide }). An operator object is detected ONLY when
|
|
112
|
+
* it has EXACTLY one key that is one of the 5 operator keys — this avoids
|
|
113
|
+
* misinterpreting JSON column values like `{ set: 'x' }` as operators
|
|
114
|
+
* (real operator objects always have exactly one key, and a plain JSON
|
|
115
|
+
* payload that happens to have a single `set` key is extremely unusual).
|
|
116
|
+
* Multi-key objects are always treated as plain (JSON) values.
|
|
117
|
+
*
|
|
118
|
+
* Returns the SQL fragment (e.g., `"view_count" = "view_count" + $3`) and
|
|
119
|
+
* pushes any required params onto the shared params array so that WHERE
|
|
120
|
+
* clause numbering continues correctly afterward.
|
|
121
|
+
*/
|
|
122
|
+
export declare function buildSetClause(qi: BuilderCtx, key: string, value: unknown, params: unknown[]): string;
|
|
123
|
+
/**
|
|
124
|
+
* Fingerprint SET clauses for update/updateMany.
|
|
125
|
+
* Captures key names + operator types (set/increment/etc) but not values.
|
|
126
|
+
*/
|
|
127
|
+
export declare function fingerprintSet(_qi: BuilderCtx, data: Record<string, unknown>): string;
|
|
128
|
+
/**
|
|
129
|
+
* Collect SET params for update/updateMany. Mirrors buildSetClause param order.
|
|
130
|
+
*/
|
|
131
|
+
export declare function collectSetParams(_qi: BuilderCtx, data: Record<string, unknown>, params: unknown[]): void;
|