uql-orm 0.102.1 → 0.102.3

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.
Files changed (34) hide show
  1. package/dist/browser/uql-browser.min.js +2 -2
  2. package/dist/browser/uql-browser.min.js.map +2 -2
  3. package/dist/cockroachdb/cockroachDialect.d.ts +1 -1
  4. package/dist/cockroachdb/cockroachDialect.js +1 -1
  5. package/dist/dialect/abstractSqlDialect.d.ts +14 -13
  6. package/dist/dialect/abstractSqlDialect.js +33 -32
  7. package/dist/dialect/aliases.d.ts +5 -3
  8. package/dist/dialect/aliases.js +7 -3
  9. package/dist/dialect/jsonSql.d.ts +4 -0
  10. package/dist/dialect/jsonSql.js +9 -0
  11. package/dist/dialect/mysqlLikeSqlDialect.d.ts +2 -1
  12. package/dist/dialect/mysqlLikeSqlDialect.js +8 -3
  13. package/dist/dialect/pgLikeSqlDialect.d.ts +4 -3
  14. package/dist/dialect/pgLikeSqlDialect.js +10 -7
  15. package/dist/dialect/queryJoins.d.ts +1 -1
  16. package/dist/mariadb/mariaDialect.d.ts +2 -2
  17. package/dist/mariadb/mariaDialect.js +2 -2
  18. package/dist/mongodb/mongoDialect.d.ts +26 -20
  19. package/dist/mongodb/mongoDialect.js +178 -126
  20. package/dist/mssql/mssqlDialect.d.ts +8 -6
  21. package/dist/mssql/mssqlDialect.js +32 -20
  22. package/dist/sqlite/sqliteDialect.d.ts +1 -1
  23. package/dist/sqlite/sqliteDialect.js +3 -3
  24. package/dist/turso/tursoLocalDialect.d.ts +2 -2
  25. package/dist/turso/tursoLocalDialect.js +7 -5
  26. package/dist/type/entity.d.ts +25 -11
  27. package/dist/type/queryAggregate.d.ts +3 -6
  28. package/dist/type/utility.d.ts +2 -0
  29. package/dist/util/dialect.util.d.ts +13 -13
  30. package/dist/util/dialect.util.js +47 -13
  31. package/dist/util/object.util.d.ts +3 -3
  32. package/dist/util/object.util.js +1 -1
  33. package/package.json +3 -3
  34. package/skills/uql-orm/SKILL.md +1 -1
@@ -1,5 +1,5 @@
1
1
  import { type RelationRows, type SelectTerm } from '../dialect/abstractSqlDialect.js';
2
- import { type JsonAccessMode } from '../dialect/jsonSql.js';
2
+ import { type JsonAccessMode, type JsonSlot } from '../dialect/jsonSql.js';
3
3
  import { MysqlLikeSqlDialect } from '../dialect/mysqlLikeSqlDialect.js';
4
4
  import type { FieldOptions, Query, QueryContext, SqlDialectFeatures, SqlValues, Type, VectorDistance, VectorMetric } from '../type/index.js';
