@rebasepro/types 0.29.0-canary.g0e3a0e7 → 0.29.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/dist/controllers/aggregates.d.ts +26 -0
- package/dist/controllers/data.d.ts +76 -11
- package/dist/controllers/data_driver.d.ts +34 -9
- package/dist/controllers/index.d.ts +1 -0
- package/dist/index.es.js +87 -3
- package/dist/index.es.js.map +1 -1
- package/dist/types/collections.d.ts +43 -0
- package/dist/types/filter-operators.d.ts +4 -2
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AggregateGroup, AggregateGroupTransform, AggregateSelect } from "./data.js";
|
|
2
|
+
import type { DriverAggregate, DriverAggregateGroup } from "./data_driver.js";
|
|
3
|
+
/** Every aggregate function, by its SDK name: what `?select=` accepts too. */
|
|
4
|
+
export declare const AGGREGATE_FUNCTIONS: readonly DriverAggregate["fn"][];
|
|
5
|
+
/** The functions that take no field. */
|
|
6
|
+
export declare const FIELDLESS_AGGREGATES: ReadonlySet<DriverAggregate["fn"]>;
|
|
7
|
+
/** Every `groupBy` transform. */
|
|
8
|
+
export declare const AGGREGATE_GROUP_TRANSFORMS: readonly AggregateGroupTransform[];
|
|
9
|
+
/**
|
|
10
|
+
* The key an aggregate comes back under.
|
|
11
|
+
*
|
|
12
|
+
* `sum(total)` → `sum_total`, `count()` → `count`, `countDistinct(sid)` →
|
|
13
|
+
* `count_distinct_sid`, `percentile(fame, 0.95)` → `p95_fame`. One function,
|
|
14
|
+
* because the SDK, the REST parser and the HTTP client all derive it and have
|
|
15
|
+
* to agree — a caller reading `row.sum_total` off an SDK result and off an HTTP
|
|
16
|
+
* response is reading the same key or the SDK is broken.
|
|
17
|
+
*/
|
|
18
|
+
export declare function aggregateAlias(fn: string, field?: string, p?: number): string;
|
|
19
|
+
/** `percentile`'s `p`, refused unless it is a fraction a key can name (0–1, at most three decimals). */
|
|
20
|
+
export declare function isPercentileFraction(p: unknown): p is number;
|
|
21
|
+
/** An `AggregateSelect` as a driver is handed it. */
|
|
22
|
+
export declare function toDriverAggregate(select: AggregateSelect<Record<string, unknown>>): DriverAggregate;
|
|
23
|
+
/** The key a group comes back under: the column's name, or `<transform>_<field>`. */
|
|
24
|
+
export declare function aggregateGroupKey(group: string | AggregateGroup | DriverAggregateGroup): string;
|
|
25
|
+
/** A `groupBy` entry as a driver is handed it. */
|
|
26
|
+
export declare function toDriverAggregateGroup(group: string | AggregateGroup): string | DriverAggregateGroup;
|
|
@@ -42,8 +42,9 @@ export type WhereElementOf<T> = ElementOf<T> | IdOf<ElementOf<T>>;
|
|
|
42
42
|
* The branches mirror `buildSingleFilterCondition` in `@rebasepro/server-postgres`:
|
|
43
43
|
*
|
|
44
44
|
* - `array-contains` → one element of the column (or a related row's id).
|
|
45
|
-
* - `in` / `not-in` / `array-contains-any`
|
|
46
|
-
*
|
|
45
|
+
* - `in` / `not-in` / `array-contains-any` / `array-contains-all` /
|
|
46
|
+
* `array-contained-by` → a list of elements; a bare element is read as the
|
|
47
|
+
* one-element list, and `null` is a null check.
|
|
47
48
|
* - `like` / `ilike` / `not-like` / `not-ilike` → a SQL pattern, always a
|
|
48
49
|
* string. It matches a text column, or an enum by its label; on a number,
|
|
49
50
|
* a date or any other column the Postgres driver refuses it with a 400
|
|
@@ -55,7 +56,7 @@ export type WhereElementOf<T> = ElementOf<T> | IdOf<ElementOf<T>>;
|
|
|
55
56
|
* (a dynamic filter UI, say) gets the union of every branch and stays as
|
|
56
57
|
* permissive as it was.
|
|
57
58
|
*/
|
|
58
|
-
export type WhereValueFor<Op extends WhereFilterOp, T> = Op extends "array-contains" ? WhereElementOf<T> : Op extends "in" | "not-in" | "array-contains-any" ? readonly WhereElementOf<T>[] | WhereElementOf<T> | null : Op extends "like" | "ilike" | "not-like" | "not-ilike" ? string : Op extends "is-null" | "is-not-null" ? null | undefined : T | null;
|
|
59
|
+
export type WhereValueFor<Op extends WhereFilterOp, T> = Op extends "array-contains" ? WhereElementOf<T> : Op extends "in" | "not-in" | "array-contains-any" | "array-contains-all" | "array-contained-by" ? readonly WhereElementOf<T>[] | WhereElementOf<T> | null : Op extends "like" | "ilike" | "not-like" | "not-ilike" ? string : Op extends "is-null" | "is-not-null" ? null | undefined : T | null;
|
|
59
60
|
/**
|
|
60
61
|
* One `[operator, value]` condition on a column of type `T`, with the value
|
|
61
62
|
* typed for the operator exactly as the fluent `where(column, op, value)` types
|
|
@@ -657,6 +658,8 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
|
|
|
657
658
|
* number nothing counted.
|
|
658
659
|
*/
|
|
659
660
|
aggregate?(params: AggregateParams<M>): Promise<AggregateResult>;
|
|
661
|
+
/** {@link SDKCollectionClient.refresh}. Optional, as `aggregate` is. */
|
|
662
|
+
refresh?(options?: RefreshOptions): Promise<void>;
|
|
660
663
|
where<K extends keyof M & string, Op extends WhereFilterOp>(column: K, operator: Op, value: WhereValueFor<Op, M[K]>): QueryBuilderInterface<M>;
|
|
661
664
|
where(logicalCondition: LogicalConditionFor<M>): QueryBuilderInterface<M>;
|
|
662
665
|
orderBy(column: (keyof M & string) | ComputedSortField, direction?: "asc" | "desc"): QueryBuilderInterface<M>;
|
|
@@ -774,10 +777,25 @@ export type QueryComputedFields = {
|
|
|
774
777
|
* `count` alone counts rows; every other function names a column, and `count`
|
|
775
778
|
* with a column counts its non-NULL values.
|
|
776
779
|
*
|
|
780
|
+
* - `countDistinct` counts the distinct non-NULL values of a column.
|
|
781
|
+
* - `mode` is the most frequent value (ties go to the first in sort order).
|
|
782
|
+
* - `percentile` is the continuous percentile `p` (0–1) of a number column:
|
|
783
|
+
* `p: 0.5` is the median.
|
|
784
|
+
* - `distinct` is the column's distinct non-NULL values, sorted, as an array —
|
|
785
|
+
* for an array column, the distinct arrays; group by `unnest` for the
|
|
786
|
+
* distinct elements.
|
|
787
|
+
* - `fingerprint` is a short string that changes whenever a row it covers is
|
|
788
|
+
* inserted, updated or deleted: compare it with the last one you saw to
|
|
789
|
+
* know whether anything changed, without reading the rows. It may also
|
|
790
|
+
* change when nothing did (a write that set a column to its own value), never
|
|
791
|
+
* the other way round.
|
|
792
|
+
*
|
|
777
793
|
* The result key is derived rather than chosen: `sum(total)` comes back as
|
|
778
|
-
* `sum_total
|
|
779
|
-
*
|
|
780
|
-
*
|
|
794
|
+
* `sum_total`, a bare `count()` as `count`, `countDistinct(sid)` as
|
|
795
|
+
* `count_distinct_sid` and `percentile(fame, 0.95)` as `p95_fame` (see
|
|
796
|
+
* {@link AggregateAlias}). Letting a caller name it would mean checking their
|
|
797
|
+
* name is not also a `groupBy` field — a rule nobody would guess, and a
|
|
798
|
+
* silently overwritten value if it went unchecked.
|
|
781
799
|
*
|
|
782
800
|
* @group Data
|
|
783
801
|
*/
|
|
@@ -788,9 +806,33 @@ export type AggregateSelect<M extends Record<string, unknown> = Record<string, u
|
|
|
788
806
|
fn: "sum" | "avg";
|
|
789
807
|
field: NumericKeyOf<M>;
|
|
790
808
|
} | {
|
|
791
|
-
fn: "min" | "max";
|
|
809
|
+
fn: "min" | "max" | "countDistinct" | "mode" | "distinct";
|
|
792
810
|
field: Extract<keyof M, string>;
|
|
811
|
+
} | {
|
|
812
|
+
fn: "percentile";
|
|
813
|
+
field: NumericKeyOf<M>;
|
|
814
|
+
p: number;
|
|
815
|
+
} | {
|
|
816
|
+
fn: "fingerprint";
|
|
817
|
+
};
|
|
818
|
+
/**
|
|
819
|
+
* A transformed column to group by, where a plain column will not do:
|
|
820
|
+
* `lower`/`upper` of a text column, the `year`/`month`/`day` of a date (in
|
|
821
|
+
* UTC, served as `"2026"`, `"2026-11"`, `"2026-11-08"`), or `unnest` — one
|
|
822
|
+
* group per element of an array column, so `count()` beside it counts the rows
|
|
823
|
+
* holding each element.
|
|
824
|
+
*
|
|
825
|
+
* Its key in each row is `<transform>_<field>` (`lower_artist`,
|
|
826
|
+
* `unnest_tags`), which is also how `orderBy` names it.
|
|
827
|
+
*
|
|
828
|
+
* @group Data
|
|
829
|
+
*/
|
|
830
|
+
export type AggregateGroup<Field extends string = string> = {
|
|
831
|
+
field: Field;
|
|
832
|
+
transform: AggregateGroupTransform;
|
|
793
833
|
};
|
|
834
|
+
/** What an {@link AggregateGroup} does to its column. @group Data */
|
|
835
|
+
export type AggregateGroupTransform = "lower" | "upper" | "unnest" | "year" | "month" | "day";
|
|
794
836
|
/**
|
|
795
837
|
* The columns of `M` that hold numbers — what `sum` and `avg` can add up. Any
|
|
796
838
|
* column used to be accepted, and `sum` of a text column was a 400. An untyped
|
|
@@ -835,8 +877,12 @@ export type AggregateRow = Record<string, unknown>;
|
|
|
835
877
|
export interface AggregateParams<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
836
878
|
/** The aggregates to compute. At least one. */
|
|
837
879
|
select: AggregateSelect<M>[];
|
|
838
|
-
/**
|
|
839
|
-
|
|
880
|
+
/**
|
|
881
|
+
* Columns to group by — or a column transformed ({@link AggregateGroup}),
|
|
882
|
+
* e.g. `{ field: "artist", transform: "lower" }`. Omit for a single row
|
|
883
|
+
* over everything that matches.
|
|
884
|
+
*/
|
|
885
|
+
groupBy?: (Extract<keyof M, string> | AggregateGroup<Extract<keyof M, string>>)[];
|
|
840
886
|
/** Filter conditions, as {@link FindParams.where}. */
|
|
841
887
|
where?: WhereFor<M>;
|
|
842
888
|
/** An `and`/`or`/`not` group, AND-ed with `where`. */
|
|
@@ -866,20 +912,25 @@ export interface AggregateParams<M extends Record<string, unknown> = Record<stri
|
|
|
866
912
|
*/
|
|
867
913
|
orderBy?: OrderByTuple<AggregateOrderKey<M>> | OrderByTuple<AggregateOrderKey<M>>[];
|
|
868
914
|
}
|
|
915
|
+
/** What `refresh()` takes. @group Data */
|
|
916
|
+
export interface RefreshOptions {
|
|
917
|
+
/** Keep serving the old rows while the new ones are computed (`REFRESH … CONCURRENTLY`). */
|
|
918
|
+
concurrently?: boolean;
|
|
919
|
+
}
|
|
869
920
|
/**
|
|
870
921
|
* The key an {@link AggregateSelect} comes back under: `count` for `count()`,
|
|
871
922
|
* `<fn>_<field>` otherwise (`sum_total`, `max_created_at`).
|
|
872
923
|
*
|
|
873
924
|
* @group Data
|
|
874
925
|
*/
|
|
875
|
-
export type AggregateAlias<M extends Record<string, unknown> = Record<string, unknown>> = "count" | `${"count" | "min" | "max"}_${Extract<keyof M, string>}` | `${"sum" | "avg"}_${NumericKeyOf<M>}`;
|
|
926
|
+
export type AggregateAlias<M extends Record<string, unknown> = Record<string, unknown>> = "count" | "fingerprint" | `${"count" | "min" | "max" | "count_distinct" | "mode" | "distinct"}_${Extract<keyof M, string>}` | `${"sum" | "avg"}_${NumericKeyOf<M>}` | `p${number}_${NumericKeyOf<M>}`;
|
|
876
927
|
/**
|
|
877
928
|
* What {@link AggregateParams.orderBy} can sort the groups by: a column (to
|
|
878
929
|
* group by) or an aggregate's alias.
|
|
879
930
|
*
|
|
880
931
|
* @group Data
|
|
881
932
|
*/
|
|
882
|
-
export type AggregateOrderKey<M extends Record<string, unknown> = Record<string, unknown>> = Extract<keyof M, string> | AggregateAlias<M>;
|
|
933
|
+
export type AggregateOrderKey<M extends Record<string, unknown> = Record<string, unknown>> = Extract<keyof M, string> | `${AggregateGroupTransform}_${Extract<keyof M, string>}` | AggregateAlias<M>;
|
|
883
934
|
/**
|
|
884
935
|
* Where a grouped aggregate's page of groups sits: the `limit` it was cut at,
|
|
885
936
|
* the `offset` it started from, and whether more groups follow.
|
|
@@ -1824,6 +1875,20 @@ Inc = IncludeSpec> {
|
|
|
1824
1875
|
* as "nothing matched".
|
|
1825
1876
|
*/
|
|
1826
1877
|
aggregate(params: AggregateParams<M>): Promise<AggregateResult>;
|
|
1878
|
+
/**
|
|
1879
|
+
* Recompute a materialized view's rows from its query (`view:
|
|
1880
|
+
* { materialized: true }`), as `REFRESH MATERIALIZED VIEW` does.
|
|
1881
|
+
*
|
|
1882
|
+
* For a caller holding one of the view's `roles` (`dataAsAdmin` does);
|
|
1883
|
+
* refused for anyone else and for a collection that is not a materialized
|
|
1884
|
+
* view. With `concurrently`, reads go on being served the old rows while
|
|
1885
|
+
* the new ones are computed — slower, and never a blocked read.
|
|
1886
|
+
*
|
|
1887
|
+
* ```ts
|
|
1888
|
+
* await rebase.dataAsAdmin.artist_stats.refresh({ concurrently: true });
|
|
1889
|
+
* ```
|
|
1890
|
+
*/
|
|
1891
|
+
refresh(options?: RefreshOptions): Promise<void>;
|
|
1827
1892
|
where<K extends keyof M & string, Op extends WhereFilterOp>(column: K, operator: Op, value: WhereValueFor<Op, M[K]>): SDKQueryBuilderInterface<M, Inc>;
|
|
1828
1893
|
/** A relation path (`author.name`) or a JSON path (`metadata->>tier`). */
|
|
1829
1894
|
where(column: NonColumnFieldPath, operator: WhereFilterOp, value: unknown): SDKQueryBuilderInterface<M, Inc>;
|
|
@@ -3,7 +3,7 @@ import type { EntityStatus, EntityValues } from "../types/entities.js";
|
|
|
3
3
|
import type { CollectionConfig, FilterValues } from "../types/collections.js";
|
|
4
4
|
import type { OrderByTuple } from "../types/filter-operators.js";
|
|
5
5
|
import type { RebaseCallContext } from "../call_context.js";
|
|
6
|
-
import type { IncludeSpec, LogicalCondition } from "./data.js";
|
|
6
|
+
import type { AggregateGroupTransform, IncludeSpec, LogicalCondition } from "./data.js";
|
|
7
7
|
import type { CollectionUpdateMeta } from "../types/websockets.js";
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
@@ -500,6 +500,14 @@ export interface DataDriver {
|
|
|
500
500
|
* a caller reaches for a batch to get.
|
|
501
501
|
*/
|
|
502
502
|
updateMany?<M extends Record<string, unknown> = Record<string, unknown>>(props: UpdateManyProps<M>): Promise<Record<string, unknown>[]>;
|
|
503
|
+
/**
|
|
504
|
+
* Recompute the rows of a collection that serves a materialized view —
|
|
505
|
+
* see `SDKCollectionClient.refresh`. Optional: only a driver with views
|
|
506
|
+
* has one.
|
|
507
|
+
*/
|
|
508
|
+
refreshView?(path: string, options?: {
|
|
509
|
+
concurrently?: boolean;
|
|
510
|
+
}): Promise<void>;
|
|
503
511
|
/**
|
|
504
512
|
* Delete the row `props.row` addresses.
|
|
505
513
|
*
|
|
@@ -687,6 +695,25 @@ export interface DataDriver {
|
|
|
687
695
|
*/
|
|
688
696
|
admin?: import("../types/backend.js").DatabaseAdmin;
|
|
689
697
|
}
|
|
698
|
+
/**
|
|
699
|
+
* One aggregate as a driver is handed it: an `AggregateSelect` with its
|
|
700
|
+
* derived `alias` (the key it comes back under).
|
|
701
|
+
*/
|
|
702
|
+
export interface DriverAggregate {
|
|
703
|
+
fn: "count" | "sum" | "avg" | "min" | "max" | "countDistinct" | "mode" | "percentile" | "distinct" | "fingerprint";
|
|
704
|
+
/** Absent for `count()` and `fingerprint()`. */
|
|
705
|
+
field?: string;
|
|
706
|
+
/** `percentile`'s fraction, 0–1. */
|
|
707
|
+
p?: number;
|
|
708
|
+
alias: string;
|
|
709
|
+
}
|
|
710
|
+
/** A transformed group (`AggregateGroup`) as a driver is handed it, with the key it comes back under. */
|
|
711
|
+
export interface DriverAggregateGroup {
|
|
712
|
+
field: string;
|
|
713
|
+
transform: AggregateGroupTransform;
|
|
714
|
+
/** `<transform>_<field>`. */
|
|
715
|
+
key: string;
|
|
716
|
+
}
|
|
690
717
|
/**
|
|
691
718
|
* REST-optimised fetch service exposed by drivers that support
|
|
692
719
|
* eager-loading of relations via `include`.
|
|
@@ -750,8 +777,10 @@ export interface RestFetchService {
|
|
|
750
777
|
*/
|
|
751
778
|
cursorFor?(collectionPath: string, row: Record<string, unknown>, orderBy?: OrderByTuple[]): string | undefined;
|
|
752
779
|
/**
|
|
753
|
-
* `
|
|
754
|
-
*
|
|
780
|
+
* The aggregates of `AggregateSelect` (`count`, `sum`, `avg`, `min`,
|
|
781
|
+
* `max`, `countDistinct`, `mode`, `percentile`, `distinct`, `fingerprint`)
|
|
782
|
+
* over the rows a filter selects, optionally grouped by columns or by
|
|
783
|
+
* transformed columns (`AggregateGroup`).
|
|
755
784
|
*
|
|
756
785
|
* Optional, and the REST route answers 501 where a driver does not
|
|
757
786
|
* implement it — an aggregate is not a thing to approximate, and an empty
|
|
@@ -768,12 +797,8 @@ export interface RestFetchService {
|
|
|
768
797
|
* `groupBy` is served; anything else is refused with a 400.
|
|
769
798
|
*/
|
|
770
799
|
aggregate?(collectionPath: string, options: {
|
|
771
|
-
aggregates:
|
|
772
|
-
|
|
773
|
-
field?: string;
|
|
774
|
-
alias: string;
|
|
775
|
-
}[];
|
|
776
|
-
groupBy?: string[];
|
|
800
|
+
aggregates: DriverAggregate[];
|
|
801
|
+
groupBy?: (string | DriverAggregateGroup)[];
|
|
777
802
|
filter?: FilterValues<string>;
|
|
778
803
|
logical?: LogicalCondition;
|
|
779
804
|
searchString?: string;
|
package/dist/index.es.js
CHANGED
|
@@ -298,6 +298,8 @@ var CANONICAL_TO_REST = {
|
|
|
298
298
|
"not-in": "nin",
|
|
299
299
|
"array-contains": "cs",
|
|
300
300
|
"array-contains-any": "csa",
|
|
301
|
+
"array-contains-all": "csall",
|
|
302
|
+
"array-contained-by": "cd",
|
|
301
303
|
"like": "like",
|
|
302
304
|
"ilike": "ilike",
|
|
303
305
|
"not-like": "nlike",
|
|
@@ -317,6 +319,8 @@ var REST_TO_CANONICAL = {
|
|
|
317
319
|
"nin": "not-in",
|
|
318
320
|
"cs": "array-contains",
|
|
319
321
|
"csa": "array-contains-any",
|
|
322
|
+
"csall": "array-contains-all",
|
|
323
|
+
"cd": "array-contained-by",
|
|
320
324
|
"like": "like",
|
|
321
325
|
"ilike": "ilike",
|
|
322
326
|
"nlike": "not-like",
|
|
@@ -342,7 +346,9 @@ var NULL_OPS = /* @__PURE__ */ new Set(["is-null", "is-not-null"]);
|
|
|
342
346
|
var LIST_OPS = /* @__PURE__ */ new Set([
|
|
343
347
|
"in",
|
|
344
348
|
"not-in",
|
|
345
|
-
"array-contains-any"
|
|
349
|
+
"array-contains-any",
|
|
350
|
+
"array-contains-all",
|
|
351
|
+
"array-contained-by"
|
|
346
352
|
]);
|
|
347
353
|
/**
|
|
348
354
|
* Every canonical operator, in a stable order. Useful for engine capability
|
|
@@ -361,6 +367,8 @@ var ALL_WHERE_FILTER_OPS = [
|
|
|
361
367
|
"not-in",
|
|
362
368
|
"array-contains",
|
|
363
369
|
"array-contains-any",
|
|
370
|
+
"array-contains-all",
|
|
371
|
+
"array-contained-by",
|
|
364
372
|
"like",
|
|
365
373
|
"ilike",
|
|
366
374
|
"not-like",
|
|
@@ -651,7 +659,7 @@ var FIREBASE_CAPABILITIES = {
|
|
|
651
659
|
supportsColumnTypes: false,
|
|
652
660
|
supportsRealtime: true,
|
|
653
661
|
supportsVectors: false,
|
|
654
|
-
filterOperators: ALL_WHERE_FILTER_OPS.filter((op) => op !== "like" && op !== "ilike" && op !== "not-like" && op !== "not-ilike"),
|
|
662
|
+
filterOperators: ALL_WHERE_FILTER_OPS.filter((op) => op !== "like" && op !== "ilike" && op !== "not-like" && op !== "not-ilike" && op !== "array-contains-all" && op !== "array-contained-by"),
|
|
655
663
|
filterableRelationKinds: [],
|
|
656
664
|
supportsRelationFieldFilters: false,
|
|
657
665
|
relationAggregateSorts: false,
|
|
@@ -3918,6 +3926,82 @@ function resolverFromSources(client) {
|
|
|
3918
3926
|
};
|
|
3919
3927
|
}
|
|
3920
3928
|
//#endregion
|
|
3921
|
-
|
|
3929
|
+
//#region src/controllers/aggregates.ts
|
|
3930
|
+
/** Every aggregate function, by its SDK name: what `?select=` accepts too. */
|
|
3931
|
+
var AGGREGATE_FUNCTIONS = [
|
|
3932
|
+
"count",
|
|
3933
|
+
"sum",
|
|
3934
|
+
"avg",
|
|
3935
|
+
"min",
|
|
3936
|
+
"max",
|
|
3937
|
+
"countDistinct",
|
|
3938
|
+
"mode",
|
|
3939
|
+
"percentile",
|
|
3940
|
+
"distinct",
|
|
3941
|
+
"fingerprint"
|
|
3942
|
+
];
|
|
3943
|
+
/** The functions that take no field. */
|
|
3944
|
+
var FIELDLESS_AGGREGATES = /* @__PURE__ */ new Set(["count", "fingerprint"]);
|
|
3945
|
+
/** Every `groupBy` transform. */
|
|
3946
|
+
var AGGREGATE_GROUP_TRANSFORMS = [
|
|
3947
|
+
"lower",
|
|
3948
|
+
"upper",
|
|
3949
|
+
"unnest",
|
|
3950
|
+
"year",
|
|
3951
|
+
"month",
|
|
3952
|
+
"day"
|
|
3953
|
+
];
|
|
3954
|
+
/** A function's name in its result key: the SDK's camelCase in SQL's spelling. */
|
|
3955
|
+
var ALIAS_NAMES = { countDistinct: "count_distinct" };
|
|
3956
|
+
/**
|
|
3957
|
+
* `percentile`'s `p` as it reads in a key: `0.95` → `95`, `0.5` → `50`,
|
|
3958
|
+
* `0.995` → `99_5`.
|
|
3959
|
+
*/
|
|
3960
|
+
function percentileLabel(p) {
|
|
3961
|
+
return String(Math.round(p * 1e3) / 10).replace(".", "_");
|
|
3962
|
+
}
|
|
3963
|
+
/**
|
|
3964
|
+
* The key an aggregate comes back under.
|
|
3965
|
+
*
|
|
3966
|
+
* `sum(total)` → `sum_total`, `count()` → `count`, `countDistinct(sid)` →
|
|
3967
|
+
* `count_distinct_sid`, `percentile(fame, 0.95)` → `p95_fame`. One function,
|
|
3968
|
+
* because the SDK, the REST parser and the HTTP client all derive it and have
|
|
3969
|
+
* to agree — a caller reading `row.sum_total` off an SDK result and off an HTTP
|
|
3970
|
+
* response is reading the same key or the SDK is broken.
|
|
3971
|
+
*/
|
|
3972
|
+
function aggregateAlias(fn, field, p) {
|
|
3973
|
+
if (fn === "percentile") return `p${percentileLabel(p ?? 0)}_${field ?? ""}`;
|
|
3974
|
+
const name = ALIAS_NAMES[fn] ?? fn;
|
|
3975
|
+
return field ? `${name}_${field}` : name;
|
|
3976
|
+
}
|
|
3977
|
+
/** `percentile`'s `p`, refused unless it is a fraction a key can name (0–1, at most three decimals). */
|
|
3978
|
+
function isPercentileFraction(p) {
|
|
3979
|
+
return typeof p === "number" && Number.isFinite(p) && p >= 0 && p <= 1 && Math.abs(Math.round(p * 1e3) - p * 1e3) < 1e-9;
|
|
3980
|
+
}
|
|
3981
|
+
/** An `AggregateSelect` as a driver is handed it. */
|
|
3982
|
+
function toDriverAggregate(select) {
|
|
3983
|
+
const field = "field" in select ? select.field : void 0;
|
|
3984
|
+
const p = select.fn === "percentile" ? select.p : void 0;
|
|
3985
|
+
return {
|
|
3986
|
+
fn: select.fn,
|
|
3987
|
+
...field !== void 0 ? { field } : {},
|
|
3988
|
+
...p !== void 0 ? { p } : {},
|
|
3989
|
+
alias: aggregateAlias(select.fn, field, p)
|
|
3990
|
+
};
|
|
3991
|
+
}
|
|
3992
|
+
/** The key a group comes back under: the column's name, or `<transform>_<field>`. */
|
|
3993
|
+
function aggregateGroupKey(group) {
|
|
3994
|
+
return typeof group === "string" ? group : `${group.transform}_${group.field}`;
|
|
3995
|
+
}
|
|
3996
|
+
/** A `groupBy` entry as a driver is handed it. */
|
|
3997
|
+
function toDriverAggregateGroup(group) {
|
|
3998
|
+
return typeof group === "string" ? group : {
|
|
3999
|
+
field: group.field,
|
|
4000
|
+
transform: group.transform,
|
|
4001
|
+
key: aggregateGroupKey(group)
|
|
4002
|
+
};
|
|
4003
|
+
}
|
|
4004
|
+
//#endregion
|
|
4005
|
+
export { ADMIN_COLLECTION_KEYS, ADMIN_PROPERTY_KEYS, ADMIN_ROLE, ADMIN_SCOPES, AGGREGATE_FUNCTIONS, AGGREGATE_GROUP_TRANSFORMS, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, ANONYMOUS_USER_IDS, AUTH_FLOW_HEADER, BATCH_REF_KEY, BUILT_IN_SCOPES, BUILT_IN_SCOPE_DESCRIPTIONS, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DATA_PLANE_SCOPES, DEFAULT_CAPABILITIES, DEFAULT_COMMIT_PATHS, DEFAULT_DATA_SOURCE_KEY, DEFAULT_FILTERABLE_RELATION_KINDS, DEFAULT_FUZZY_THRESHOLD, DEFAULT_LIST_LIMIT, DEFAULT_RESOURCE_KEY, DEFAULT_SEARCH_COLUMN, DEFAULT_SEARCH_LANGUAGE, DEFAULT_SEARCH_MODE, DEFAULT_SEARCH_WEIGHT, DEFAULT_STORAGE_SOURCE_KEY, DEFAULT_TENANT_BYPASS_ROLES, DEFAULT_VECTOR_LIST_LIMIT, EMPTY_ACCESS_MODEL, EntityReference, EntityRelation, FIELDLESS_AGGREGATES, FIELD_OPERATORS, FIREBASE_CAPABILITIES, GeoPoint, IMPERSONATE_HEADER, INCLUDE_COUNT_KEY, JUNCTION_PIVOT_KEY, KEY_MANAGEMENT_SCOPES, LEGACY_RLS_JWT_SQL, LEGACY_RLS_ROLES_SQL, LEGACY_RLS_SCHEMA, LEGACY_RLS_UID_SQL, LIST_OPS, ListLimitError, MAX_INCLUDE_DEPTH, MAX_LIST_LIMIT, MCP_APP_MODULES, MONGODB_CAPABILITIES, NULL_OPS, POSTGRES_CAPABILITIES, PUBLIC_STORAGE_PREFIX, REBASE_SCHEMA, RELEVANCE_SORT_FIELD, RESERVED_BACKEND_PREFIXES, RESOURCE_GRAPH_VERSION, REST_TO_CANONICAL, RLS_IS_ANONYMOUS_SQL, RLS_JWT_SQL, RLS_ROLES_SQL, RLS_UID_SQL, RUNTIME_CONTRACT_VERSION, RUNTIME_ONLY_COLLECTION_KEYS, RebaseApiError, RebaseClientError, SCHEMA_VERSION_HEADER, SCOPE_TARGETS, SIMULATED_CONTEXT_HEADER, SIMULATE_API_KEY_ID_HEADER, SIMULATE_ROLE_HEADER, SIMULATE_USER_ID_HEADER, STORAGE_REFERENCE_SCHEME, Vector, aggregateAlias, aggregateGroupKey, amendResourceKind, applyCollectionPatch, bucket, buildResourceGraph, canonicalSchemaPayload, collectionPatchProblems, computeSchemaVersion, database, declareCron, declareFunction, declareResource, declaredDataSources, declaredDatabaseExtensions, declaredQueueConsumers, declaredResources, declaredStorageSources, declaredSubscriptions, describeScope, deserializeCollections, diffCollections, diffJsonValues, encodeRelationAggregateSort, envBasesForResource, findEnvSuffixCollision, findStorageSuffixCollision, formatSimulatedContext, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, hasAdminRole, hasFieldOperation, hasForeignKeyOnTarget, intersectScopes, isAdminScope, isAnonymousUid, isBranchAdmin, isBuiltInScope, isChannelBusInstance, isCollectionPatch, isContentHashedFileName, isDataPlaneScope, isDocumentAdmin, isFieldOperation, isFirebaseCollectionConfig, isLazyComponentRef, isManyToMany, isMongoDBCollectionConfig, isPercentileFraction, isPostgresCollectionConfig, isPublicStorageKey, isPublicStoragePath, isRelationAggregateSort, isRelationalCollectionConfig, isResourceHandle, isSQLAdmin, isSchemaAdmin, isSchemaEditingAdmin, isSerializedCollectionRef, isStorageReference, isTenantClaimSource, isTenantMembershipSource, isToMany, isUnsupported, isValidAppHost, isValidEngine, joinConditions, knownScopes, nestAdminCollectionKeys, nestAdminKeysOf, nestAdminPropertyKeys, nestCollectionPatchPaths, parseAppAddress, parseEnvBoolean, parseRelationAggregateSort, parseScope, parseSimulatedContext, parseStorageReference, policy, queue, registerDataSourceCapabilities, registerResourceKind, reservedPrefixFor, resetDeclaredQueueConsumers, resetDeclaredResources, resetDeclaredSubscriptions, resolveClientListLimit, resolveResourceRefs, resolveStorageReferences, resourceEnvSuffix, resourceId, resourceKeyOf, resourceKind, resourceKinds, resourceToDataSource, resourceToStorageSource, rewriteLegacyRlsFunctions, roleNameProblem, runtimeOnlyKeyIn, scopeAcceptsTarget, scopeGrants, scopeGrantsAny, scopeTargets, scopesBeyond, scopesForRoles, serializeCollections, setQueueRuntime, setTopicRuntime, simulationHeaders, soleJoinCondition, sortKeyToString, storageEnvSuffix, storageObjectPath, storageReference, storageReferencesForDownloadUrls, storageTargetOfDownloadUrl, storageTargetsInText, summarizeRoles, summarizeScopes, toCanonicalOp, toCollectionJson, toDriverAggregate, toDriverAggregateGroup, topic, unsupportedMethod, usesLegacyRlsFunctions, validateScopes };
|
|
3922
4006
|
|
|
3923
4007
|
//# sourceMappingURL=index.es.js.map
|