@protobase/query 0.46.6 → 0.46.7
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/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/scope.d.ts +8 -0
- package/dist/scope.js +9 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CompileOptions, compileFilter } from "./compile-filter.js";
|
|
2
2
|
import { Db } from "./db.js";
|
|
3
|
-
import { Scope } from "./scope.js";
|
|
3
|
+
import { Scope, tenantCondition } from "./scope.js";
|
|
4
4
|
import { RelatedRowsQuery, buildRelatedRows, relatedRows } from "./related-rows.js";
|
|
5
5
|
import { ExtraColumn, ListOptions, ListPlan, ListResult, buildListQuery, listQuery, maxLimit } from "./list-query.js";
|
|
6
6
|
import { estimateCount } from "./estimate-count.js";
|
|
@@ -20,4 +20,4 @@ import { IndexKey, TableIndex, TableIndexes, tableIndexes } from "./table-indexe
|
|
|
20
20
|
import { ColumnUse, CoverageQuery, IndexNeed, UncoveredColumn, indexServes, uncoveredColumns } from "./index-coverage.js";
|
|
21
21
|
import { QueryError, QueryErrorCode } from "./fields/query-error.js";
|
|
22
22
|
import { SeekRequest, seekToPosition } from "./seek-to-position.js";
|
|
23
|
-
export { type ColumnUse, type CompileOptions, type CoverageQuery, type Db, type ExtraColumn, type FacetCount, type FacetOptions, type Granularity, type GroupTotal, type GroupTotalsOptions, type Histogram, type HistogramBucket, type IndexKey, type IndexNeed, type ListOptions, type ListPlan, type ListResult, type MapBounds, type MapBucket, type MapBuckets, type MapPosition, type Measure, QueryError, type QueryErrorCode, type RelatedRowsQuery, type Scope, type ScrollMode, type SeekRequest, type SeriesOptions, type SeriesPoint, type SplitPoint, type SplitSeriesOptions, type TableIndex, type TableIndexes, type UncoveredColumn, buildListQuery, buildRelatedRows, cellsAcross, checkMapPosition, compileFilter, countUpTo, estimateCount, exactCount, facetCounts, groupTotals, histogram, indexServes, listQuery, mapBuckets, mapCellPixels, maxLimit, maxMapBuckets, maxMapZoom, relatedRows, scrollMode, seekToPosition, series, splitSeries, tableIndexes, uncoveredColumns, withoutField };
|
|
23
|
+
export { type ColumnUse, type CompileOptions, type CoverageQuery, type Db, type ExtraColumn, type FacetCount, type FacetOptions, type Granularity, type GroupTotal, type GroupTotalsOptions, type Histogram, type HistogramBucket, type IndexKey, type IndexNeed, type ListOptions, type ListPlan, type ListResult, type MapBounds, type MapBucket, type MapBuckets, type MapPosition, type Measure, QueryError, type QueryErrorCode, type RelatedRowsQuery, type Scope, type ScrollMode, type SeekRequest, type SeriesOptions, type SeriesPoint, type SplitPoint, type SplitSeriesOptions, type TableIndex, type TableIndexes, type UncoveredColumn, buildListQuery, buildRelatedRows, cellsAcross, checkMapPosition, compileFilter, countUpTo, estimateCount, exactCount, facetCounts, groupTotals, histogram, indexServes, listQuery, mapBuckets, mapCellPixels, maxLimit, maxMapBuckets, maxMapZoom, relatedRows, scrollMode, seekToPosition, series, splitSeries, tableIndexes, tenantCondition, uncoveredColumns, withoutField };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QueryError } from "./fields/query-error.js";
|
|
2
2
|
import { compileFilter } from "./compile-filter.js";
|
|
3
|
+
import { tenantCondition } from "./scope.js";
|
|
3
4
|
import { buildListQuery, listQuery, maxLimit } from "./list-query.js";
|
|
4
5
|
import { buildRelatedRows, relatedRows } from "./related-rows.js";
|
|
5
6
|
import { estimateCount } from "./estimate-count.js";
|
|
@@ -16,4 +17,4 @@ import { scrollMode } from "./scroll-mode.js";
|
|
|
16
17
|
import { tableIndexes } from "./table-indexes.js";
|
|
17
18
|
import { indexServes, uncoveredColumns } from "./index-coverage.js";
|
|
18
19
|
import { seekToPosition } from "./seek-to-position.js";
|
|
19
|
-
export { QueryError, buildListQuery, buildRelatedRows, cellsAcross, checkMapPosition, compileFilter, countUpTo, estimateCount, exactCount, facetCounts, groupTotals, histogram, indexServes, listQuery, mapBuckets, mapCellPixels, maxLimit, maxMapBuckets, maxMapZoom, relatedRows, scrollMode, seekToPosition, series, splitSeries, tableIndexes, uncoveredColumns, withoutField };
|
|
20
|
+
export { QueryError, buildListQuery, buildRelatedRows, cellsAcross, checkMapPosition, compileFilter, countUpTo, estimateCount, exactCount, facetCounts, groupTotals, histogram, indexServes, listQuery, mapBuckets, mapCellPixels, maxLimit, maxMapBuckets, maxMapZoom, relatedRows, scrollMode, seekToPosition, series, splitSeries, tableIndexes, tenantCondition, uncoveredColumns, withoutField };
|
package/dist/scope.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { CheckedFilter, ResourceModel } from "@protobase/schema";
|
|
|
4
4
|
/**
|
|
5
5
|
* Who is asking, and which rows they may see.
|
|
6
6
|
* - `tenantValue`: models with a `tenant` column only ever see rows of this value.
|
|
7
|
+
* - `tenantValues`: instead, rows of any of these values, for a list across the caller's tenants; `rowFilter` then ties
|
|
8
|
+
* each tenant to its own access. An empty list sees no rows.
|
|
7
9
|
* - `rowFilter`: a filter from access rules, ANDed in before the user's filter. It is checked against the FULL model,
|
|
8
10
|
* so it may use hidden or non-filterable columns the user's own (restricted) model does not expose.
|
|
9
11
|
* - `fullModel`: that full model. Soft delete, tenant and `rowFilter` resolve against it; everything the user
|
|
@@ -11,7 +13,13 @@ import { CheckedFilter, ResourceModel } from "@protobase/schema";
|
|
|
11
13
|
*/
|
|
12
14
|
export type Scope = {
|
|
13
15
|
tenantValue?: string | number;
|
|
16
|
+
tenantValues?: readonly (string | number)[];
|
|
14
17
|
rowFilter?: CheckedFilter;
|
|
15
18
|
fullModel?: ResourceModel;
|
|
16
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* `tenant = value`, or `tenant in (values)`, for tenant models; throws when the scope is missing, so a forgotten scope
|
|
22
|
+
* never leaks rows.
|
|
23
|
+
*/
|
|
24
|
+
export declare const tenantCondition: (model: ResourceModel, scope?: Scope) => Expression<SqlBool> | undefined;
|
|
17
25
|
//#endregion
|
package/dist/scope.js
CHANGED
|
@@ -3,14 +3,21 @@ import { columnRef } from "./columns.js";
|
|
|
3
3
|
import { sql } from "kysely";
|
|
4
4
|
//#region src/scope.ts
|
|
5
5
|
const fullModelOf = (model, scope) => scope?.fullModel ?? model;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* `tenant = value`, or `tenant in (values)`, for tenant models; throws when the scope is missing, so a forgotten scope
|
|
8
|
+
* never leaks rows.
|
|
9
|
+
*/
|
|
7
10
|
const tenantCondition = (model, scope) => {
|
|
8
11
|
const full = fullModelOf(model, scope);
|
|
9
12
|
const tenant = full.tenant ?? model.tenant;
|
|
10
13
|
if (!tenant) return void 0;
|
|
11
|
-
if (scope?.tenantValue === void 0) throw new QueryError("missing_tenant", `Resource "${model.name}" is tenant-scoped; pass scope.tenantValue`);
|
|
12
14
|
const field = Object.hasOwn(full.fields, tenant) ? full.fields[tenant] : void 0;
|
|
13
15
|
const column = field ? columnRef(field) : sql`${sql.id("t", tenant)}`;
|
|
16
|
+
if (scope?.tenantValues) {
|
|
17
|
+
if (scope.tenantValues.length === 0) return sql`false`;
|
|
18
|
+
return sql`${column} in (${sql.join(scope.tenantValues)})`;
|
|
19
|
+
}
|
|
20
|
+
if (scope?.tenantValue === void 0) throw new QueryError("missing_tenant", `Resource "${model.name}" is tenant-scoped; pass scope.tenantValue`);
|
|
14
21
|
return sql`${column} = ${scope.tenantValue}`;
|
|
15
22
|
};
|
|
16
23
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/query",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.7",
|
|
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.46.
|
|
32
|
+
"@protobase/schema": "0.46.7",
|
|
33
33
|
"kysely": "^0.29.6"
|
|
34
34
|
}
|
|
35
35
|
}
|