@danceroutine/tango-orm 1.11.13 → 1.11.14

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.
@@ -83,6 +83,7 @@ declare class QueryCompiler {
83
83
  sql: string;
84
84
  params: readonly unknown[];
85
85
  };
86
+ private buildQueryWindowSuffix;
86
87
  private compileManyToManyPrefetch;
87
88
  private compileHydrationNode;
88
89
  private validateHydrationRelation;
@@ -1296,4 +1297,4 @@ interface QuerySetState<T, TSourceModel = unknown> {
1296
1297
  }
1297
1298
  //#endregion
1298
1299
  export { QBuilder as A, index_d_exports$2 as B, ReverseSingleRelations as C, ManyToManyRelatedManagerCreateInputs as D, ManyToManyRelatedManager as E, QNode as F, TableMeta as H, FilterInput as I, FilterValue as L, QueryExecutor as M, QuerySet as N, ManyToManyTargetRef as O, OrderToken as P, FilterKey as R, ReverseCollectionRelations as S, SingleRelationHydrationCardinality as T, QueryResult as U, QueryCompiler as V, ManyRelationHydrationCardinality as _, TableMetaFactory as a, RelationHydrationCardinality as b, RelationMeta as c, GeneratedPrefetchRelatedPathKeys as d, GeneratedRelationFilterKeys as f, InternalRelationHydrationCardinality as g, HydratedRelationMap as h, WhereClause as i, ModelQuerySet as j, index_d_exports$1 as k, ForwardSingleRelations as l, HydratedQueryResult as m, OrderSpec as n, Direction as o, GeneratedSelectRelatedPathKeys as p, index_d_exports as r, CompiledQuery as s, QuerySetState as t, GeneratedHydratedRelationMap as u, MaybeHydratedRelationMap as v, SelectRelatedRelations as w, RelationKeys as x, PrefetchRelatedRelations as y, LookupType as z };
1299
- //# sourceMappingURL=QuerySetState-D9xr3SCH.d.ts.map
1300
+ //# sourceMappingURL=QuerySetState-BBLa-sz1.d.ts.map
@@ -1,5 +1,5 @@
1
- import { D as ManyToManyRelatedManagerCreateInputs, E as ManyToManyRelatedManager, M as QueryExecutor, N as QuerySet, O as ManyToManyTargetRef, U as QueryResult, t as QuerySetState } from "./QuerySetState-D9xr3SCH.js";
2
- import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, t as registerModelObjects } from "./registerModelObjects-DpiMWh5n.js";
1
+ import { D as ManyToManyRelatedManagerCreateInputs, E as ManyToManyRelatedManager, M as QueryExecutor, N as QuerySet, O as ManyToManyTargetRef, U as QueryResult, t as QuerySetState } from "./QuerySetState-BBLa-sz1.js";
2
+ import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, t as registerModelObjects } from "./registerModelObjects-BWUxmI0P.js";
3
3
 
4
4
  //#region src/manager/relations/ManyToManyRelatedQuerySet.d.ts
