@danceroutine/tango-orm 1.11.9 → 1.11.10

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.
@@ -77,6 +77,7 @@ declare class QueryCompiler {
77
77
  constructor(meta: TableMeta, adapter: Adapter);
78
78
  static isQueryCompiler(value: unknown): value is QueryCompiler;
79
79
  compile<T, TSourceModel = unknown>(state: QuerySetState<T, TSourceModel>): CompiledQuery;
80
+ compileExists<T, TSourceModel = unknown>(state: QuerySetState<T, TSourceModel>): CompiledQuery;
80
81
  compilePrefetch(node: CompiledHydrationNode, sourceValues: readonly (string | number)[]): CompiledPrefetchQuery;
81
82
  compileManyToManyTargets(node: CompiledHydrationNode, targetIds: readonly (string | number)[]): {
82
83
  sql: string;
@@ -1307,4 +1308,4 @@ interface QuerySetState<T, TSourceModel = unknown> {
1307
1308
  }
1308
1309
  //#endregion
1309
1310
  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 };
1310
- //# sourceMappingURL=QuerySetState-CjyvAUBs.d.ts.map
1311
+ //# sourceMappingURL=QuerySetState-DRL9-rKQ.d.ts.map
@@ -1,4 +1,4 @@
1
- import { a as MaterializedModelRecord, n as ModelManager, r as TangoRuntime, t as registerModelObjects } from "./registerModelObjects-C-MliIiM.js";
1
+ import { a as MaterializedModelRecord, n as ModelManager, r as TangoRuntime, t as registerModelObjects } from "./registerModelObjects-CEqCRlVY.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-rjKca3U_.d.ts.map
31
+ //# sourceMappingURL=index-CCvYeJt4.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-CjyvAUBs.js";
2
- import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, t as registerModelObjects } from "./registerModelObjects-C-MliIiM.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-DRL9-rKQ.js";
2
+ import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, t as registerModelObjects } from "./registerModelObjects-CEqCRlVY.js";
3
3
 
4
4
  //#region src/manager/relations/ManyToManyRelatedQuerySet.d.ts
