turbine-orm 0.55.0 → 0.57.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 +16 -1
- package/dist/cjs/cli/index.d.ts +3 -1
- package/dist/cjs/cli/index.js +341 -14
- package/dist/cjs/client.d.ts +16 -1
- package/dist/cjs/client.js +7 -39
- package/dist/cjs/dialect.d.ts +9 -0
- package/dist/cjs/index-stats.d.ts +46 -0
- package/dist/cjs/index-stats.js +42 -1
- package/dist/cjs/plan-divergence.d.ts +511 -0
- package/dist/cjs/plan-divergence.js +790 -0
- package/dist/cjs/powql.d.ts +11 -0
- package/dist/cjs/powql.js +22 -0
- package/dist/cjs/prisma-compat.d.ts +32 -1
- package/dist/cjs/prisma-compat.js +297 -41
- package/dist/cjs/query/builder.d.ts +45 -0
- package/dist/cjs/query/builder.js +90 -17
- package/dist/cjs/query/deferred.d.ts +9 -0
- package/dist/cjs/query/index.d.ts +2 -0
- package/dist/cjs/query/index.js +18 -1
- package/dist/cjs/query/option-surface.d.ts +100 -0
- package/dist/cjs/query/option-surface.js +214 -0
- package/dist/cjs/query/types.d.ts +140 -0
- package/dist/cjs/query/utils.d.ts +30 -0
- package/dist/cjs/query/utils.js +67 -3
- package/dist/cjs/query/warn-registry.d.ts +8 -0
- package/dist/cjs/query/warn-registry.js +8 -0
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +341 -14
- package/dist/client.d.ts +16 -1
- package/dist/client.js +8 -40
- package/dist/dialect.d.ts +9 -0
- package/dist/index-stats.d.ts +46 -0
- package/dist/index-stats.js +42 -1
- package/dist/plan-divergence.d.ts +511 -0
- package/dist/plan-divergence.js +783 -0
- package/dist/powql.d.ts +11 -0
- package/dist/powql.js +22 -0
- package/dist/prisma-compat.d.ts +32 -1
- package/dist/prisma-compat.js +297 -41
- package/dist/query/builder.d.ts +45 -0
- package/dist/query/builder.js +90 -17
- package/dist/query/deferred.d.ts +9 -0
- package/dist/query/index.d.ts +2 -0
- package/dist/query/index.js +1 -0
- package/dist/query/option-surface.d.ts +100 -0
- package/dist/query/option-surface.js +209 -0
- package/dist/query/types.d.ts +140 -0
- package/dist/query/utils.d.ts +30 -0
- package/dist/query/utils.js +66 -3
- package/dist/query/warn-registry.d.ts +8 -0
- package/dist/query/warn-registry.js +8 -0
- package/package.json +1 -1
package/dist/query/types.d.ts
CHANGED
|
@@ -465,6 +465,8 @@ export interface FindUniqueArgs<T, R extends object = {}, W extends TypedWithCla
|
|
|
465
465
|
skipGlobalFilters?: SkipGlobalFilters;
|
|
466
466
|
/** Include PII-tagged columns in the result. See {@link FindManyArgs.includePii}. */
|
|
467
467
|
includePii?: boolean;
|
|
468
|
+
/** Plan this query with its real parameter values. See {@link FindManyArgs.forceCustomPlan}. */
|
|
469
|
+
forceCustomPlan?: boolean;
|
|
468
470
|
}
|
|
469
471
|
export interface FindManyArgs<T, R extends object = {}, W extends TypedWithClause<R> = TypedWithClause<R>, S extends Record<string, boolean> | undefined = undefined, O extends Record<string, boolean> | undefined = undefined> {
|
|
470
472
|
/** Row filter. Keys are checked against `T` and `R` (see {@link WhereClause}). */
|
|
@@ -518,6 +520,138 @@ export interface FindManyArgs<T, R extends object = {}, W extends TypedWithClaus
|
|
|
518
520
|
* always allowed regardless of this flag (the reference is explicit).
|
|
519
521
|
*/
|
|
520
522
|
includePii?: boolean;
|
|
523
|
+
/**
|
|
524
|
+
* Plan THIS query with its actual parameter values, every execution.
|
|
525
|
+
* PostgreSQL only (see the refusal below).
|
|
526
|
+
*
|
|
527
|
+
* WHY IT EXISTS. Turbine executes through a NAMED prepared statement, which
|
|
528
|
+
* enters the backend's plan cache, and from the sixth execution onward
|
|
529
|
+
* PostgreSQL may replace the per-execution plan with a single GENERIC plan
|
|
530
|
+
* (whenever the generic plan's estimated cost is not worse than the average
|
|
531
|
+
* custom cost). A generic plan substitutes a default for every value it
|
|
532
|
+
* cannot see: an unknown equality gets `rows / n_distinct`, an unknown range
|
|
533
|
+
* gets a third of the table, an unknown LIKE gets 0.5%, and an unknown LIMIT
|
|
534
|
+
* gets 10% of its child node's estimate. When one of those defaults lands on
|
|
535
|
+
* the other side of a plan boundary from the real value, the plan SHAPE
|
|
536
|
+
* flips, and the flip can be catastrophic. It fails in both directions: a
|
|
537
|
+
* default above the truth and a default below it are both capable of it, so
|
|
538
|
+
* "the tenant with few rows" is not the predictor.
|
|
539
|
+
*
|
|
540
|
+
* WHAT IT DOES, stated as the mechanism really is rather than as the tempting
|
|
541
|
+
* one-liner. `true` sends this one statement UNNAMED. It is NOT true that
|
|
542
|
+
* PostgreSQL treats an unnamed statement as a one-shot plan that never enters
|
|
543
|
+
* the plan cache: `exec_parse_message` builds a `CachedPlanSource` and calls
|
|
544
|
+
* `SaveCachedPlan` on it for the unnamed statement too (it is kept in
|
|
545
|
+
* `unnamed_stmt_psrc`). The reason the option works is one level up, in the
|
|
546
|
+
* DRIVER: node-postgres only skips Parse for a statement it has already
|
|
547
|
+
* parsed BY NAME (`Query.hasBeenParsed` is `this.name && ...`), so an unnamed
|
|
548
|
+
* statement is re-Parsed on every execution. Each Parse replaces the unnamed
|
|
549
|
+
* entry with a fresh `CachedPlanSource` whose custom-plan counter starts at
|
|
550
|
+
* zero, so the five-execution threshold that precedes promotion is never
|
|
551
|
+
* reached and every execution is planned with the real parameter values.
|
|
552
|
+
*
|
|
553
|
+
* That distinction matters in practice: the guarantee is a property of the
|
|
554
|
+
* driver's behaviour plus the backend's promotion rule, not a special
|
|
555
|
+
* one-shot plan class, which is exactly why a connection pinned to
|
|
556
|
+
* `force_generic_plan` still overrides it (see PRECEDENCE below).
|
|
557
|
+
*
|
|
558
|
+
* Nothing is set on the session, no `SET` is emitted, no transaction is
|
|
559
|
+
* opened, and no extra round trip is added.
|
|
560
|
+
*
|
|
561
|
+
* WHAT IT CANNOT DO, and why this is a boolean rather than the client-level
|
|
562
|
+
* three-value {@link TurbineConfig.planCacheMode}: the generic direction is
|
|
563
|
+
* NOT expressible per query. `force_generic_plan` is a property of a CACHED
|
|
564
|
+
* plan, and the only per-query lever here is keeping the statement out of the
|
|
565
|
+
* cache, which can only ever mean "custom". A per-query
|
|
566
|
+
* `planCacheMode: 'force_generic_plan'` would be a promise this mechanism
|
|
567
|
+
* cannot keep, so the option is named for the one thing it does.
|
|
568
|
+
*
|
|
569
|
+
* PRECEDENCE over the client-level `planCacheMode`, which is a connection
|
|
570
|
+
* parameter and cannot be unset for one query. Stated exactly, because one of
|
|
571
|
+
* these four is the opposite of what the mechanism suggests:
|
|
572
|
+
* - Client on the default (`planCacheMode` unset) or `'auto'`: this is what
|
|
573
|
+
* the option is FOR. `auto` is the only mode in which promotion to a
|
|
574
|
+
* generic plan happens, and the re-Parse described above resets the
|
|
575
|
+
* counter that promotion depends on before it can ever be reached.
|
|
576
|
+
* - Client on `'force_custom_plan'`: redundant and harmless, both routes
|
|
577
|
+
* plan with the real values.
|
|
578
|
+
* - Client on `'force_generic_plan'`: REFUSED, with `ValidationError`
|
|
579
|
+
* (E003). It does NOT win. That setting governs the unnamed statement's
|
|
580
|
+
* cached plan source as well as a named one (measured on PostgreSQL 16.14: five executions
|
|
581
|
+
* of the same unnamed statement read 19,107 buffers under the setting and
|
|
582
|
+
* 55 with the connection back on `auto`), so withholding the name buys
|
|
583
|
+
* nothing against it and the query would be planned generically anyway.
|
|
584
|
+
* Rather than report a guarantee it cannot keep, Turbine refuses the
|
|
585
|
+
* combination and says which of the two settings to change. Only the
|
|
586
|
+
* setting TURBINE applied is visible: a `plan_cache_mode` installed by a
|
|
587
|
+
* caller's `SET`, `ALTER ROLE`, or a pooler cannot be seen or refused.
|
|
588
|
+
* - `false` / omitted changes nothing. It does not opt back out of a
|
|
589
|
+
* client-level setting, it simply leaves that setting in charge.
|
|
590
|
+
* - With the client-level `preparedStatements: false`, every statement is
|
|
591
|
+
* already unnamed, so this option is a no-op for plan choice.
|
|
592
|
+
*
|
|
593
|
+
* COST, and it has two halves.
|
|
594
|
+
*
|
|
595
|
+
* The first is planning. The statement is parsed and planned on every
|
|
596
|
+
* execution instead of once. On a flat read that is in the noise (an unnamed
|
|
597
|
+
* statement also skips the extra Parse/Describe round trip a named one needs
|
|
598
|
+
* on its first execution, so it can even come out ahead). It grows with the
|
|
599
|
+
* size of the statement: a deep `with` tree is a much larger plan, and
|
|
600
|
+
* re-planning it per execution is a measurable share of a fast query's
|
|
601
|
+
* latency. Turn it on where a plan flip is the risk, not everywhere.
|
|
602
|
+
*
|
|
603
|
+
* The second is the one nobody expects: A CUSTOM PLAN IS NOT ALWAYS THE
|
|
604
|
+
* BETTER PLAN. There are real shapes where the generic plan's ignorance is
|
|
605
|
+
* what saves it, and forcing a custom plan forecloses that. Reproduced on
|
|
606
|
+
* PostgreSQL 16.14, `synchronize_seqscans` off, parallel workers off:
|
|
607
|
+
*
|
|
608
|
+
* ```sql
|
|
609
|
+
* CREATE TABLE ev (id bigserial PRIMARY KEY, tenant_id int NOT NULL, pad text);
|
|
610
|
+
* -- 320,000 rows over 800 tenants, inserted in RANDOM physical order
|
|
611
|
+
* INSERT INTO ev (tenant_id, pad)
|
|
612
|
+
* SELECT t, repeat('x', 60)
|
|
613
|
+
* FROM (SELECT ((g % 800) + 1) AS t FROM generate_series(1, 320000) g
|
|
614
|
+
* ORDER BY random()) s
|
|
615
|
+
* WHERE t <> 400;
|
|
616
|
+
* -- then tenant 400's 80,000 rows LAST, so they all sit past everything above
|
|
617
|
+
* INSERT INTO ev (tenant_id, pad)
|
|
618
|
+
* SELECT 400, repeat('x', 60) FROM generate_series(1, 80000) g;
|
|
619
|
+
* CREATE INDEX ev_tenant_idx ON ev (tenant_id);
|
|
620
|
+
* ANALYZE ev; -- relpages 5334, n_distinct 800, correlation 0.004
|
|
621
|
+
*
|
|
622
|
+
* PREPARE q(int, int) AS SELECT * FROM ev WHERE tenant_id = $1 LIMIT $2;
|
|
623
|
+
* -- force_custom_plan : Seq Scan, Buffers: shared hit=4262
|
|
624
|
+
* -- force_generic_plan: Bitmap Heap Scan, Buffers: shared hit=71
|
|
625
|
+
* ```
|
|
626
|
+
*
|
|
627
|
+
* 60x, with no `ORDER BY` anywhere. The custom planner knows tenant 400 is
|
|
628
|
+
* 20% of the table, so with `LIMIT 20` it prices a sequential scan as
|
|
629
|
+
* essentially free on the assumption it will stop almost immediately. It is
|
|
630
|
+
* right about how MANY rows match and wrong about WHERE they are: they are
|
|
631
|
+
* all at the end of the heap, so it reads 319,600 non-matching rows first.
|
|
632
|
+
* The generic plan, unable to see the value, estimates 500 rows, takes the
|
|
633
|
+
* bitmap path, and touches one heap block. Re-insert the identical rows in
|
|
634
|
+
* random physical order and the effect vanishes and reverses (custom 2
|
|
635
|
+
* buffers, generic 66): physical CLUSTERING is the variable, not selectivity.
|
|
636
|
+
*
|
|
637
|
+
* Read that carefully before treating it as an argument against this option.
|
|
638
|
+
* On that shape `plan_cache_mode = auto` never promotes (the generic plan's
|
|
639
|
+
* ESTIMATED cost is far higher than the average custom cost, which is exactly
|
|
640
|
+
* the condition under which `auto` refuses), so the default already produces
|
|
641
|
+
* the 4,262-buffer plan and `forceCustomPlan` costs nothing against it. The
|
|
642
|
+
* honest statement is that a generic plan is 60x better there than either the
|
|
643
|
+
* default or this option, and only an explicit client-level
|
|
644
|
+
* `planCacheMode: 'force_generic_plan'` can reach it. The reason to scope
|
|
645
|
+
* this option per query is still real: it is a targeted remedy for a measured
|
|
646
|
+
* flip, not a setting to turn on globally.
|
|
647
|
+
*
|
|
648
|
+
* NON-POSTGRESQL ENGINES. `true` throws {@link UnsupportedFeatureError}
|
|
649
|
+
* (E017), the same refusal the client-level option gives: an engine with no
|
|
650
|
+
* PostgreSQL plan cache has no cached generic plan to keep this query out of,
|
|
651
|
+
* so silently accepting the flag would report a guarantee that was never
|
|
652
|
+
* made. Omitting it (or `false`) is accepted everywhere.
|
|
653
|
+
*/
|
|
654
|
+
forceCustomPlan?: boolean;
|
|
521
655
|
}
|
|
522
656
|
export interface FindManyStreamArgs<T, R extends object = {}, W extends TypedWithClause<R> = TypedWithClause<R>, S extends Record<string, boolean> | undefined = undefined, O extends Record<string, boolean> | undefined = undefined> extends FindManyArgs<T, R, W, S, O> {
|
|
523
657
|
/**
|
|
@@ -716,6 +850,8 @@ export interface CountArgs<T, R extends object = {}> {
|
|
|
716
850
|
timeout?: number;
|
|
717
851
|
/** Opt out of configured {@link GlobalFilters}. See {@link SkipGlobalFilters}. */
|
|
718
852
|
skipGlobalFilters?: SkipGlobalFilters;
|
|
853
|
+
/** Plan this query with its real parameter values. See {@link FindManyArgs.forceCustomPlan}. */
|
|
854
|
+
forceCustomPlan?: boolean;
|
|
719
855
|
}
|
|
720
856
|
/**
|
|
721
857
|
* Comparison operators usable inside a `having` aggregate filter. A bare value
|
|
@@ -955,6 +1091,8 @@ export interface GroupByArgs<T, R extends object = {}> {
|
|
|
955
1091
|
timeout?: number;
|
|
956
1092
|
/** Opt out of configured {@link GlobalFilters}. See {@link SkipGlobalFilters}. */
|
|
957
1093
|
skipGlobalFilters?: SkipGlobalFilters;
|
|
1094
|
+
/** Plan this query with its real parameter values. See {@link FindManyArgs.forceCustomPlan}. */
|
|
1095
|
+
forceCustomPlan?: boolean;
|
|
958
1096
|
}
|
|
959
1097
|
/** The by-key union of a groupBy args type (array element type of `by`). */
|
|
960
1098
|
type GroupByKeys<A> = A extends {
|
|
@@ -1055,6 +1193,8 @@ export interface AggregateArgs<T, R extends object = {}> {
|
|
|
1055
1193
|
timeout?: number;
|
|
1056
1194
|
/** Opt out of configured {@link GlobalFilters}. See {@link SkipGlobalFilters}. */
|
|
1057
1195
|
skipGlobalFilters?: SkipGlobalFilters;
|
|
1196
|
+
/** Plan this query with its real parameter values. See {@link FindManyArgs.forceCustomPlan}. */
|
|
1197
|
+
forceCustomPlan?: boolean;
|
|
1058
1198
|
}
|
|
1059
1199
|
/** Result type for aggregate queries */
|
|
1060
1200
|
export interface AggregateResult<T> {
|
package/dist/query/utils.d.ts
CHANGED
|
@@ -319,6 +319,20 @@ export declare function isDefaultTextParser(oid: number, parser: (text: string)
|
|
|
319
319
|
* the origin of, and the resulting bug is order-dependent: which reading wins
|
|
320
320
|
* depends on module evaluation order, which lazy route imports make unstable
|
|
321
321
|
* between requests. So say it out loud, once.
|
|
322
|
+
*
|
|
323
|
+
* NOT DEV-ONLY. It used to go quiet under `NODE_ENV=production`, along with
|
|
324
|
+
* every other dev warning, and that was the wrong rule for THIS one, for the
|
|
325
|
+
* same reason the temporal-infinity warning (builder.ts `warnTemporalInfinity`)
|
|
326
|
+
* is not dev-only either. A parser overwrite is ORDER-DEPENDENT: which module
|
|
327
|
+
* calls `setTypeParser` last decides the reading, and evaluation order is
|
|
328
|
+
* exactly what differs between a dev process (eager imports, one route
|
|
329
|
+
* exercised at a time) and a production one (bundled or lazily imported routes,
|
|
330
|
+
* warmed in whatever order traffic arrives). So a process can be clean in dev
|
|
331
|
+
* and wrong in production purely from import order, which makes production the
|
|
332
|
+
* case that matters MOST, and it was the case that was silent. The cost is
|
|
333
|
+
* bounded to the point of irrelevance: once per OID per process, at client
|
|
334
|
+
* construction, and only when somebody else's non-default parser is actually
|
|
335
|
+
* being replaced.
|
|
322
336
|
*/
|
|
323
337
|
export declare function warnParserOverwrite(oid: number, typeName: string): void;
|
|
324
338
|
/**
|
|
@@ -406,6 +420,22 @@ export declare function jsonWireCoercionOid(pgType: string | undefined): number
|
|
|
406
420
|
export declare function coerceJsonWireValue(oid: number, value: unknown): unknown;
|
|
407
421
|
/** The closest name in `candidates` to `input`, or null when none is close. */
|
|
408
422
|
export declare function closestName(input: string, candidates: Iterable<string>): string | null;
|
|
423
|
+
/**
|
|
424
|
+
* The real option key `key` most likely meant, or null when nothing is close.
|
|
425
|
+
*
|
|
426
|
+
* Shared by every "unknown option" diagnostic (the client-config warner in
|
|
427
|
+
* client.ts and the prisma-compat query-option warner), so a reader who has
|
|
428
|
+
* seen one recognizes the ranking in the other.
|
|
429
|
+
*
|
|
430
|
+
* {@link closestName} decides first, which is bounded by edit distance and
|
|
431
|
+
* covers typos. It does not cover the miss these warnings exist for: a guessed
|
|
432
|
+
* name that omits a whole WORD. `logParams` is five edits from `logQueryParams`,
|
|
433
|
+
* past the bound, yet it names the same words in the same order; likewise
|
|
434
|
+
* `customPlan` for `forceCustomPlan`. So a second pass accepts a candidate whose
|
|
435
|
+
* camelCase words CONTAIN the guess's words in order, preferring the one that
|
|
436
|
+
* adds fewest words.
|
|
437
|
+
*/
|
|
438
|
+
export declare function suggestKey(key: string, candidates: Iterable<string>): string | null;
|
|
409
439
|
/**
|
|
410
440
|
* The "unknown field" error text, listing RELATIONS as well as columns.
|
|
411
441
|
*
|
package/dist/query/utils.js
CHANGED
|
@@ -565,10 +565,22 @@ export function isDefaultTextParser(oid, parser) {
|
|
|
565
565
|
* the origin of, and the resulting bug is order-dependent: which reading wins
|
|
566
566
|
* depends on module evaluation order, which lazy route imports make unstable
|
|
567
567
|
* between requests. So say it out loud, once.
|
|
568
|
+
*
|
|
569
|
+
* NOT DEV-ONLY. It used to go quiet under `NODE_ENV=production`, along with
|
|
570
|
+
* every other dev warning, and that was the wrong rule for THIS one, for the
|
|
571
|
+
* same reason the temporal-infinity warning (builder.ts `warnTemporalInfinity`)
|
|
572
|
+
* is not dev-only either. A parser overwrite is ORDER-DEPENDENT: which module
|
|
573
|
+
* calls `setTypeParser` last decides the reading, and evaluation order is
|
|
574
|
+
* exactly what differs between a dev process (eager imports, one route
|
|
575
|
+
* exercised at a time) and a production one (bundled or lazily imported routes,
|
|
576
|
+
* warmed in whatever order traffic arrives). So a process can be clean in dev
|
|
577
|
+
* and wrong in production purely from import order, which makes production the
|
|
578
|
+
* case that matters MOST, and it was the case that was silent. The cost is
|
|
579
|
+
* bounded to the point of irrelevance: once per OID per process, at client
|
|
580
|
+
* construction, and only when somebody else's non-default parser is actually
|
|
581
|
+
* being replaced.
|
|
568
582
|
*/
|
|
569
583
|
export function warnParserOverwrite(oid, typeName) {
|
|
570
|
-
if (process.env.NODE_ENV === 'production')
|
|
571
|
-
return;
|
|
572
584
|
const getParser = pg.types.getTypeParser;
|
|
573
585
|
const current = getParser(oid, 'text');
|
|
574
586
|
// Turbine's own earlier registration is not a third party's expectation.
|
|
@@ -588,7 +600,9 @@ export function warnParserOverwrite(oid, typeName) {
|
|
|
588
600
|
'process, and Turbine is replacing it. `pg.types.setTypeParser` is process-global and takes effect ' +
|
|
589
601
|
'immediately for EVERY pg.Pool in the process, including pools that already exist and are already ' +
|
|
590
602
|
'querying, so whatever set that parser will now read this column differently. If yours should win, ' +
|
|
591
|
-
`register it AFTER constructing the client.${remedy}
|
|
603
|
+
`register it AFTER constructing the client.${remedy} This warning fires under \`NODE_ENV=production\` ` +
|
|
604
|
+
'too: which parser wins depends on module evaluation order, so a process can be clean in dev and wrong ' +
|
|
605
|
+
'in production from import order alone.');
|
|
592
606
|
}
|
|
593
607
|
/**
|
|
594
608
|
* Register the UTC readings of the four zone-less temporal OIDs on the pg
|
|
@@ -767,6 +781,55 @@ export function closestName(input, candidates) {
|
|
|
767
781
|
}
|
|
768
782
|
return best;
|
|
769
783
|
}
|
|
784
|
+
/** camelCase name → its lowercased words (`logQueryParams` → log, query, params). */
|
|
785
|
+
function camelWords(name) {
|
|
786
|
+
return name
|
|
787
|
+
.split(/(?=[A-Z])/)
|
|
788
|
+
.map((w) => w.toLowerCase())
|
|
789
|
+
.filter(Boolean);
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* The real option key `key` most likely meant, or null when nothing is close.
|
|
793
|
+
*
|
|
794
|
+
* Shared by every "unknown option" diagnostic (the client-config warner in
|
|
795
|
+
* client.ts and the prisma-compat query-option warner), so a reader who has
|
|
796
|
+
* seen one recognizes the ranking in the other.
|
|
797
|
+
*
|
|
798
|
+
* {@link closestName} decides first, which is bounded by edit distance and
|
|
799
|
+
* covers typos. It does not cover the miss these warnings exist for: a guessed
|
|
800
|
+
* name that omits a whole WORD. `logParams` is five edits from `logQueryParams`,
|
|
801
|
+
* past the bound, yet it names the same words in the same order; likewise
|
|
802
|
+
* `customPlan` for `forceCustomPlan`. So a second pass accepts a candidate whose
|
|
803
|
+
* camelCase words CONTAIN the guess's words in order, preferring the one that
|
|
804
|
+
* adds fewest words.
|
|
805
|
+
*/
|
|
806
|
+
export function suggestKey(key, candidates) {
|
|
807
|
+
const direct = closestName(key, candidates);
|
|
808
|
+
if (direct)
|
|
809
|
+
return direct;
|
|
810
|
+
const wanted = camelWords(key);
|
|
811
|
+
if (wanted.length < 2)
|
|
812
|
+
return null;
|
|
813
|
+
let best = null;
|
|
814
|
+
let bestExtra = Number.POSITIVE_INFINITY;
|
|
815
|
+
for (const candidate of candidates) {
|
|
816
|
+
const words = camelWords(candidate);
|
|
817
|
+
if (words.length <= wanted.length)
|
|
818
|
+
continue;
|
|
819
|
+
let i = 0;
|
|
820
|
+
for (const w of words)
|
|
821
|
+
if (w === wanted[i])
|
|
822
|
+
i++;
|
|
823
|
+
if (i !== wanted.length)
|
|
824
|
+
continue;
|
|
825
|
+
const extra = words.length - wanted.length;
|
|
826
|
+
if (extra < bestExtra) {
|
|
827
|
+
bestExtra = extra;
|
|
828
|
+
best = candidate;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return best;
|
|
832
|
+
}
|
|
770
833
|
/**
|
|
771
834
|
* The "unknown field" error text, listing RELATIONS as well as columns.
|
|
772
835
|
*
|
|
@@ -96,6 +96,14 @@ export declare const WARN_NS: {
|
|
|
96
96
|
* `warnParserOverwrite`). Keyed on the OID.
|
|
97
97
|
*/
|
|
98
98
|
readonly parserOverwrite: "parserOverwrite";
|
|
99
|
+
/**
|
|
100
|
+
* A key on the args object passed to a `turbine-orm/prisma-compat` delegate
|
|
101
|
+
* call that is neither a Prisma arg for that operation nor a turbine-native
|
|
102
|
+
* query option (prisma-compat.ts `warnUnknownQueryOptions`). Keyed on
|
|
103
|
+
* `model.operation.key`, so the same typo on two models is two reports, and
|
|
104
|
+
* a million executions of one call site is one.
|
|
105
|
+
*/
|
|
106
|
+
readonly unknownQueryOption: "unknownQueryOption";
|
|
99
107
|
/**
|
|
100
108
|
* `planCacheMode` was set on a client given an EXTERNAL pool, where Turbine
|
|
101
109
|
* runs no connection setup, so the option is a no-op (client.ts constructor).
|
|
@@ -131,6 +131,14 @@ export const WARN_NS = {
|
|
|
131
131
|
* `warnParserOverwrite`). Keyed on the OID.
|
|
132
132
|
*/
|
|
133
133
|
parserOverwrite: 'parserOverwrite',
|
|
134
|
+
/**
|
|
135
|
+
* A key on the args object passed to a `turbine-orm/prisma-compat` delegate
|
|
136
|
+
* call that is neither a Prisma arg for that operation nor a turbine-native
|
|
137
|
+
* query option (prisma-compat.ts `warnUnknownQueryOptions`). Keyed on
|
|
138
|
+
* `model.operation.key`, so the same typo on two models is two reports, and
|
|
139
|
+
* a million executions of one call site is one.
|
|
140
|
+
*/
|
|
141
|
+
unknownQueryOption: 'unknownQueryOption',
|
|
134
142
|
/**
|
|
135
143
|
* `planCacheMode` was set on a client given an EXTERNAL pool, where Turbine
|
|
136
144
|
* runs no connection setup, so the option is a no-op (client.ts constructor).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turbine-orm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "Postgres-native TypeScript ORM, runs on Neon, Vercel Postgres, Cloudflare, Supabase. Streaming cursors, typed errors, single-query nested relations. One dependency, no WASM engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"//exports": "Each subpath declares its types PER CONDITION. A single shared top-level \"types\" resolves to the ESM declarations for `require` too, which is TS1479 (\"is an ES module ... cannot be require()d\") for any CJS consumer on moduleResolution node16/nodenext. The require condition points at dist/cjs, which ships its own {\"type\":\"commonjs\"} package.json, so those declarations are CJS declarations. Gated in CI by publint + @arethetypeswrong/cli + a real .cts consumer typecheck (see the package-types job in ci.yml).",
|