5
5
  /**
@@ -68,4 +68,4 @@ declare namespace index_d_exports {
68
68
  }
69
69
  //#endregion
70
70
  export { ManyToManyRelatedQuerySetBridge as i, index_d_exports$1 as n, ManyToManyRelatedQuerySet as r, index_d_exports as t };
71
- //# sourceMappingURL=index-DIL4gXO6.d.ts.map
71
+ //# sourceMappingURL=index-DJ1MyxYN.d.ts.map
@@ -1,4 +1,4 @@
1
- import { a as MaterializedModelRecord, n as ModelManager, r as TangoRuntime, t as registerModelObjects } from "./registerModelObjects-DpiMWh5n.js";
1
+ import { a as MaterializedModelRecord, n as ModelManager, r as TangoRuntime, t as registerModelObjects } from "./registerModelObjects-BWUxmI0P.js";
2
2
  import { z } from "zod";
3
3
  import { Model } from "@danceroutine/tango-schema/domain";
4
4
 
@@ -28,4 +28,4 @@ declare global {
28
28
  }
29
29
  //#endregion
30
30
  export { resetTangoRuntime as i, getTangoRuntime as n, initializeTangoRuntime as r, index_d_exports as t };
31
- //# sourceMappingURL=index-Db_GZk8M.d.ts.map
31
+ //# sourceMappingURL=index-DYuC5ymb.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { t as DBClient } from "./DBClient-DuYcXolQ.js";
2
2
  import { i as Dialect, n as AdapterConfig, t as Adapter } from "./Adapter-DKxAaL4l.js";
3
3
  import { c as getDefaultAdapterRegistry, l as SqliteAdapter, o as AdapterRegistry, s as connectDB, t as index_d_exports, u as PostgresAdapter } from "./index-o2LFpJ8S.js";
4
- import { A as QBuilder, E as ManyToManyRelatedManager, F as QNode, H as TableMeta, I as FilterInput, L as FilterValue, M as QueryExecutor, N as QuerySet, O as ManyToManyTargetRef, P as OrderToken, R as FilterKey, U as QueryResult, V as QueryCompiler, c as RelationMeta, i as WhereClause, j as ModelQuerySet, k as index_d_exports$2, n as OrderSpec, o as Direction, s as CompiledQuery, t as QuerySetState, z as LookupType } from "./QuerySetState-D9xr3SCH.js";
5
- import { t as index_d_exports$1 } from "./index-DIL4gXO6.js";
6
- import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, r as TangoRuntime } from "./registerModelObjects-DpiMWh5n.js";
7
- import { i as resetTangoRuntime, n as getTangoRuntime, r as initializeTangoRuntime, t as index_d_exports$3 } from "./index-Db_GZk8M.js";
4
+ import { A as QBuilder, E as ManyToManyRelatedManager, F as QNode, H as TableMeta, I as FilterInput, L as FilterValue, M as QueryExecutor, N as QuerySet, O as ManyToManyTargetRef, P as OrderToken, R as FilterKey, U as QueryResult, V as QueryCompiler, c as RelationMeta, i as WhereClause, j as ModelQuerySet, k as index_d_exports$2, n as OrderSpec, o as Direction, s as CompiledQuery, t as QuerySetState, z as LookupType } from "./QuerySetState-BBLa-sz1.js";
5
+ import { t as index_d_exports$1 } from "./index-DJ1MyxYN.js";
6
+ import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, r as TangoRuntime } from "./registerModelObjects-BWUxmI0P.js";
7
+ import { i as resetTangoRuntime, n as getTangoRuntime, r as initializeTangoRuntime, t as index_d_exports$3 } from "./index-DYuC5ymb.js";
8
8
  import { a as OnCommitOptions, i as AtomicTransaction, n as UnitOfWork, o as SavepointOptions, r as atomic, s as SavepointResult, t as index_d_exports$4 } from "./index-uuG57Y7C.js";
9
9
  export { type Adapter, type AdapterConfig, AdapterRegistry, type AtomicTransaction, type CompiledQuery, type DBClient, type Dialect, type Direction, type FilterInput, type FilterKey, type FilterValue, type LookupType, type ManagerLike, ManyToManyRelatedManager, type ManyToManyTargetRef, type MaterializedModelRecord, ModelManager, ModelQuerySet, type OnCommitOptions, type OrderSpec, type OrderToken, PostgresAdapter, QBuilder as Q, QBuilder, type QNode, QueryCompiler, type QueryExecutor, QueryResult, QuerySet, type QuerySetState, type RelationMeta, type SavepointOptions, type SavepointResult, SqliteAdapter, type TableMeta, TangoRuntime, UnitOfWork, type WhereClause, atomic, connectDB, index_d_exports as connection, getDefaultAdapterRegistry, getTangoRuntime, initializeTangoRuntime, index_d_exports$1 as manager, index_d_exports$2 as query, resetTangoRuntime, index_d_exports$3 as runtime, index_d_exports$4 as transaction };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { i as PostgresAdapter, t as SqliteAdapter } from "./SqliteAdapter-CrUhpTDb.js";
2
2
  import { a as connectDB, i as AdapterRegistry, o as getDefaultAdapterRegistry, t as connection_exports } from "./connection-B2cDwZ72.js";
3
- import { d as QueryCompiler, i as QBuilder, l as QueryResult, n as ModelQuerySet, r as QuerySet, t as query_exports } from "./query-hvcqTb9O.js";
4
- import { n as ModelManager, r as ManyToManyRelatedManager } from "./registerModelObjects-Dr1YYKt3.js";
5
- import { t as manager_exports } from "./manager-BwiDQLup.js";
3
+ import { d as QueryCompiler, i as QBuilder, l as QueryResult, n as ModelQuerySet, r as QuerySet, t as query_exports } from "./query-SyO9nqpp.js";
4
+ import { n as ModelManager, r as ManyToManyRelatedManager } from "./registerModelObjects-D-EA4y_y.js";
5
+ import { t as manager_exports } from "./manager-DTh3wSkd.js";
6
6
  import { i as TangoRuntime, n as initializeTangoRuntime, r as resetTangoRuntime, t as getTangoRuntime } from "./defaultRuntime-WIsxnh8K.js";
7
7
  import { t as runtime_exports } from "./runtime/index.js";
8
8
  import { n as UnitOfWork, r as atomic, t as transaction_exports } from "./transaction-DpDXQq5V.js";
@@ -1,4 +1,4 @@
1
- import { D as ManyToManyRelatedManagerCreateInputs, E as ManyToManyRelatedManager, O as ManyToManyTargetRef } from "../QuerySetState-D9xr3SCH.js";
2
- import { i as ManyToManyRelatedQuerySetBridge, n as index_d_exports, r as ManyToManyRelatedQuerySet } from "../index-DIL4gXO6.js";
3
- import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, t as registerModelObjects } from "../registerModelObjects-DpiMWh5n.js";
1
+ import { D as ManyToManyRelatedManagerCreateInputs, E as ManyToManyRelatedManager, O as ManyToManyTargetRef } from "../QuerySetState-BBLa-sz1.js";
2
+ import { i as ManyToManyRelatedQuerySetBridge, n as index_d_exports, r as ManyToManyRelatedQuerySet } from "../index-DJ1MyxYN.js";
3
+ import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, t as registerModelObjects } from "../registerModelObjects-BWUxmI0P.js";
4
4
  export { type ManagerLike, ManyToManyRelatedManager, type ManyToManyRelatedManagerCreateInputs, ManyToManyRelatedQuerySet, type ManyToManyRelatedQuerySetBridge, type ManyToManyTargetRef, type MaterializedModelRecord, ModelManager, registerModelObjects, index_d_exports as relations };
@@ -1,3 +1,3 @@
1
- import { i as ManyToManyRelatedQuerySet, n as ModelManager, r as ManyToManyRelatedManager, t as registerModelObjects } from "../registerModelObjects-Dr1YYKt3.js";
2
- import { n as relations_exports } from "../manager-BwiDQLup.js";
1
+ import { i as ManyToManyRelatedQuerySet, n as ModelManager, r as ManyToManyRelatedManager, t as registerModelObjects } from "../registerModelObjects-D-EA4y_y.js";
2
+ import { n as relations_exports } from "../manager-DTh3wSkd.js";
3
3
  export { ManyToManyRelatedManager, ManyToManyRelatedQuerySet, ModelManager, registerModelObjects, relations_exports as relations };
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
- import { i as ManyToManyRelatedQuerySet, n as ModelManager, r as ManyToManyRelatedManager, t as registerModelObjects } from "./registerModelObjects-Dr1YYKt3.js";
2
+ import { i as ManyToManyRelatedQuerySet, n as ModelManager, r as ManyToManyRelatedManager, t as registerModelObjects } from "./registerModelObjects-D-EA4y_y.js";
3
3
  //#region src/manager/relations/index.ts
4
4
  var relations_exports = /* @__PURE__ */ __exportAll({
5
5
  ManyToManyRelatedManager: () => ManyToManyRelatedManager,
@@ -17,4 +17,4 @@ var manager_exports = /* @__PURE__ */ __exportAll({
17
17
  //#endregion
18
18
  export { relations_exports as n, manager_exports as t };
19
19
 
20
- //# sourceMappingURL=manager-BwiDQLup.js.map
20
+ //# sourceMappingURL=manager-DTh3wSkd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"manager-BwiDQLup.js","names":[],"sources":["../src/manager/relations/index.ts","../src/manager/index.ts"],"sourcesContent":["/**\n * Domain boundary barrel: centralizes ORM relation managers attached to\n * materialized model records.\n */\n\nexport { ManyToManyRelatedQuerySet } from './ManyToManyRelatedQuerySet';\nexport type { ManyToManyRelatedQuerySetBridge } from './ManyToManyRelatedQuerySet';\nexport { ManyToManyRelatedManager } from './ManyToManyRelatedManager';\nexport type { ManyToManyRelatedManagerCreateInputs, ManyToManyTargetRef } from './ManyToManyRelatedManager';\nexport type { MaterializedModelRecord } from './MaterializedModelRecord';\n","/**\n * Domain boundary barrel: centralizes manager-first ORM APIs.\n */\nexport * as relations from './relations/index';\n\nexport type { ManagerLike } from './ManagerLike';\nexport { ModelManager } from './ModelManager';\nexport { registerModelObjects } from './registerModelObjects';\nexport { ManyToManyRelatedQuerySet } from './relations/ManyToManyRelatedQuerySet';\nexport type { ManyToManyRelatedQuerySetBridge } from './relations/ManyToManyRelatedQuerySet';\nexport { ManyToManyRelatedManager } from './relations/ManyToManyRelatedManager';\nexport type { ManyToManyRelatedManagerCreateInputs, ManyToManyTargetRef } from './relations/ManyToManyRelatedManager';\nexport type { MaterializedModelRecord } from './relations/MaterializedModelRecord';\n"],"mappings":""}
1
+ {"version":3,"file":"manager-DTh3wSkd.js","names":[],"sources":["../src/manager/relations/index.ts","../src/manager/index.ts"],"sourcesContent":["/**\n * Domain boundary barrel: centralizes ORM relation managers attached to\n * materialized model records.\n */\n\nexport { ManyToManyRelatedQuerySet } from './ManyToManyRelatedQuerySet';\nexport type { ManyToManyRelatedQuerySetBridge } from './ManyToManyRelatedQuerySet';\nexport { ManyToManyRelatedManager } from './ManyToManyRelatedManager';\nexport type { ManyToManyRelatedManagerCreateInputs, ManyToManyTargetRef } from './ManyToManyRelatedManager';\nexport type { MaterializedModelRecord } from './MaterializedModelRecord';\n","/**\n * Domain boundary barrel: centralizes manager-first ORM APIs.\n */\nexport * as relations from './relations/index';\n\nexport type { ManagerLike } from './ManagerLike';\nexport { ModelManager } from './ModelManager';\nexport { registerModelObjects } from './registerModelObjects';\nexport { ManyToManyRelatedQuerySet } from './relations/ManyToManyRelatedQuerySet';\nexport type { ManyToManyRelatedQuerySetBridge } from './relations/ManyToManyRelatedQuerySet';\nexport { ManyToManyRelatedManager } from './relations/ManyToManyRelatedManager';\nexport type { ManyToManyRelatedManagerCreateInputs, ManyToManyTargetRef } from './relations/ManyToManyRelatedManager';\nexport type { MaterializedModelRecord } from './relations/MaterializedModelRecord';\n"],"mappings":""}
@@ -1,3 +1,3 @@
1
1
  import { i as Dialect } from "../Adapter-DKxAaL4l.js";
2
- import { A as QBuilder, B as index_d_exports, C as ReverseSingleRelations, F as QNode, H as TableMeta, I as FilterInput, L as FilterValue, M as QueryExecutor, N as QuerySet, P as OrderToken, R as FilterKey, S as ReverseCollectionRelations, T as SingleRelationHydrationCardinality, U as QueryResult, V as QueryCompiler, _ as ManyRelationHydrationCardinality, a as TableMetaFactory, b as RelationHydrationCardinality, c as RelationMeta, d as GeneratedPrefetchRelatedPathKeys, f as GeneratedRelationFilterKeys, g as InternalRelationHydrationCardinality, h as HydratedRelationMap, i as WhereClause, j as ModelQuerySet, l as ForwardSingleRelations, m as HydratedQueryResult, n as OrderSpec, o as Direction, p as GeneratedSelectRelatedPathKeys, r as index_d_exports$1, s as CompiledQuery, t as QuerySetState, u as GeneratedHydratedRelationMap, v as MaybeHydratedRelationMap, w as SelectRelatedRelations, x as RelationKeys, y as PrefetchRelatedRelations, z as LookupType } from "../QuerySetState-D9xr3SCH.js";
2
+ import { A as QBuilder, B as index_d_exports, C as ReverseSingleRelations, F as QNode, H as TableMeta, I as FilterInput, L as FilterValue, M as QueryExecutor, N as QuerySet, P as OrderToken, R as FilterKey, S as ReverseCollectionRelations, T as SingleRelationHydrationCardinality, U as QueryResult, V as QueryCompiler, _ as ManyRelationHydrationCardinality, a as TableMetaFactory, b as RelationHydrationCardinality, c as RelationMeta, d as GeneratedPrefetchRelatedPathKeys, f as GeneratedRelationFilterKeys, g as InternalRelationHydrationCardinality, h as HydratedRelationMap, i as WhereClause, j as ModelQuerySet, l as ForwardSingleRelations, m as HydratedQueryResult, n as OrderSpec, o as Direction, p as GeneratedSelectRelatedPathKeys, r as index_d_exports$1, s as CompiledQuery, t as QuerySetState, u as GeneratedHydratedRelationMap, v as MaybeHydratedRelationMap, w as SelectRelatedRelations, x as RelationKeys, y as PrefetchRelatedRelations, z as LookupType } from "../QuerySetState-BBLa-sz1.js";
3
3
  export { type CompiledQuery, type Dialect, type Direction, type FilterInput, type FilterKey, type FilterValue, type ForwardSingleRelations, type GeneratedHydratedRelationMap, type GeneratedPrefetchRelatedPathKeys, type GeneratedRelationFilterKeys, type GeneratedSelectRelatedPathKeys, type HydratedQueryResult, type HydratedRelationMap, type InternalRelationHydrationCardinality, type LookupType, type ManyRelationHydrationCardinality, type MaybeHydratedRelationMap, ModelQuerySet, type OrderSpec, type OrderToken, type PrefetchRelatedRelations, QBuilder as Q, QBuilder, type QNode, QueryCompiler, type QueryExecutor, QueryResult, QuerySet, type QuerySetState, type RelationHydrationCardinality, type RelationKeys, type RelationMeta, type ReverseCollectionRelations, type ReverseSingleRelations, type SelectRelatedRelations, type SingleRelationHydrationCardinality, type TableMeta, type TableMetaFactory, type WhereClause, index_d_exports as compiler, index_d_exports$1 as domain };
@@ -1,2 +1,2 @@
1
- import { d as QueryCompiler, i as QBuilder, l as QueryResult, n as ModelQuerySet, o as domain_exports, r as QuerySet, u as compiler_exports } from "../query-hvcqTb9O.js";
1
+ import { d as QueryCompiler, i as QBuilder, l as QueryResult, n as ModelQuerySet, o as domain_exports, r as QuerySet, u as compiler_exports } from "../query-SyO9nqpp.js";
2
2
  export { ModelQuerySet, QBuilder as Q, QBuilder, QueryCompiler, QueryResult, QuerySet, compiler_exports as compiler, domain_exports as domain };
@@ -462,10 +462,7 @@ var QueryCompiler = class QueryCompiler {
462
462
  ...this.buildRootHiddenSelects(compiledPrefetchNodes, table)
463
463
  ].join(", ");
464
464
  const whereSQL = whereParts.length ? ` WHERE ${whereParts.join(" AND ")}` : "";
465
- const orderSQL = ` ORDER BY ${state.order?.length ? state.order.map((order) => `${validatedPlan.orderFields[String(order.by)]} ${order.dir.toUpperCase()}`).join(", ") : `${table}.${validatedPlan.meta.pk} ASC`}`;
466
- const hasOffset = state.offset !== void 0;
467
- const limitSQL = state.limit !== void 0 ? ` LIMIT ${state.limit}` : hasOffset && this.adapter.dialect === InternalDialect.SQLITE ? " LIMIT -1" : "";
468
- const offsetSQL = state.offset !== void 0 ? ` OFFSET ${state.offset}` : "";
465
+ const { orderSQL, limitSQL, offsetSQL } = this.buildQueryWindowSuffix(state, validatedPlan, table);
469
466
  return {
470
467
  sql: `SELECT ${select} FROM ${table}${joinCollection.joins.length ? ` ${joinCollection.joins.join(" ")}` : ""}${whereSQL}${orderSQL}${limitSQL}${offsetSQL}`,
471
468
  params,
@@ -506,8 +503,14 @@ var QueryCompiler = class QueryCompiler {
506
503
  params.push(...result.params);
507
504
  }
508
505
  });
506
+ const whereSQL = whereParts.length ? ` WHERE ${whereParts.join(" AND ")}` : "";
507
+ if (state.limit === void 0 && state.offset === void 0) return {
508
+ sql: `SELECT 1 AS tango_exists FROM ${table}${whereSQL} LIMIT 1`,
509
+ params
510
+ };
511
+ const { orderSQL, limitSQL, offsetSQL } = this.buildQueryWindowSuffix(state, validatedPlan, table, { existsProbe: state.offset !== void 0 });
509
512
  return {
510
- sql: `SELECT 1 AS tango_exists FROM ${table}${whereParts.length ? ` WHERE ${whereParts.join(" AND ")}` : ""} LIMIT 1${state.offset ? ` OFFSET ${state.offset}` : ""}`,
513
+ sql: `SELECT 1 AS tango_exists FROM ${table}${whereSQL}${orderSQL}${limitSQL}${offsetSQL}`,
511
514
  params
512
515
  };
513
516
  }
@@ -544,6 +547,15 @@ var QueryCompiler = class QueryCompiler {
544
547
  params: targetIds
545
548
  };
546
549
  }
550
+ buildQueryWindowSuffix(state, validatedPlan, table, options) {
551
+ const orderSQL = ` ORDER BY ${state.order?.length ? state.order.map((order) => `${validatedPlan.orderFields[String(order.by)]} ${order.dir.toUpperCase()}`).join(", ") : `${table}.${validatedPlan.meta.pk} ASC`}`;
552
+ const hasOffset = state.offset !== void 0;
553
+ return {
554
+ orderSQL,
555
+ limitSQL: options?.existsProbe ? state.limit === 0 ? " LIMIT 0" : " LIMIT 1" : state.limit !== void 0 ? ` LIMIT ${state.limit}` : hasOffset && this.adapter.dialect === InternalDialect.SQLITE ? " LIMIT -1" : "",
556
+ offsetSQL: state.offset !== void 0 ? ` OFFSET ${state.offset}` : ""
557
+ };
558
+ }
547
559
  compileManyToManyPrefetch(node, sourceValues) {
548
560
  const placeholders = this.placeholders.list(sourceValues.length);
549
561
  const throughValidated = sqlSafetyAdapter.validate({
@@ -1652,4 +1664,4 @@ var query_exports = /* @__PURE__ */ __exportAll({
1652
1664
  //#endregion
1653
1665
  export { isQNodeLike as a, InternalRelationKind as c, QueryCompiler as d, OrmSqlSafetyAdapter as f, QBuilder as i, QueryResult as l, InternalQNodeType as m, ModelQuerySet as n, domain_exports as o, InternalSqlValidationPlanKind as p, QuerySet as r, TableMetaFactory as s, query_exports as t, compiler_exports as u };
1654
1666
 
1655
- //# sourceMappingURL=query-hvcqTb9O.js.map
1667
+ //# sourceMappingURL=query-SyO9nqpp.js.map