@protobase/query 0.99.2 → 0.99.4

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.
@@ -2,7 +2,8 @@ import { QueryError } from "./fields/query-error.js";
2
2
  import { columnRef, requireField } from "./columns.js";
3
3
  import { baseQuery } from "./base-query.js";
4
4
  import { assertFilterRequirements } from "./filter-requirements.js";
5
- import { checkPerLimit, firstPerValue, ownerAlias, rankAlias } from "./related-rows.js";
5
+ import { rankAlias } from "./internal-aliases.js";
6
+ import { checkPerLimit, firstPerValue, ownerAlias } from "./related-rows.js";
6
7
  import { toNumber } from "./numbers.js";
7
8
  import { withStatementTimeout } from "./with-statement-timeout.js";
8
9
  import { measureSql, measureValue } from "./measure.js";
@@ -122,12 +122,12 @@ const uncoveredColumns = (model, table, query, scope) => {
122
122
  const groupField = query.groupBy !== void 0 ? model.fields[query.groupBy] : void 0;
123
123
  const perField = query.per !== void 0 ? model.fields[query.per] : void 0;
124
124
  return unique([
125
+ ...perField ? perNeed(ctx("per"), perField, sortField, pinned) : [],
125
126
  ...scope?.rowFilter ? walk(ctx("access", full), scope.rowFilter, pinned, false) : [],
126
127
  ...(scope?.parents ?? []).flatMap((read) => need(ctx(read.related ? "related" : "parent", full), read.field, "btree", pinned)),
127
128
  ...query.filter ? walk(ctx("filter"), query.filter, pinned, false) : [],
128
129
  ...scope?.within ? walk(ctx("filter", full), scope.within, pinned, false) : [],
129
130
  ...query.selects ? need(ctx("related", full), query.selects, "btree", pinned) : [],
130
- ...perField ? perNeed(ctx("per"), perField, sortField, pinned) : [],
131
131
  ...sortField && !perField ? need(ctx("sort"), sortField, "btree", pinned) : [],
132
132
  ...groupField ? need(ctx("facet"), groupField, "btree", pinned) : []
133
133
  ]);
@@ -0,0 +1,5 @@
1
+ //#region src/internal-aliases.ts
2
+ /** The alias of a row's place within its value in a per-value read, which `extraColumns` may not take. */
3
+ const rankAlias = "__pb_rank";
4
+ //#endregion
5
+ export { rankAlias };
@@ -6,6 +6,7 @@ import { seekCondition } from "./seek.js";
6
6
  import { baseQuery } from "./base-query.js";
7
7
  import { decodeCursor, encodeCursor } from "./cursor.js";
8
8
  import { assertFilterRequirements } from "./filter-requirements.js";
9
+ import "./internal-aliases.js";
9
10
  import { sql } from "kysely";
10
11
  //#region src/list-query.ts
11
12
  const maxLimit = 500;
@@ -18,7 +19,7 @@ const requestedFields = (model, columns) => (columns ?? Object.keys(model.fields
18
19
  /** The selections of `extraColumns`, refusing an alias that collides with a field or an internal column. */
19
20
  const extraSelections = (model, extras = []) => extras.map(({ field, as, alias }) => {
20
21
  if (as !== "text") throw new QueryError("invalid_option", "extraColumns only supports as: \"text\"");
21
- if (Object.hasOwn(model.fields, alias) || alias.startsWith("__pb_key")) throw new QueryError("invalid_option", `extra column alias "${alias}" collides with a field or internal column`);
22
+ if (Object.hasOwn(model.fields, alias) || alias.startsWith("__pb_key") || alias === "__pb_rank") throw new QueryError("invalid_option", `extra column alias "${alias}" collides with a field or internal column`);
22
23
  return sql`${columnRef(findField(model, field))}::text`.as(alias);
23
24
  });
24
25
  const selectPage = (db, model, query, scope, keys, cursorValues, options) => {
@@ -3,11 +3,11 @@ import { columnRef, findField } from "./columns.js";
3
3
  import { orderTerm } from "./order.js";
4
4
  import { effectiveSort } from "./sort.js";
5
5
  import { baseQuery } from "./base-query.js";
6
+ import { rankAlias } from "./internal-aliases.js";
6
7
  import "./list-query.js";
7
8
  import { sql } from "kysely";
8
9
  //#region src/related-rows.ts
9
10
  const ownerAlias = "__pb_owner";
10
- const rankAlias = "__pb_rank";
11
11
  /** Refuses a per-value limit outside a list's page sizes. */
12
12
  const checkPerLimit = (limit) => {
13
13
  if (!Number.isInteger(limit) || limit < 1 || limit > 500) throw new QueryError("invalid_limit", `limit must be a whole number from 1 to 500`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/query",
3
- "version": "0.99.2",
3
+ "version": "0.99.4",
4
4
  "description": "Kysely list, filter, count and aggregate queries over Protobase resources.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@protobase/schema": "0.99.2",
32
+ "@protobase/schema": "0.99.4",
33
33
  "kysely": "^0.29.6"
34
34
  }
35
35
  }