5
5
  export declare class MariaDialect extends MysqlLikeSqlDialect {
@@ -33,7 +33,7 @@ export declare class MariaDialect extends MysqlLikeSqlDialect {
33
33
  */
34
34
  protected jsonArrayOf(elem: string): string;
35
35
  /** Text-backed JSON compares as text, so `JSON_EQUALS` compares it as JSON, key order aside. */
36
- protected jsonDiffers(elem: string, operand: string): string;
36
+ protected jsonElemEquals(ctx: QueryContext, slot: JsonSlot, alias: string, value: unknown): string;
37
37
  /** `VEC_DISTANCE_COSINE`/`VEC_DISTANCE_EUCLIDEAN`, 11.7+, which the index's `DISTANCE=` names alike. */
38
38
  readonly vectorMetrics: ReadonlyMap<VectorDistance, VectorMetric>;
39
39
  /**
@@ -61,8 +61,8 @@ export class MariaDialect extends MysqlLikeSqlDialect {
61
61
  return super.jsonArrayOf(`JSON_COMPACT(${elem})`);
62
62
  }
63
63
  /** Text-backed JSON compares as text, so `JSON_EQUALS` compares it as JSON, key order aside. */
64
- jsonDiffers(elem, operand) {
65
- return `NOT JSON_EQUALS(${elem}, ${operand})`;
64
+ jsonElemEquals(ctx, slot, alias, value) {
65
+ return `JSON_EQUALS(${this.jsonElemValue(slot, alias, 'json')}, ${this.jsonScalarParam(ctx, value)})`;
66
66
  }
67
67
  /** `VEC_DISTANCE_COSINE`/`VEC_DISTANCE_EUCLIDEAN`, 11.7+, which the index's `DISTANCE=` names alike. */
68
68
  vectorMetrics = new Map([
@@ -24,10 +24,10 @@ type MongoReadStages = {
24
24
  readonly temporary?: boolean;
25
25
  };
26
26
  };
27
- /** Accumulator threaded through `$where` rendering: the relation lookups it needs, and their temp fields. */
28
- type RelationLookups = {
29
- readonly stages: MongoAggregationPipelineEntry<Document>[];
30
- readonly temps: string[];
27
+ /** Lookup stages, and the temp fields they fill, which the pipeline takes back out once read. */
28
+ type Lookup = {
29
+ stages: MongoAggregationPipelineEntry<Document>[];
30
+ temps: string[];
31
31
  };
32
32
  /** Default {@link DialectFeatures} for MongoDB. */
33
33
  export declare const mongoDialectFeatures: DialectFeatures;
@@ -45,27 +45,28 @@ export declare class MongoDialect extends AbstractDialect {
45
45
  /**
46
46
  * The stages every pipeline starts with: the `$lookup` each relation condition needs, into a temporary
47
47
  * field so `$or` keeps its meaning, the `$match` reading them, and the temporaries taken back out. Each
48
- * relation aggregate the `$where` or `named` reads is left on the document, once, under its column.
48
+ * relation aggregate the `$where` or `fields` reads is left on the document, once, under its column.
49
+ * `lookup` keeps the temporaries used, so a later lookup neither repeats nor reuses one.
49
50
  */
50
- matchStages<E extends Document>(entity: Type<E>, where?: QueryWhere<E>, opts?: QueryOptions, named?: readonly string[]): MongoAggregationPipelineEntry<Document>[];
51
+ matchStages<E extends Document>(entity: Type<E>, where?: QueryWhere<E>, opts?: QueryOptions, fields?: readonly string[], lookup?: Lookup): MongoAggregationPipelineEntry<Document>[];
51
52
  /**
52
53
  * Renders a `$where` tree without applying entity filters (used for same-scope group-operator
53
54
  * recursion). A relation, or a relation aggregate, needs `$lookup` stages, so it is only accepted
54
- * when `lookups` is given - a plain `find`/`updateMany` filter has nowhere to put them.
55
+ * when `lookup` is given - a plain `find`/`updateMany` filter has nowhere to put them.
55
56
  */
56
- protected renderFilter<E extends Document>(entity: Type<E>, where?: QueryWhere<E>, lookups?: RelationLookups): Filter<E>;
57
+ protected renderFilter<E extends Document>(entity: Type<E>, where?: QueryWhere<E>, lookup?: Lookup): Filter<E>;
57
58
  /**
58
59
  * Renders `$and`/`$or`/`$not`/`$nor` into `filter`, both negations as MongoDB's `$nor` (a `$not`'s clauses
59
60
  * wrapped in one `$and`), dropping empty clauses, since MongoDB refuses an empty operator.
60
61
  */
61
62
  private appendLogicalOperator;
62
63
  /**
63
- * Emits the correlated `$lookup` for one relation condition, and adds to `filter` the condition testing
64
- * its result: presence of a row for a plain relation filter, a comparison against the row count for
65
- * `$size`. The target's (and, for ManyToMany, the junction's) own filters scope the lookup, so a
66
- * relation subquery can no more read out-of-scope rows than a direct query on the target can.
64
+ * One relation condition as an expression over the correlated `$lookup` it adds to `lookup`: a row exists
65
+ * for a plain filter, the row count compared for a `$size`. The target's (and, for ManyToMany, the
66
+ * junction's) own filters scope the lookup, so a relation subquery can no more read out-of-scope rows
67
+ * than a direct query on the target can.
67
68
  */
68
- private appendRelationLookup;
69
+ private relationExpression;
69
70
  /**
70
71
  * The correlated `$lookup` for the target rows of one relation `where` narrows, as `temp`: straight at
71
72
  * the target, or for a many-to-many from inside its junction's rows. The caller's filter bypass is not
@@ -113,15 +114,17 @@ export declare class MongoDialect extends AbstractDialect {
113
114
  * by ahead of the value itself.
114
115
  */
115
116
  sortPlan<E extends Document>(entity: Type<E>, { $sort: sort, $populate: populate, $where: where }: Query<E>): MongoSortPlan;
116
- /** Walks `$sort` against the metadata of the entity each level addresses, as the SQL dialects do. */
117
+ /**
118
+ * Walks `$sort` against the metadata of the entity each level addresses, as the SQL dialects do. `at` is where the
119
+ * level is: the relations walked to it (`path`, ending in a dot), and the join its rows came from, if any.
120
+ */
117
121
  private collectSort;
118
122
  /**
119
123
  * The stages a `$sort` by a relation's aggregate needs - its size, or its row nearest a vector: one
120
124
  * correlated `$lookup` reading it per parent, and the `$set` that lifts it onto the document as the
121
125
  * field the `$sort` then orders by. A parent with no related row reads a zero tally and no distance.
122
126
  */
123
- sortAggregateStages<E extends Document>(entity: Type<E>, sort: QuerySortMap<E> | undefined): {
124
- readonly stages: MongoAggregationPipelineEntry<Document>[];
127
+ sortAggregateStages<E extends Document>(entity: Type<E>, sort: QuerySortMap<E> | undefined): Lookup & {
125
128
  readonly fields: string[];
126
129
  };
127
130
  /** Whether a read answers with a relation aggregate, which only the pipeline can build. */
@@ -206,6 +209,8 @@ export declare class MongoDialect extends AbstractDialect {
206
209
  private joinKeys;
207
210
  /** `[column, key]` for the fields whose stored name differs from their property name, memoized per entity. */
208
211
  private renamedColumns;
212
+ /** Each relation's key, the field its rows are read from, and its entity, memoized per entity for `normalizeId`. */
213
+ private relationReads;
209
214
  private referenceKeys;
210
215
  normalizeIds<E extends Document>(meta: EntityMeta<E>, docs: Document[]): E[];
211
216
  /** `doc` is the wire shape - `_id`, stored names, `ObjectId`s - and what comes back is the code's. */
@@ -240,16 +245,17 @@ export declare class MongoDialect extends AbstractDialect {
240
245
  /**
241
246
  * Resolve parsed group entries into the `_id` keys and accumulators of a `$group` stage, and the
242
247
  * `columns` its `$project` reads each result from: a group key out of `_id`, a DISTINCT set by its
243
- * size, and a `$sum` as null where it read no value, as SQL answers it. `named` is every field it reads,
244
- * filters included, so each relation aggregate among them is put on the document first.
248
+ * size, and a `$sum` as null where it read no value, as SQL answers it. `lookups` puts on each matched
249
+ * row what the group reads through one: a relation aggregate, and an aggregate's relation condition,
250
+ * past the `matched` temporaries, whose relation aggregates are on the row already.
245
251
  */
246
252
  private buildGroupSpec;
247
253
  /** The field a grouped path reads, on the document or on the joined one its lookup unwound. */
248
254
  private groupedPath;
249
255
  /**
250
256
  * An aggregate's own `$where` as the expression a `$cond` tests, which a query filter is not: the
251
- * comparisons and the logical operators translate, anything else is refused by name. `named` gathers
252
- * the fields it reads, so a relation aggregate among them is on the document first.
257
+ * comparisons, the logical operators and relations translate, anything else is refused by name. `lookup`
258
+ * gathers the lookups it tests: a relation condition's, and a relation aggregate's it compares.
253
259
  */
254
260
  private whereExpression;
255
261
  /** One field's condition as an expression: a value it equals, a list it is in, or a map of comparisons. */