turbine-orm 0.81.0 → 0.90.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 +26 -25
- package/dist/checkout.d.ts +27 -2
- package/dist/checkout.js +75 -4
- package/dist/cjs/checkout.d.ts +27 -2
- package/dist/cjs/checkout.js +76 -3
- package/dist/cjs/cli/code-first-tags.d.ts +62 -0
- package/dist/cjs/cli/code-first-tags.js +124 -0
- package/dist/cjs/cli/compile-query.js +9 -0
- package/dist/cjs/cli/config.d.ts +35 -6
- package/dist/cjs/cli/config.js +17 -1
- package/dist/cjs/cli/destructive.d.ts +7 -4
- package/dist/cjs/cli/destructive.js +224 -20
- package/dist/cjs/cli/error-catalog.js +36 -0
- package/dist/cjs/cli/error-text.d.ts +15 -0
- package/dist/cjs/cli/error-text.js +40 -0
- package/dist/cjs/cli/index.d.ts +62 -4
- package/dist/cjs/cli/index.js +568 -108
- package/dist/cjs/cli/local-server-guard.d.ts +53 -0
- package/dist/cjs/cli/local-server-guard.js +119 -0
- package/dist/cjs/cli/local-server-output.d.ts +41 -0
- package/dist/cjs/cli/local-server-output.js +103 -0
- package/dist/cjs/cli/mcp.d.ts +8 -0
- package/dist/cjs/cli/mcp.js +121 -32
- package/dist/cjs/cli/migrate.d.ts +113 -5
- package/dist/cjs/cli/migrate.js +270 -21
- package/dist/cjs/cli/observe.d.ts +6 -1
- package/dist/cjs/cli/observe.js +85 -55
- package/dist/cjs/cli/pii-predicate-guard.d.ts +43 -23
- package/dist/cjs/cli/pii-predicate-guard.js +98 -37
- package/dist/cjs/cli/prisma-resolve.js +17 -13
- package/dist/cjs/cli/prisma-schema.js +12 -4
- package/dist/cjs/cli/studio-ui.generated.js +1 -1
- package/dist/cjs/cli/studio.d.ts +14 -2
- package/dist/cjs/cli/studio.js +244 -69
- package/dist/cjs/cli/ui.d.ts +1 -1
- package/dist/cjs/client.d.ts +558 -85
- package/dist/cjs/client.js +1270 -395
- package/dist/cjs/connection-guard.d.ts +13 -0
- package/dist/cjs/connection-guard.js +28 -0
- package/dist/cjs/connection-url.d.ts +51 -16
- package/dist/cjs/connection-url.js +67 -34
- package/dist/cjs/diagnostics.d.ts +81 -0
- package/dist/cjs/diagnostics.js +147 -0
- package/dist/cjs/dialect.d.ts +449 -20
- package/dist/cjs/dialect.js +117 -76
- package/dist/cjs/engine-config.d.ts +7 -6
- package/dist/cjs/errors.d.ts +126 -6
- package/dist/cjs/errors.js +256 -13
- package/dist/cjs/generate.d.ts +57 -7
- package/dist/cjs/generate.js +635 -279
- package/dist/cjs/global-filters-config.d.ts +59 -0
- package/dist/cjs/global-filters-config.js +367 -0
- package/dist/cjs/index.d.ts +9 -4
- package/dist/cjs/index.js +10 -2
- package/dist/cjs/introspect.d.ts +31 -6
- package/dist/cjs/introspect.js +108 -50
- package/dist/cjs/log-codes.d.ts +12 -0
- package/dist/cjs/log-codes.js +77 -0
- package/dist/cjs/logger.d.ts +87 -0
- package/dist/cjs/logger.js +98 -0
- package/dist/cjs/mssql.d.ts +8 -5
- package/dist/cjs/mssql.js +352 -65
- package/dist/cjs/mysql.d.ts +3 -5
- package/dist/cjs/mysql.js +420 -70
- package/dist/cjs/nested-write.d.ts +3 -0
- package/dist/cjs/nested-write.js +179 -114
- package/dist/cjs/pipeline-submittable.d.ts +12 -0
- package/dist/cjs/pipeline-submittable.js +118 -44
- package/dist/cjs/pipeline.js +21 -26
- package/dist/cjs/powdb-introspect.d.ts +5 -2
- package/dist/cjs/powdb-introspect.js +20 -15
- package/dist/cjs/powdb-shared.d.ts +36 -5
- package/dist/cjs/powdb-shared.js +67 -8
- package/dist/cjs/powdb.d.ts +4 -0
- package/dist/cjs/powdb.js +183 -51
- package/dist/cjs/powql.d.ts +394 -51
- package/dist/cjs/powql.js +1829 -284
- package/dist/cjs/prisma-compat.d.ts +23 -15
- package/dist/cjs/prisma-compat.js +507 -372
- package/dist/cjs/query/aggregates.d.ts +17 -1
- package/dist/cjs/query/aggregates.js +261 -29
- package/dist/cjs/query/batched-loader.d.ts +25 -6
- package/dist/cjs/query/batched-loader.js +103 -20
- package/dist/cjs/query/builder.d.ts +325 -184
- package/dist/cjs/query/builder.js +1452 -490
- package/dist/cjs/query/column-ref.d.ts +61 -0
- package/dist/cjs/query/column-ref.js +73 -0
- package/dist/cjs/query/compound-unique.d.ts +21 -0
- package/dist/cjs/query/compound-unique.js +98 -18
- package/dist/cjs/query/deferred.d.ts +53 -16
- package/dist/cjs/query/expr.d.ts +217 -0
- package/dist/cjs/query/expr.js +859 -0
- package/dist/cjs/query/filters.d.ts +155 -53
- package/dist/cjs/query/filters.js +613 -76
- package/dist/cjs/query/index.d.ts +2 -0
- package/dist/cjs/query/index.js +7 -1
- package/dist/cjs/query/json-value.d.ts +43 -0
- package/dist/cjs/query/json-value.js +59 -0
- package/dist/cjs/query/normalize-args.d.ts +87 -0
- package/dist/cjs/query/normalize-args.js +527 -0
- package/dist/cjs/query/option-surface.d.ts +16 -4
- package/dist/cjs/query/option-surface.js +57 -14
- package/dist/cjs/query/relation-names.d.ts +14 -0
- package/dist/cjs/query/relation-names.js +77 -18
- package/dist/cjs/query/relations.d.ts +30 -3
- package/dist/cjs/query/relations.js +219 -63
- package/dist/cjs/query/row-lock.d.ts +49 -0
- package/dist/cjs/query/row-lock.js +138 -0
- package/dist/cjs/query/sql-comment.d.ts +161 -0
- package/dist/cjs/query/sql-comment.js +381 -0
- package/dist/cjs/query/stream-idle.d.ts +132 -0
- package/dist/cjs/query/stream-idle.js +212 -0
- package/dist/cjs/query/table-client.d.ts +101 -0
- package/dist/cjs/query/table-client.js +74 -0
- package/dist/cjs/query/types.d.ts +677 -298
- package/dist/cjs/query/utils.d.ts +105 -6
- package/dist/cjs/query/utils.js +426 -19
- package/dist/cjs/query/warn-registry.d.ts +18 -0
- package/dist/cjs/query/warn-registry.js +18 -0
- package/dist/cjs/query/where-compile.d.ts +138 -14
- package/dist/cjs/query/where-compile.js +513 -29
- package/dist/cjs/query/where.d.ts +159 -59
- package/dist/cjs/query/where.js +716 -246
- package/dist/cjs/query/writes.d.ts +112 -50
- package/dist/cjs/query/writes.js +1498 -200
- package/dist/cjs/query-events.d.ts +4 -2
- package/dist/cjs/query-events.js +3 -1
- package/dist/cjs/realtime.d.ts +7 -3
- package/dist/cjs/realtime.js +13 -2
- package/dist/cjs/schema-builder.d.ts +55 -4
- package/dist/cjs/schema-builder.js +382 -18
- package/dist/cjs/schema-metadata.d.ts +21 -1
- package/dist/cjs/schema-metadata.js +29 -7
- package/dist/cjs/schema-sql.d.ts +75 -5
- package/dist/cjs/schema-sql.js +497 -45
- package/dist/cjs/schema.d.ts +26 -5
- package/dist/cjs/schema.js +110 -13
- package/dist/cjs/sql-placeholders.d.ts +56 -0
- package/dist/cjs/sql-placeholders.js +204 -0
- package/dist/cjs/sqlite.d.ts +75 -20
- package/dist/cjs/sqlite.js +593 -95
- package/dist/cjs/supplied-pool-types.d.ts +48 -0
- package/dist/cjs/supplied-pool-types.js +256 -0
- package/dist/cjs/transaction-control.d.ts +51 -0
- package/dist/cjs/transaction-control.js +316 -0
- package/dist/cjs/transaction-state.d.ts +342 -0
- package/dist/cjs/transaction-state.js +707 -0
- package/dist/cjs/typed-sql.d.ts +37 -3
- package/dist/cjs/typed-sql.js +102 -8
- package/dist/cli/code-first-tags.d.ts +62 -0
- package/dist/cli/code-first-tags.js +120 -0
- package/dist/cli/compile-query.js +9 -0
- package/dist/cli/config.d.ts +35 -6
- package/dist/cli/config.js +16 -1
- package/dist/cli/destructive.d.ts +7 -4
- package/dist/cli/destructive.js +224 -20
- package/dist/cli/error-catalog.js +36 -0
- package/dist/cli/error-text.d.ts +15 -0
- package/dist/cli/error-text.js +37 -0
- package/dist/cli/index.d.ts +62 -4
- package/dist/cli/index.js +569 -112
- package/dist/cli/local-server-guard.d.ts +53 -0
- package/dist/cli/local-server-guard.js +113 -0
- package/dist/cli/local-server-output.d.ts +41 -0
- package/dist/cli/local-server-output.js +98 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +121 -34
- package/dist/cli/migrate.d.ts +113 -5
- package/dist/cli/migrate.js +261 -21
- package/dist/cli/observe.d.ts +6 -1
- package/dist/cli/observe.js +84 -54
- package/dist/cli/pii-predicate-guard.d.ts +43 -23
- package/dist/cli/pii-predicate-guard.js +100 -35
- package/dist/cli/prisma-resolve.js +15 -11
- package/dist/cli/prisma-schema.js +12 -4
- package/dist/cli/studio-ui.generated.js +1 -1
- package/dist/cli/studio.d.ts +14 -2
- package/dist/cli/studio.js +246 -71
- package/dist/cli/ui.d.ts +1 -1
- package/dist/client.d.ts +558 -85
- package/dist/client.js +1275 -400
- package/dist/connection-guard.d.ts +13 -0
- package/dist/connection-guard.js +27 -0
- package/dist/connection-url.d.ts +51 -16
- package/dist/connection-url.js +63 -34
- package/dist/diagnostics.d.ts +81 -0
- package/dist/diagnostics.js +144 -0
- package/dist/dialect.d.ts +449 -20
- package/dist/dialect.js +115 -43
- package/dist/engine-config.d.ts +7 -6
- package/dist/errors.d.ts +126 -6
- package/dist/errors.js +252 -12
- package/dist/generate.d.ts +57 -7
- package/dist/generate.js +635 -281
- package/dist/global-filters-config.d.ts +59 -0
- package/dist/global-filters-config.js +361 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +4 -2
- package/dist/introspect.d.ts +31 -6
- package/dist/introspect.js +106 -50
- package/dist/log-codes.d.ts +12 -0
- package/dist/log-codes.js +74 -0
- package/dist/logger.d.ts +87 -0
- package/dist/logger.js +93 -0
- package/dist/mssql.d.ts +8 -5
- package/dist/mssql.js +354 -67
- package/dist/mysql.d.ts +3 -5
- package/dist/mysql.js +423 -73
- package/dist/nested-write.d.ts +3 -0
- package/dist/nested-write.js +177 -112
- package/dist/pipeline-submittable.d.ts +12 -0
- package/dist/pipeline-submittable.js +117 -44
- package/dist/pipeline.js +21 -26
- package/dist/powdb-introspect.d.ts +5 -2
- package/dist/powdb-introspect.js +21 -16
- package/dist/powdb-shared.d.ts +36 -5
- package/dist/powdb-shared.js +65 -8
- package/dist/powdb.d.ts +4 -0
- package/dist/powdb.js +183 -51
- package/dist/powql.d.ts +394 -51
- package/dist/powql.js +1836 -291
- package/dist/prisma-compat.d.ts +23 -15
- package/dist/prisma-compat.js +508 -373
- package/dist/query/aggregates.d.ts +17 -1
- package/dist/query/aggregates.js +263 -32
- package/dist/query/batched-loader.d.ts +25 -6
- package/dist/query/batched-loader.js +101 -21
- package/dist/query/builder.d.ts +325 -184
- package/dist/query/builder.js +1458 -495
- package/dist/query/column-ref.d.ts +61 -0
- package/dist/query/column-ref.js +66 -0
- package/dist/query/compound-unique.d.ts +21 -0
- package/dist/query/compound-unique.js +97 -19
- package/dist/query/deferred.d.ts +53 -16
- package/dist/query/expr.d.ts +217 -0
- package/dist/query/expr.js +848 -0
- package/dist/query/filters.d.ts +155 -53
- package/dist/query/filters.js +597 -72
- package/dist/query/index.d.ts +2 -0
- package/dist/query/index.js +4 -0
- package/dist/query/json-value.d.ts +43 -0
- package/dist/query/json-value.js +54 -0
- package/dist/query/normalize-args.d.ts +87 -0
- package/dist/query/normalize-args.js +517 -0
- package/dist/query/option-surface.d.ts +16 -4
- package/dist/query/option-surface.js +56 -13
- package/dist/query/relation-names.d.ts +14 -0
- package/dist/query/relation-names.js +77 -19
- package/dist/query/relations.d.ts +30 -3
- package/dist/query/relations.js +220 -67
- package/dist/query/row-lock.d.ts +49 -0
- package/dist/query/row-lock.js +131 -0
- package/dist/query/sql-comment.d.ts +161 -0
- package/dist/query/sql-comment.js +374 -0
- package/dist/query/stream-idle.d.ts +132 -0
- package/dist/query/stream-idle.js +203 -0
- package/dist/query/table-client.d.ts +101 -0
- package/dist/query/table-client.js +70 -0
- package/dist/query/types.d.ts +677 -298
- package/dist/query/utils.d.ts +105 -6
- package/dist/query/utils.js +414 -18
- package/dist/query/warn-registry.d.ts +18 -0
- package/dist/query/warn-registry.js +18 -0
- package/dist/query/where-compile.d.ts +138 -14
- package/dist/query/where-compile.js +508 -31
- package/dist/query/where.d.ts +159 -59
- package/dist/query/where.js +711 -248
- package/dist/query/writes.d.ts +112 -50
- package/dist/query/writes.js +1496 -202
- package/dist/query-events.d.ts +4 -2
- package/dist/query-events.js +3 -1
- package/dist/realtime.d.ts +7 -3
- package/dist/realtime.js +13 -2
- package/dist/schema-builder.d.ts +55 -4
- package/dist/schema-builder.js +381 -18
- package/dist/schema-metadata.d.ts +21 -1
- package/dist/schema-metadata.js +28 -7
- package/dist/schema-sql.d.ts +75 -5
- package/dist/schema-sql.js +494 -44
- package/dist/schema.d.ts +26 -5
- package/dist/schema.js +109 -13
- package/dist/sql-placeholders.d.ts +56 -0
- package/dist/sql-placeholders.js +200 -0
- package/dist/sqlite.d.ts +75 -20
- package/dist/sqlite.js +597 -99
- package/dist/supplied-pool-types.d.ts +48 -0
- package/dist/supplied-pool-types.js +247 -0
- package/dist/transaction-control.d.ts +51 -0
- package/dist/transaction-control.js +311 -0
- package/dist/transaction-state.d.ts +342 -0
- package/dist/transaction-state.js +696 -0
- package/dist/typed-sql.d.ts +37 -3
- package/dist/typed-sql.js +100 -8
- package/package.json +7 -4
- package/skills/turbine-orm/SKILL.md +56 -6
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
*
|
|
16
16
|
* This module removes the drift BY CONSTRUCTION:
|
|
17
17
|
* - {@link walkWhere} is the ONE enumeration. It sorts keys canonically,
|
|
18
|
-
* skips `undefined
|
|
19
|
-
* relation filters, and yields a
|
|
20
|
-
*
|
|
21
|
-
* combinator structure
|
|
18
|
+
* skips `undefined` values, applies the one combinator-shape rule
|
|
19
|
+
* ({@link combinatorBranches}), dispatches relation filters, and yields a
|
|
20
|
+
* flat, ordered {@link WhereEvent} stream. All three consumers iterate this
|
|
21
|
+
* same stream, so their key order, combinator structure and view of
|
|
22
|
+
* `undefined` can never diverge.
|
|
22
23
|
* - {@link classifyScalarForSql} is the ONE scalar-shape decision the SQL
|
|
23
24
|
* paths use. `buildWhereClause` and `collectWhereParams` BOTH call it with
|
|
24
25
|
* the same `(rawColumn, value)`, so they always take the same branch and
|
|
@@ -120,10 +121,17 @@ export type ScalarSqlClass = {
|
|
|
120
121
|
*/
|
|
121
122
|
export type WhereEvent = {
|
|
122
123
|
kind: 'or';
|
|
123
|
-
conditions: WhereRecord[];
|
|
124
|
-
}
|
|
124
|
+
conditions: readonly WhereRecord[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* `fixedArity` marks an `AND` written as one object (`AND: { ... }`): its
|
|
128
|
+
* SQL has one branch whatever the caller sends, so it need not give up the
|
|
129
|
+
* prepared-statement name a caller-sized array does.
|
|
130
|
+
*/
|
|
131
|
+
| {
|
|
125
132
|
kind: 'and';
|
|
126
|
-
conditions: WhereRecord[];
|
|
133
|
+
conditions: readonly WhereRecord[];
|
|
134
|
+
fixedArity?: true;
|
|
127
135
|
} | {
|
|
128
136
|
kind: 'not';
|
|
129
137
|
condition: WhereRecord;
|
|
@@ -138,17 +146,133 @@ export type WhereEvent = {
|
|
|
138
146
|
value: unknown;
|
|
139
147
|
};
|
|
140
148
|
/**
|
|
141
|
-
*
|
|
142
|
-
* `
|
|
149
|
+
* Why a relation-filter key's value cannot be read, or `null` when it can.
|
|
150
|
+
* `some` / `none` / `every` take a where object; `is` / `isNot` take a where
|
|
151
|
+
* object or `null`. Any other value (`null` on a quantifier, a scalar, an
|
|
152
|
+
* array) used to compile to no condition at all, so a filter, or a tenant
|
|
153
|
+
* global filter, built from a missing value matched every row. Shared with the
|
|
154
|
+
* PowDB engine so both refuse the same values in the same words.
|
|
155
|
+
*/
|
|
156
|
+
export declare function relationFilterValueProblem(wrapper: string, value: unknown): string | null;
|
|
157
|
+
/**
|
|
158
|
+
* Why a relation filter reads a to-one key on a to-many relation, or `null`
|
|
159
|
+
* when it does not. `posts: { is: {...} }` compiled to "at least one post
|
|
160
|
+
* matches" and `isNot` to "no post matches", which is not what either word says
|
|
161
|
+
* about a list of rows, and the typed API never offers them there. The
|
|
162
|
+
* quantifiers on a to-one relation are left alone: with at most one related
|
|
163
|
+
* row, `some` / `none` / `every` each have one reading. Shared with the PowDB
|
|
164
|
+
* engine so both refuse the same filters in the same words.
|
|
165
|
+
*/
|
|
166
|
+
export declare function relationCardinalityProblem(relDef: RelationDef, filterObj: WhereRecord): string | null;
|
|
167
|
+
/**
|
|
168
|
+
* A bare where object on a to-one relation is an implicit `is`
|
|
169
|
+
* (`{ author: { name: 'x' } }` is `{ author: { is: { name: 'x' } } }`). To-many
|
|
170
|
+
* relations still require a quantifier. The one rule, used by the SQL engines'
|
|
171
|
+
* hosts and by PowDB.
|
|
172
|
+
*/
|
|
173
|
+
export declare function normalizeToOneRelationFilter(relDef: RelationDef, filterObj: WhereRecord): WhereRecord;
|
|
174
|
+
/** The where combinators. */
|
|
175
|
+
export type CombinatorKey = 'AND' | 'OR' | 'NOT';
|
|
176
|
+
/**
|
|
177
|
+
* THE combinator-shape rule, shared by every walker over a where (or having)
|
|
178
|
+
* clause: the SQL walk below, `having`, and the `globalFilters` check at
|
|
179
|
+
* construction. Returns the branches `value` stands for, or throws
|
|
180
|
+
* {@link ValidationError} (E003).
|
|
181
|
+
*
|
|
182
|
+
* - `AND` and `NOT` take one where object (a single branch) or an array of
|
|
183
|
+
* them; `OR` takes an array. This is Prisma's shape.
|
|
184
|
+
* - Anything else is refused by name: `OR: { ... }`, a string, a number,
|
|
185
|
+
* `null`, and an array holding one of those. A combinator the compiler
|
|
186
|
+
* cannot read would compile to nothing, so a mistyped filter, or a
|
|
187
|
+
* tenant filter built as `{ OR: { orgId } }`, would match every row.
|
|
188
|
+
* - An `undefined` member is absent and is dropped. When every member was
|
|
189
|
+
* `undefined` the combinator itself is absent and this returns `null`, the
|
|
190
|
+
* same reading the args seam gives it.
|
|
191
|
+
*
|
|
192
|
+
* An array written empty is returned empty; what that means is the caller's
|
|
193
|
+
* rule (in a where clause: `OR: []` matches nothing, `AND: []` and `NOT: []`
|
|
194
|
+
* apply no condition). Returns the input array by reference when it holds no
|
|
195
|
+
* `undefined`, so the common path allocates nothing.
|
|
196
|
+
*/
|
|
197
|
+
export declare function combinatorBranches(key: CombinatorKey, value: unknown, table: string, clause?: 'where' | 'having'): readonly WhereRecord[] | null;
|
|
198
|
+
/**
|
|
199
|
+
* THE canonical WHERE enumeration. Yields events in sorted-key order,
|
|
200
|
+
* dispatching combinators and relation filters, so every consumer
|
|
143
201
|
* (fingerprint, SQL build, param collect) walks identically.
|
|
144
202
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
203
|
+
* `undefined`: the args seam is the authority and removes it, with every
|
|
204
|
+
* object it emptied, before any of this runs. This walk is the backstop for
|
|
205
|
+
* callers below the seam and reads only `undefined` itself: a key holding it
|
|
206
|
+
* is skipped, a combinator member holding it is dropped, and a relation filter
|
|
207
|
+
* whose wrapper keys all hold it is absent. Values are never looked inside, so
|
|
208
|
+
* a JSON operand is data whatever its shape.
|
|
209
|
+
*
|
|
210
|
+
* Combinators follow {@link combinatorBranches}. `AND` and `NOT` with no
|
|
211
|
+
* branches apply no condition; `OR` with none matches no row
|
|
212
|
+
* ({@link matchNothingEvent}), and an `OR` member made only of `undefined` is
|
|
213
|
+
* dropped ({@link isAbsentBranch}). A `NOT` array negates each branch (`NOT a AND
|
|
214
|
+
* NOT b`), as Prisma does; a `NOT` object negates the object as a whole. A key
|
|
215
|
+
* that names a relation takes only the relation-filter keys (a to-one relation
|
|
216
|
+
* also takes a bare where object, read as `is`), each holding a value the
|
|
217
|
+
* compiler reads ({@link relationFilterValueProblem}), and anything else is
|
|
218
|
+
* refused (E003). Only when the key also names a column, and its object names
|
|
219
|
+
* no relation-filter key, is it that column's filter.
|
|
150
220
|
*/
|
|
151
221
|
export declare function walkWhere(host: WhereHost, where: WhereRecord): WhereEvent[];
|
|
222
|
+
/**
|
|
223
|
+
* What a where clause is for every row, read from the SQL it compiles to:
|
|
224
|
+
*
|
|
225
|
+
* - `'empty'`: it compiles to no SQL (`{}`, `AND: []`, `NOT: {}`);
|
|
226
|
+
* - `'true'` / `'false'`: a constant whatever the row holds, NULLs included
|
|
227
|
+
* (`NOT: { OR: [] }` and `OR: [{}, ...]` are TRUE, `OR: []` is FALSE);
|
|
228
|
+
* - `'row'`: it depends on the row.
|
|
229
|
+
*
|
|
230
|
+
* The mass-mutation guard reads it: a where that is `'true'` writes every row
|
|
231
|
+
* exactly as an empty one does. It mirrors the compiler rather than ideal
|
|
232
|
+
* logic, branch for branch: a branch that compiles to nothing makes its `OR`
|
|
233
|
+
* TRUE (the compiler writes the constant), and `NOT` of something that
|
|
234
|
+
* compiles to nothing applies no condition, as in the SQL. Only shapes whose
|
|
235
|
+
* SQL is a constant fold; anything else is `'row'`, so folding never refuses a
|
|
236
|
+
* filter that narrows. Constants come from an empty `in` list (FALSE), an
|
|
237
|
+
* empty `notIn` list (TRUE), an `OR` with a branch that applies no condition
|
|
238
|
+
* (TRUE), and an `EXISTS` / `NOT EXISTS` over a sub-where that is itself
|
|
239
|
+
* constant.
|
|
240
|
+
*
|
|
241
|
+
* `hostFor` gives the host of a relation's target table, or `undefined` when
|
|
242
|
+
* the schema has no such table (the compiler emits nothing for it).
|
|
243
|
+
*
|
|
244
|
+
* With `options.notNull` the fold also reads what the schema says about the
|
|
245
|
+
* rows: on a NOT NULL column `{ not: null }`, `contains: ''` (and
|
|
246
|
+
* `startsWith` / `endsWith`), a comparison of the column with itself, and
|
|
247
|
+
* `hasEvery: []` are TRUE for every row, and `null` / `equals: null` FALSE; on
|
|
248
|
+
* a belongsTo relation whose foreign key is NOT NULL and enforced, and whose
|
|
249
|
+
* target has no global filter, `is: {}` (or a bare `{}`) is TRUE. Only the
|
|
250
|
+
* mass-mutation guard asks for it: a where that is TRUE because of a NOT NULL
|
|
251
|
+
* column writes every row just as an empty one does.
|
|
252
|
+
*/
|
|
253
|
+
export type WhereFold = 'empty' | 'true' | 'false' | 'row';
|
|
254
|
+
/** What {@link foldWhere} may read beyond the SQL. */
|
|
255
|
+
export interface WhereFoldOptions {
|
|
256
|
+
notNull?: {
|
|
257
|
+
/** Whether the engine enforces declared foreign keys (an orphan row has no related row). */
|
|
258
|
+
foreignKeys: boolean;
|
|
259
|
+
/** Whether `table` has a global filter, which applies inside a relation filter's EXISTS. */
|
|
260
|
+
hasGlobalFilter(table: string): boolean;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
export declare function foldWhere(host: WhereHost, where: WhereRecord, hostFor: (table: string) => WhereHost | undefined, depth?: number, options?: WhereFoldOptions): WhereFold;
|
|
264
|
+
/**
|
|
265
|
+
* A {@link WhereHost} over plain table metadata, for callers with no SQL
|
|
266
|
+
* builder (PowDB, construction-time checks). Same column-type and to-one rules
|
|
267
|
+
* as the SQL engines' scoped hosts.
|
|
268
|
+
*/
|
|
269
|
+
export declare function metadataWhereHost(meta: TableMetadata): WhereHost;
|
|
270
|
+
/**
|
|
271
|
+
* {@link foldWhere} for `table` in `tables`, with plain metadata hosts. Also
|
|
272
|
+
* validates the whole clause shape at every depth (combinators, relation-filter
|
|
273
|
+
* keys and values), so a construction-time check can run it on a static filter.
|
|
274
|
+
*/
|
|
275
|
+
export declare function foldWhereFor(tables: Readonly<Record<string, TableMetadata>>, table: string, where: WhereRecord, options?: WhereFoldOptions): WhereFold;
|
|
152
276
|
/**
|
|
153
277
|
* Column-aware SQL classification of a scalar WHERE value. Reproduces the SQL
|
|
154
278
|
* builder's linear fall-through: a JSON/array-shaped value on a non-JSON/array
|