@rebasepro/types 0.28.2 → 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 +64 -9
- package/dist/controllers/index.d.ts +1 -0
- package/dist/index.es.js +150 -3
- package/dist/index.es.js.map +1 -1
- package/dist/types/auth_adapter.d.ts +18 -0
- package/dist/types/backend.d.ts +46 -0
- package/dist/types/collections.d.ts +43 -0
- package/dist/types/filter-operators.d.ts +4 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mcp_app_modules.d.ts +28 -0
- package/dist/types/properties.d.ts +10 -10
- package/dist/types/schema_editing.d.ts +7 -1
- 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
|
|
@@ -447,6 +447,31 @@ export interface DataDriver {
|
|
|
447
447
|
* @return Function to cancel subscription
|
|
448
448
|
*/
|
|
449
449
|
listenOne?<M extends Record<string, unknown> = Record<string, unknown>>(props: ListenOneProps<M>): () => void;
|
|
450
|
+
/**
|
|
451
|
+
* Let `<Rebase>` hear about changes this driver learns of that it did not
|
|
452
|
+
* write itself — rows another process wrote, or ones an agent changed
|
|
453
|
+
* through the driver's own backend.
|
|
454
|
+
*
|
|
455
|
+
* `<Rebase>` calls it once per driver it holds, while it is mounted, and
|
|
456
|
+
* calls the function it returns when it unmounts. The driver calls
|
|
457
|
+
* `onExternalChange(path)` with the path of each collection that changed
|
|
458
|
+
* (the path the driver stores it under, as {@link FetchCollectionProps.path}
|
|
459
|
+
* names it, or the collection's slug), and every view of that collection
|
|
460
|
+
* whose data source cannot subscribe reads it again: the row hooks
|
|
461
|
+
* (`useRows`, `useRow`, `useRowCount`, `useAggregate`) and the admin's
|
|
462
|
+
* collection views. A view that subscribes through
|
|
463
|
+
* {@link listenCollection} is left alone, so a driver that already pushes
|
|
464
|
+
* the change there gains nothing from announcing it here.
|
|
465
|
+
*
|
|
466
|
+
* Writes made through `<Rebase>` itself need no announcement: they are
|
|
467
|
+
* signalled as they succeed.
|
|
468
|
+
*
|
|
469
|
+
* Optional: a driver that learns of no outside changes leaves it out.
|
|
470
|
+
*
|
|
471
|
+
* @param onExternalChange call with a changed collection's path
|
|
472
|
+
* @return stop calling `onExternalChange`
|
|
473
|
+
*/
|
|
474
|
+
subscribeToExternalChanges?(onExternalChange: (path: string) => void): () => void;
|
|
450
475
|
/**
|
|
451
476
|
* Save a row to the specified path
|
|
452
477
|
* @param props
|
|
@@ -475,6 +500,14 @@ export interface DataDriver {
|
|
|
475
500
|
* a caller reaches for a batch to get.
|
|
476
501
|
*/
|
|
477
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>;
|
|
478
511
|
/**
|
|
479
512
|
* Delete the row `props.row` addresses.
|
|
480
513
|
*
|
|
@@ -662,6 +695,25 @@ export interface DataDriver {
|
|
|
662
695
|
*/
|
|
663
696
|
admin?: import("../types/backend.js").DatabaseAdmin;
|
|
664
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
|
+
}
|
|
665
717
|
/**
|
|
666
718
|
* REST-optimised fetch service exposed by drivers that support
|
|
667
719
|
* eager-loading of relations via `include`.
|
|
@@ -725,8 +777,10 @@ export interface RestFetchService {
|
|
|
725
777
|
*/
|
|
726
778
|
cursorFor?(collectionPath: string, row: Record<string, unknown>, orderBy?: OrderByTuple[]): string | undefined;
|
|
727
779
|
/**
|
|
728
|
-
* `
|
|
729
|
-
*
|
|
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`).
|
|
730
784
|
*
|
|
731
785
|
* Optional, and the REST route answers 501 where a driver does not
|
|
732
786
|
* implement it — an aggregate is not a thing to approximate, and an empty
|
|
@@ -736,14 +790,15 @@ export interface RestFetchService {
|
|
|
736
790
|
* read**. An aggregate is an efficient way to learn about rows you cannot
|
|
737
791
|
* select, and `count(*)` over a table whose policies would return nothing
|
|
738
792
|
* has to be zero.
|
|
793
|
+
*
|
|
794
|
+
* Nor may it read what `afterRead` hides. An aggregate does not pass
|
|
795
|
+
* through the callbacks, so on a collection any `afterRead` applies to
|
|
796
|
+
* (global, collection or property) only `count` with no field and no
|
|
797
|
+
* `groupBy` is served; anything else is refused with a 400.
|
|
739
798
|
*/
|
|
740
799
|
aggregate?(collectionPath: string, options: {
|
|
741
|
-
aggregates:
|
|
742
|
-
|
|
743
|
-
field?: string;
|
|
744
|
-
alias: string;
|
|
745
|
-
}[];
|
|
746
|
-
groupBy?: string[];
|
|
800
|
+
aggregates: DriverAggregate[];
|
|
801
|
+
groupBy?: (string | DriverAggregateGroup)[];
|
|
747
802
|
filter?: FilterValues<string>;
|
|
748
803
|
logical?: LogicalCondition;
|
|
749
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,
|
|
@@ -1906,6 +1914,7 @@ amendResourceKind("database", { envBases: [
|
|
|
1906
1914
|
"DATABASE_URL",
|
|
1907
1915
|
"DATABASE_READ_URL",
|
|
1908
1916
|
"DATABASE_DIRECT_URL",
|
|
1917
|
+
"DATABASE_POOLED",
|
|
1909
1918
|
"ADMIN_CONNECTION_STRING",
|
|
1910
1919
|
"REBASE_DRIVER",
|
|
1911
1920
|
"DB_POOL_MAX",
|
|
@@ -2389,6 +2398,24 @@ function isLazyComponentRef(ref) {
|
|
|
2389
2398
|
*/
|
|
2390
2399
|
var IMPERSONATE_HEADER = "x-rebase-impersonate";
|
|
2391
2400
|
/**
|
|
2401
|
+
* The request header a client sends to the auth routes to say where it keeps
|
|
2402
|
+
* its refresh token. `json` asks for the token in the response body, and has
|
|
2403
|
+
* the token it presents read from the request body.
|
|
2404
|
+
*
|
|
2405
|
+
* It matters only on a server with `cookieAuth`, which otherwise puts the
|
|
2406
|
+
* token in an HttpOnly cookie and answers the body's with `""`, so a client
|
|
2407
|
+
* with no cookie jar (Node, React Native), or one that keeps its own sign-in
|
|
2408
|
+
* apart from the page's cookie session, held nothing to renew with. A request
|
|
2409
|
+
* that sends it is answered as a server without `cookieAuth` answers: the
|
|
2410
|
+
* cookie is neither read nor set. So it can never turn a cookie the page's
|
|
2411
|
+
* script cannot read into a token it can.
|
|
2412
|
+
*
|
|
2413
|
+
* `@rebasepro/client` sends it on every auth request in `authFlowMode: "json"`.
|
|
2414
|
+
*
|
|
2415
|
+
* @group Auth
|
|
2416
|
+
*/
|
|
2417
|
+
var AUTH_FLOW_HEADER = "x-rebase-auth-flow";
|
|
2418
|
+
/**
|
|
2392
2419
|
* The request header that asks for a data-plane request to run as a role —
|
|
2393
2420
|
* the RLS simulator's "view as". Alone it runs as a signed-in holder of that
|
|
2394
2421
|
* role who owns no rows; with {@link SIMULATE_USER_ID_HEADER} it runs as that
|
|
@@ -3357,6 +3384,50 @@ function computeSchemaVersion(collections) {
|
|
|
3357
3384
|
return `v1:${hex(h1)}${hex(h2)}`;
|
|
3358
3385
|
}
|
|
3359
3386
|
//#endregion
|
|
3387
|
+
//#region src/types/mcp_app_modules.ts
|
|
3388
|
+
/**
|
|
3389
|
+
* The modules an app Claude writes for show_app may import, and from each the
|
|
3390
|
+
* names the MCP view serves.
|
|
3391
|
+
*
|
|
3392
|
+
* An app imports the real package names, so the code reads — and pastes into
|
|
3393
|
+
* a project — like every other piece of Rebase code. Inside the view each
|
|
3394
|
+
* name is the package's own part: `"*"` serves the whole module, a list
|
|
3395
|
+
* serves exactly those exports. The one list three readers share, so none
|
|
3396
|
+
* can drift from the others:
|
|
3397
|
+
*
|
|
3398
|
+
* - the view's module registry (`@rebasepro/cms/mcp-view`), which hands an
|
|
3399
|
+
* app these exports and no others;
|
|
3400
|
+
* - the server's compiler for show_app, which refuses any other import
|
|
3401
|
+
* before the app opens, naming it;
|
|
3402
|
+
* - show_app's guide (`SHOW_APP_CODE_GUIDE` in `@rebasepro/server`), which a
|
|
3403
|
+
* test holds to this list.
|
|
3404
|
+
*/
|
|
3405
|
+
var MCP_APP_MODULES = {
|
|
3406
|
+
"react": "*",
|
|
3407
|
+
"react/jsx-runtime": "*",
|
|
3408
|
+
"@rebasepro/ui": "*",
|
|
3409
|
+
"@rebasepro/app": [
|
|
3410
|
+
"useRows",
|
|
3411
|
+
"useRow",
|
|
3412
|
+
"useRowCount",
|
|
3413
|
+
"useAggregate",
|
|
3414
|
+
"useRowWrites"
|
|
3415
|
+
],
|
|
3416
|
+
"@rebasepro/cms": [
|
|
3417
|
+
"CollectionPanel",
|
|
3418
|
+
"CollectionToolbar",
|
|
3419
|
+
"CollectionSearchBar",
|
|
3420
|
+
"CollectionFiltersButton",
|
|
3421
|
+
"CollectionViewModeToggle",
|
|
3422
|
+
"CollectionAddButton",
|
|
3423
|
+
"RecordForm",
|
|
3424
|
+
"RecordDetail",
|
|
3425
|
+
"FormField",
|
|
3426
|
+
"FieldValue",
|
|
3427
|
+
"useSidePanel"
|
|
3428
|
+
]
|
|
3429
|
+
};
|
|
3430
|
+
//#endregion
|
|
3360
3431
|
//#region src/controllers/data.ts
|
|
3361
3432
|
/**
|
|
3362
3433
|
* Hops an {@link IncludeSpec} may nest. `comments.author` is two.
|
|
@@ -3855,6 +3926,82 @@ function resolverFromSources(client) {
|
|
|
3855
3926
|
};
|
|
3856
3927
|
}
|
|
3857
3928
|
//#endregion
|
|
3858
|
-
|
|
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 };
|
|
3859
4006
|
|
|
3860
4007
|
//# sourceMappingURL=index.es.js.map
|