@rebasepro/common 0.16.0 → 0.16.1-canary.g0d7af95
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/collections/CollectionRegistry.d.ts +1 -1
- package/dist/collections/index.d.ts +2 -2
- package/dist/index.d.ts +11 -11
- package/dist/index.es.js +50 -1
- package/dist/index.es.js.map +1 -1
- package/dist/util/index.d.ts +21 -21
- package/dist/util/internal-tables.d.ts +9 -0
- package/dist/util/internal-tables.test.d.ts +1 -0
- package/dist/util/policy/index.d.ts +4 -4
- package/dist/util/relations.d.ts +25 -0
- package/package.json +4 -4
- package/src/data/buildRebaseData.ts +9 -0
- package/src/util/internal-tables.test.ts +176 -0
- package/src/util/internal-tables.ts +11 -0
- package/src/util/relations.ts +48 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CollectionCallbacks, CollectionConfig } from "@rebasepro/types";
|
|
2
|
-
import { DataSourceRegistry } from "../data/resolveDataSource";
|
|
2
|
+
import { DataSourceRegistry } from "../data/resolveDataSource.js";
|
|
3
3
|
export declare class CollectionRegistry {
|
|
4
4
|
/**
|
|
5
5
|
* Declared data sources, used during normalization to resolve each
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./CollectionRegistry";
|
|
2
|
-
export * from "./default-collections";
|
|
1
|
+
export * from "./CollectionRegistry.js";
|
|
2
|
+
export * from "./default-collections.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from "./util";
|
|
2
|
-
export * from "./collections";
|
|
3
|
-
export * from "./data/buildRebaseData";
|
|
4
|
-
export * from "./data/buildRoutedRebaseData";
|
|
5
|
-
export * from "./data/resolveDataSource";
|
|
6
|
-
export * from "./data/query_builder";
|
|
7
|
-
export * from "./data/paginate";
|
|
8
|
-
export * from "./data/filter-conditions";
|
|
9
|
-
export * from "./data/filter-dialect";
|
|
10
|
-
export * from "./data/sort-dialect";
|
|
11
|
-
export * from "./table-classification";
|
|
1
|
+
export * from "./util/index.js";
|
|
2
|
+
export * from "./collections/index.js";
|
|
3
|
+
export * from "./data/buildRebaseData.js";
|
|
4
|
+
export * from "./data/buildRoutedRebaseData.js";
|
|
5
|
+
export * from "./data/resolveDataSource.js";
|
|
6
|
+
export * from "./data/query_builder.js";
|
|
7
|
+
export * from "./data/paginate.js";
|
|
8
|
+
export * from "./data/filter-conditions.js";
|
|
9
|
+
export * from "./data/filter-dialect.js";
|
|
10
|
+
export * from "./data/sort-dialect.js";
|
|
11
|
+
export * from "./table-classification.js";
|
package/dist/index.es.js
CHANGED
|
@@ -699,8 +699,45 @@ function getTableName(collection) {
|
|
|
699
699
|
if (isRelationalCollectionConfig(collection)) return collection.table ?? toSnakeCase(collection.slug) ?? toSnakeCase(collection.name);
|
|
700
700
|
return toSnakeCase(collection.slug) ?? toSnakeCase(collection.name);
|
|
701
701
|
}
|
|
702
|
+
/**
|
|
703
|
+
* A JavaScript identifier: what a generated `export const <name> =` needs.
|
|
704
|
+
*
|
|
705
|
+
* Deliberately the same shape the two schema generators already define
|
|
706
|
+
* privately — this is the third place that needed it, and the first two guard
|
|
707
|
+
* property keys and member accesses while nothing guarded the variable name
|
|
708
|
+
* itself.
|
|
709
|
+
*/
|
|
710
|
+
var JS_IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
711
|
+
/**
|
|
712
|
+
* The variable name a generated table is bound to.
|
|
713
|
+
*
|
|
714
|
+
* Camel-cases underscores, and then guarantees the result is a legal
|
|
715
|
+
* identifier. It did only the first, so a table name that is legal in Postgres
|
|
716
|
+
* and not in JavaScript produced a `schema.generated.ts` that does not parse:
|
|
717
|
+
*
|
|
718
|
+
* `2024_archive` → `export const 2024Archive = pgTable(…)`
|
|
719
|
+
* "An identifier or keyword cannot immediately follow
|
|
720
|
+
* a numeric literal"
|
|
721
|
+
* `reporting.events` → `export const reporting.events = pgTable(…)`
|
|
722
|
+
* "',' expected"
|
|
723
|
+
*
|
|
724
|
+
* That file is imported by the server, so the failure is not one broken
|
|
725
|
+
* collection — `rebase build` and `db push` fail at tsc for the whole
|
|
726
|
+
* directory. And it is reachable from a documented flow: `rebase init` against
|
|
727
|
+
* a database holding a table called `2024_archive` writes a collection file
|
|
728
|
+
* that parses and a schema file that does not.
|
|
729
|
+
*
|
|
730
|
+
* **A no-op for every name that already worked**, which is what makes changing
|
|
731
|
+
* a derived name safe here: the only inputs whose output changes are the ones
|
|
732
|
+
* that produced a syntax error, and nothing can be running against those.
|
|
733
|
+
* Separators become camel case rather than disappearing, so `reporting.events`
|
|
734
|
+
* and `reporting_events` do not collide into one variable.
|
|
735
|
+
*/
|
|
702
736
|
function getTableVarName(tableName) {
|
|
703
|
-
|
|
737
|
+
const camel = tableName.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
738
|
+
if (JS_IDENTIFIER.test(camel)) return camel;
|
|
739
|
+
const sanitised = camel.replace(/[^A-Za-z0-9_$]+([A-Za-z0-9])?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^([0-9])/, "t$1");
|
|
740
|
+
return JS_IDENTIFIER.test(sanitised) ? sanitised : `t${sanitised}`;
|
|
704
741
|
}
|
|
705
742
|
function getEnumVarName(tableName, propName) {
|
|
706
743
|
return `${getTableVarName(tableName)}${propName.charAt(0).toUpperCase() + propName.slice(1)}`;
|
|
@@ -2804,6 +2841,15 @@ var REBASE_USER_ROLE = "rebase_user";
|
|
|
2804
2841
|
*
|
|
2805
2842
|
* `atlas_schema_revisions` is Atlas's migration ledger, which lands in `rebase`
|
|
2806
2843
|
* because `db migrate apply` passes `--revisions-schema rebase`.
|
|
2844
|
+
*
|
|
2845
|
+
* Every entry here must also be revoked by whatever creates it, and vice versa:
|
|
2846
|
+
* the creation-time revoke fires once, on the boot that first makes the table,
|
|
2847
|
+
* so it cannot help a database provisioned before that revoke existed. This
|
|
2848
|
+
* list is what the boot-time sweep in `ensureAppRole` iterates, and the sweep
|
|
2849
|
+
* is the only thing that can repair an already-granted table. A table revoked
|
|
2850
|
+
* at creation but missing here is therefore permanently stranded on any
|
|
2851
|
+
* database that predates its revoke — which is exactly what happened to
|
|
2852
|
+
* `jobs`, added here after a scan of a pre-0.14 database found it.
|
|
2807
2853
|
*/
|
|
2808
2854
|
var REBASE_INTERNAL_TABLES = [
|
|
2809
2855
|
"user_identities",
|
|
@@ -2818,10 +2864,12 @@ var REBASE_INTERNAL_TABLES = [
|
|
|
2818
2864
|
"api_keys",
|
|
2819
2865
|
"cron_logs",
|
|
2820
2866
|
"cron_claims",
|
|
2867
|
+
"jobs",
|
|
2821
2868
|
"rate_limit_hits",
|
|
2822
2869
|
"idempotency_keys",
|
|
2823
2870
|
"entity_history",
|
|
2824
2871
|
"branches",
|
|
2872
|
+
"metric_samples",
|
|
2825
2873
|
"channel_messages",
|
|
2826
2874
|
"channel_cursors",
|
|
2827
2875
|
"channel_presence",
|
|
@@ -4543,6 +4591,7 @@ function createDriverAccessor(driver, slug, getPks = () => []) {
|
|
|
4543
4591
|
orderBy: normalizeOrderBy(params?.orderBy),
|
|
4544
4592
|
searchString: params?.searchString,
|
|
4545
4593
|
searchExplain: params?.searchExplain,
|
|
4594
|
+
vectorSearch: params?.vectorSearch,
|
|
4546
4595
|
onUpdate: (entities) => {
|
|
4547
4596
|
onUpdate({
|
|
4548
4597
|
data: entities.map((row) => rowToEntity(normalize(row), slug, getPks())),
|