5
5
  /**
@@ -55,6 +55,7 @@ declare class ManyToManyRelatedQuerySet<TTarget extends Record<string, unknown>>
55
55
  fetch<Out>(shape?: ShapeFunction<TTarget, Out> | ShapeParser<TTarget, Out>): Promise<QueryResult<TTarget | Out>>;
56
56
  fetchOne<Out>(shape?: ShapeFunction<TTarget, Out> | ShapeParser<TTarget, Out>): Promise<TTarget | Out | null>;
57
57
  count(): Promise<number>;
58
+ exists(): Promise<boolean>;
58
59
  protected spawn<TNextBaseResult extends Record<string, unknown>, TNextHydrated extends Record<string, unknown>>(state: QuerySetState<TTarget>): QuerySet<TTarget, TNextBaseResult, unknown, TNextHydrated>;
59
60
  private isStateTrivial;
60
61
  private scopedState;
@@ -67,4 +68,4 @@ declare namespace index_d_exports {
67
68
  }
68
69
  //#endregion
69
70
  export { ManyToManyRelatedQuerySetBridge as i, index_d_exports$1 as n, ManyToManyRelatedQuerySet as r, index_d_exports as t };
70
- //# sourceMappingURL=index-D9B6gKez.d.ts.map
71
+ //# sourceMappingURL=index-CJlkeldS.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-CjyvAUBs.js";
5
- import { t as index_d_exports$1 } from "./index-D9B6gKez.js";
6
- import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, r as TangoRuntime } from "./registerModelObjects-C-MliIiM.js";
7
- import { i as resetTangoRuntime, n as getTangoRuntime, r as initializeTangoRuntime, t as index_d_exports$3 } from "./index-rjKca3U_.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-DRL9-rKQ.js";
5
+ import { t as index_d_exports$1 } from "./index-CJlkeldS.js";
6
+ import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, r as TangoRuntime } from "./registerModelObjects-CEqCRlVY.js";
7
+ import { i as resetTangoRuntime, n as getTangoRuntime, r as initializeTangoRuntime, t as index_d_exports$3 } from "./index-CCvYeJt4.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-CP1UMIX6.js";
4
- import { n as ModelManager, r as ManyToManyRelatedManager } from "./registerModelObjects-CGjjOzd9.js";
5
- import { t as manager_exports } from "./manager-DRra01q8.js";
3
+ import { d as QueryCompiler, i as QBuilder, l as QueryResult, n as ModelQuerySet, r as QuerySet, t as query_exports } from "./query-B-ooqvSG.js";
4
+ import { n as ModelManager, r as ManyToManyRelatedManager } from "./registerModelObjects-BKGs2c_m.js";
5
+ import { t as manager_exports } from "./manager-GMmYq4lC.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-CjyvAUBs.js";
2
- import { i as ManyToManyRelatedQuerySetBridge, n as index_d_exports, r as ManyToManyRelatedQuerySet } from "../index-D9B6gKez.js";
3
- import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, t as registerModelObjects } from "../registerModelObjects-C-MliIiM.js";
1
+ import { D as ManyToManyRelatedManagerCreateInputs, E as ManyToManyRelatedManager, O as ManyToManyTargetRef } from "../QuerySetState-DRL9-rKQ.js";
2
+ import { i as ManyToManyRelatedQuerySetBridge, n as index_d_exports, r as ManyToManyRelatedQuerySet } from "../index-CJlkeldS.js";
3
+ import { a as MaterializedModelRecord, i as ManagerLike, n as ModelManager, t as registerModelObjects } from "../registerModelObjects-CEqCRlVY.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-CGjjOzd9.js";
2
- import { n as relations_exports } from "../manager-DRra01q8.js";
1
+ import { i as ManyToManyRelatedQuerySet, n as ModelManager, r as ManyToManyRelatedManager, t as registerModelObjects } from "../registerModelObjects-BKGs2c_m.js";
2
+ import { n as relations_exports } from "../manager-GMmYq4lC.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-CGjjOzd9.js";
2
+ import { i as ManyToManyRelatedQuerySet, n as ModelManager, r as ManyToManyRelatedManager, t as registerModelObjects } from "./registerModelObjects-BKGs2c_m.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-DRra01q8.js.map
20
+ //# sourceMappingURL=manager-GMmYq4lC.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"manager-DRra01q8.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-GMmYq4lC.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-CjyvAUBs.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-DRL9-rKQ.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-CP1UMIX6.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-B-ooqvSG.js";
2
2
  export { ModelQuerySet, QBuilder as Q, QBuilder, QueryCompiler, QueryResult, QuerySet, compiler_exports as compiler, domain_exports as domain };
@@ -476,6 +476,40 @@ var QueryCompiler = class QueryCompiler {
476
476
  } : void 0
477
477
  };
478
478
  }
479
+ compileExists(state) {
480
+ const validatedPlan = sqlSafetyAdapter.validate({
481
+ kind: InternalSqlValidationPlanKind.SELECT,
482
+ meta: this.meta,
483
+ selectFields: state.select?.map(String),
484
+ filterKeys: this.collectStateFilterKeys(state),
485
+ orderFields: state.order?.map((order) => String(order.by)),
486
+ relationNames: []
487
+ });
488
+ const table = validatedPlan.meta.table;
489
+ const whereParts = [];
490
+ const params = [];
491
+ if (state.q) {
492
+ const result = this.compileQNode(state.q, params.length + 1, validatedPlan.filterKeys);
493
+ if (result.sql) {
494
+ whereParts.push(result.sql);
495
+ params.push(...result.params);
496
+ }
497
+ }
498
+ state.excludes?.forEach((exclude) => {
499
+ const result = this.compileQNode({
500
+ kind: InternalQNodeType.NOT,
501
+ node: exclude
502
+ }, params.length + 1, validatedPlan.filterKeys);
503
+ if (result.sql) {
504
+ whereParts.push(result.sql);
505
+ params.push(...result.params);
506
+ }
507
+ });
508
+ return {
509
+ sql: `SELECT 1 AS tango_exists FROM ${table}${whereParts.length ? ` WHERE ${whereParts.join(" AND ")}` : ""} LIMIT 1${state.offset ? ` OFFSET ${state.offset}` : ""}`,
510
+ params
511
+ };
512
+ }
479
513
  compilePrefetch(node, sourceValues) {
480
514
  if (node.throughTable && node.throughSourceKey && node.throughTargetKey) return this.compileManyToManyPrefetch(node, sourceValues);
481
515
  const placeholders = this.placeholders.list(sourceValues.length);
@@ -1293,7 +1327,8 @@ var QuerySet = class QuerySet {
1293
1327
  * Return whether at least one row matches the current query state.
1294
1328
  */
1295
1329
  async exists() {
1296
- return await this.count() > 0;
1330
+ const compiled = new QueryCompiler(this.executor.meta, this.executor.adapter).compileExists(this.withoutHydrationState());
1331
+ return (await this.executor.client.query(compiled.sql, compiled.params)).rows.length > 0;
1297
1332
  }
1298
1333
  shapeFetchedRow(row, shape) {
1299
1334
  if (!shape) return row;
@@ -1555,4 +1590,4 @@ var query_exports = /* @__PURE__ */ __exportAll({
1555
1590
  //#endregion
1556
1591
  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 };
1557
1592
 
1558
- //# sourceMappingURL=query-CP1UMIX6.js.map
1593
+ //# sourceMappingURL=query-B-ooqvSG.js.map