@rebasepro/server-postgres 0.17.3 → 0.18.1
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/LICENSE +0 -1
- package/README.md +31 -0
- package/dist/BranchService-ByLfM_Tt.js +360 -0
- package/dist/BranchService-ByLfM_Tt.js.map +1 -0
- package/dist/__vite-browser-external-BnuHet1e.js +46 -0
- package/dist/__vite-browser-external-BnuHet1e.js.map +1 -0
- package/dist/arg-Dni7MzLB.js +87 -0
- package/dist/arg-Dni7MzLB.js.map +1 -0
- package/dist/auth-users-columns-D2LBFrMH.js +116 -0
- package/dist/auth-users-columns-D2LBFrMH.js.map +1 -0
- package/dist/backup-argv.d.ts +19 -0
- package/dist/backup-cli-oM9WQVlV.js +408 -0
- package/dist/backup-cli-oM9WQVlV.js.map +1 -0
- package/dist/backup-service-Br3tqwsy.js +715 -0
- package/dist/backup-service-Br3tqwsy.js.map +1 -0
- package/dist/branch-argv.d.ts +28 -0
- package/dist/branch-prune.d.ts +77 -0
- package/dist/cli-collections-path.d.ts +31 -0
- package/dist/cli-errors-DxN4yzdH.js +657 -0
- package/dist/cli-errors-DxN4yzdH.js.map +1 -0
- package/dist/cli-errors.d.ts +123 -0
- package/dist/cli-flags.d.ts +101 -0
- package/dist/cli-helpers.d.ts +94 -10
- package/dist/cli-output-CNdMql-L.js +47 -0
- package/dist/cli-output-CNdMql-L.js.map +1 -0
- package/dist/cli.js +2020 -0
- package/dist/cli.js.map +1 -0
- package/dist/collection-index-BHgT_TKd.js +276 -0
- package/dist/collection-index-BHgT_TKd.js.map +1 -0
- package/dist/{collections-schema-version-BMeu3cgv.js → collections-schema-version-T6cGvrDi.js} +1 -2
- package/dist/{collections-schema-version-BMeu3cgv.js.map → collections-schema-version-T6cGvrDi.js.map} +1 -1
- package/dist/{connection-GOKU3Hu5.js → databasePoolManager-Bj5FbeAs.js} +112 -40
- package/dist/databasePoolManager-Bj5FbeAs.js.map +1 -0
- package/dist/databasePoolManager.d.ts +27 -0
- package/dist/doctor-D7HWmGzs.js +974 -0
- package/dist/doctor-D7HWmGzs.js.map +1 -0
- package/dist/{ensure-collection-policies-UCqgv_8c.js → ensure-collection-policies-2c2NV8zX.js} +7 -27
- package/dist/ensure-collection-policies-2c2NV8zX.js.map +1 -0
- package/dist/ensure-collection-tables-D4wJzM4y.js +820 -0
- package/dist/ensure-collection-tables-D4wJzM4y.js.map +1 -0
- package/dist/ensure-tables-CIojK-Rx.js +650 -0
- package/dist/ensure-tables-CIojK-Rx.js.map +1 -0
- package/dist/generate-drizzle-schema-CwEgVyjO.js +123 -0
- package/dist/generate-drizzle-schema-CwEgVyjO.js.map +1 -0
- package/dist/generate-drizzle-schema-logic-so2Z_lyC.js +528 -0
- package/dist/generate-drizzle-schema-logic-so2Z_lyC.js.map +1 -0
- package/dist/{ensure-collection-tables-DgVixhX3.js → generate-postgres-ddl-logic-CtnpIBVv.js} +126 -984
- package/dist/generate-postgres-ddl-logic-CtnpIBVv.js.map +1 -0
- package/dist/generated-schema-staleness-DQdfJl2A.js +157 -0
- package/dist/generated-schema-staleness-DQdfJl2A.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.es.js +7423 -1133
- package/dist/index.es.js.map +1 -1
- package/dist/introspect-db-logic-C6LQdTxj.js +1378 -0
- package/dist/introspect-db-logic-C6LQdTxj.js.map +1 -0
- package/dist/policy-drift-kNJ6X2Uj.js +313 -0
- package/dist/policy-drift-kNJ6X2Uj.js.map +1 -0
- package/dist/{backup-service-DCk7KhhL.js → rls-bootstrap-sql-DLDnUjtx.js} +737 -2689
- package/dist/rls-bootstrap-sql-DLDnUjtx.js.map +1 -0
- package/dist/{rls-enforcement-DvAbL9YJ.js → rls-enforcement-DeYEjYLt.js} +65 -190
- package/dist/rls-enforcement-DeYEjYLt.js.map +1 -0
- package/dist/schema/bin/generate-drizzle-schema.d.ts +1 -0
- package/dist/schema/bin/generate-postgres-ddl.d.ts +1 -0
- package/dist/schema/column-type-drift.d.ts +79 -0
- package/dist/schema/doctor-cli.js +129 -0
- package/dist/schema/doctor-cli.js.map +1 -0
- package/dist/schema/doctor.d.ts +42 -0
- package/dist/schema/ensure-collection-tables.d.ts +90 -0
- package/dist/schema/generate-drizzle-schema.d.ts +1 -1
- package/dist/schema/generate-drizzle-schema.js +24 -0
- package/dist/schema/generate-drizzle-schema.js.map +1 -0
- package/dist/schema/generate-next-step.d.ts +30 -0
- package/dist/schema/generate-postgres-ddl-logic.d.ts +28 -0
- package/dist/schema/generate-postgres-ddl.d.ts +1 -1
- package/dist/schema/generate-postgres-ddl.js +138 -0
- package/dist/schema/generate-postgres-ddl.js.map +1 -0
- package/dist/schema/generated-schema-staleness.d.ts +37 -0
- package/dist/schema/introspect-db-queries.d.ts +34 -0
- package/dist/schema/introspect-db.js +866 -0
- package/dist/schema/introspect-db.js.map +1 -0
- package/dist/security/rls-enforcement.d.ts +63 -2
- package/dist/services/BranchService.d.ts +86 -1
- package/dist/services/collection-helpers.d.ts +1 -1
- package/dist/services/realtimeService.d.ts +30 -2
- package/dist/services/row-pipeline.d.ts +12 -1
- package/dist/source-Br7L7GOI.js +410 -0
- package/dist/source-Br7L7GOI.js.map +1 -0
- package/dist/utils/pg-error-utils.d.ts +3 -1
- package/dist/utils/pg-numeric-number-patch.d.ts +31 -0
- package/dist/vector-index-DkWxm2de.js +309 -0
- package/dist/vector-index-DkWxm2de.js.map +1 -0
- package/package.json +32 -27
- package/dist/backup-service-DCk7KhhL.js.map +0 -1
- package/dist/collection-index-BRUg10H5.js +0 -5690
- package/dist/collection-index-BRUg10H5.js.map +0 -1
- package/dist/connection-GOKU3Hu5.js.map +0 -1
- package/dist/ensure-collection-policies-UCqgv_8c.js.map +0 -1
- package/dist/ensure-collection-tables-DgVixhX3.js.map +0 -1
- package/dist/rls-bootstrap-sql-B5C9LoJ6.js +0 -244
- package/dist/rls-bootstrap-sql-B5C9LoJ6.js.map +0 -1
- package/dist/rls-enforcement-DvAbL9YJ.js.map +0 -1
- package/dist/src-DiB5RP2Z.js +0 -541
- package/dist/src-DiB5RP2Z.js.map +0 -1
- package/dist/websocket-BZ4H5wUz.js +0 -8198
- package/dist/websocket-BZ4H5wUz.js.map +0 -1
- package/src/PostgresAdapter.ts +0 -91
- package/src/PostgresBackendDriver.ts +0 -1857
- package/src/PostgresBootstrapper.ts +0 -1157
- package/src/auth/ensure-tables.ts +0 -896
- package/src/auth/schema-version.ts +0 -260
- package/src/auth/services.ts +0 -1610
- package/src/backup/backup-cli.ts +0 -520
- package/src/backup/backup-cron.ts +0 -212
- package/src/backup/backup-logic.ts +0 -93
- package/src/backup/backup-service.ts +0 -485
- package/src/backup/index.ts +0 -12
- package/src/backup/pg-tools.ts +0 -403
- package/src/backup/retention.ts +0 -86
- package/src/cli-errors.ts +0 -265
- package/src/cli-helpers.ts +0 -569
- package/src/cli-output.ts +0 -43
- package/src/cli.ts +0 -1339
- package/src/collections/PostgresCollectionRegistry.ts +0 -108
- package/src/collections/buildRegistry.ts +0 -68
- package/src/collections/validate-relations.ts +0 -402
- package/src/connection.ts +0 -333
- package/src/data-transformer.ts +0 -845
- package/src/databasePoolManager.ts +0 -95
- package/src/history/HistoryService.ts +0 -254
- package/src/history/ensure-history-table.ts +0 -53
- package/src/index.ts +0 -19
- package/src/interfaces.ts +0 -60
- package/src/module-dir.ts +0 -7
- package/src/schema/atlas-argv.ts +0 -94
- package/src/schema/auth-schema.ts +0 -298
- package/src/schema/auth-users-columns.ts +0 -131
- package/src/schema/carved-out-migration.ts +0 -404
- package/src/schema/classify-change.ts +0 -436
- package/src/schema/collection-index.ts +0 -427
- package/src/schema/collections-schema-version.ts +0 -103
- package/src/schema/destructive-sql.ts +0 -94
- package/src/schema/doctor-cli.ts +0 -66
- package/src/schema/doctor-policy-checks.ts +0 -105
- package/src/schema/doctor.ts +0 -837
- package/src/schema/drizzle-ddl.ts +0 -33
- package/src/schema/dynamic-tables.test.ts +0 -302
- package/src/schema/dynamic-tables.ts +0 -293
- package/src/schema/ensure-collection-policies.ts +0 -198
- package/src/schema/ensure-collection-tables.test.ts +0 -518
- package/src/schema/ensure-collection-tables.ts +0 -1267
- package/src/schema/generate-drizzle-schema-logic.ts +0 -957
- package/src/schema/generate-drizzle-schema.ts +0 -143
- package/src/schema/generate-postgres-ddl-logic.ts +0 -1339
- package/src/schema/generate-postgres-ddl.ts +0 -180
- package/src/schema/generate-schema-commit.ts +0 -267
- package/src/schema/generated-schema-staleness.ts +0 -284
- package/src/schema/introspect-db-constraints.ts +0 -385
- package/src/schema/introspect-db-inference.ts +0 -255
- package/src/schema/introspect-db-logic.ts +0 -1387
- package/src/schema/introspect-db-naming.ts +0 -15
- package/src/schema/introspect-db-project.ts +0 -78
- package/src/schema/introspect-db-queries.ts +0 -326
- package/src/schema/introspect-db-structure.ts +0 -670
- package/src/schema/introspect-db-types.ts +0 -56
- package/src/schema/introspect-db.ts +0 -257
- package/src/schema/introspect-runtime.test.ts +0 -260
- package/src/schema/introspect-runtime.ts +0 -327
- package/src/schema/non-sql-collections.test.ts +0 -131
- package/src/schema/rls-bootstrap-sql.ts +0 -288
- package/src/schema/search-column.ts +0 -643
- package/src/schema/test-schema.ts +0 -11
- package/src/schema/vector-index.ts +0 -491
- package/src/security/anonymous-grants.test.ts +0 -73
- package/src/security/policy-drift.test.ts +0 -435
- package/src/security/policy-drift.ts +0 -473
- package/src/security/rls-enforcement.ts +0 -505
- package/src/services/BranchService.ts +0 -326
- package/src/services/FetchService.ts +0 -2115
- package/src/services/PersistService.ts +0 -557
- package/src/services/RelationService.ts +0 -978
- package/src/services/RelationWriteService.ts +0 -653
- package/src/services/cdc/CdcListener.ts +0 -103
- package/src/services/cdc/junction-tables.ts +0 -91
- package/src/services/cdc/trigger-cdc.ts +0 -173
- package/src/services/channel-bus/ChannelBus.ts +0 -44
- package/src/services/channel-bus/PostgresChannelBus.ts +0 -299
- package/src/services/channel-bus/index.ts +0 -114
- package/src/services/channel-history.ts +0 -424
- package/src/services/channel-presence.ts +0 -185
- package/src/services/collection-helpers.ts +0 -420
- package/src/services/dataService.ts +0 -256
- package/src/services/index.ts +0 -14
- package/src/services/junction-writes.ts +0 -295
- package/src/services/nested-path.ts +0 -145
- package/src/services/pg-notify-listener.ts +0 -151
- package/src/services/realtimeService.ts +0 -2545
- package/src/services/row-pipeline.ts +0 -240
- package/src/services/write-denial.ts +0 -55
- package/src/types.ts +0 -4
- package/src/utils/connection-string.ts +0 -58
- package/src/utils/drizzle-conditions.ts +0 -2743
- package/src/utils/pg-array-null-patch.ts +0 -42
- package/src/utils/pg-error-utils.ts +0 -391
- package/src/websocket.ts +0 -855
package/dist/src-DiB5RP2Z.js
DELETED
|
@@ -1,541 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from "module";
|
|
2
|
-
import "process";
|
|
3
|
-
__createRequire(import.meta.url);
|
|
4
|
-
//#region ../types/src/types/filter-operators.ts
|
|
5
|
-
/** The wire spelling of a {@link RelationAggregateSort}: `min(applications.created_at)`. */
|
|
6
|
-
var RELATION_AGGREGATE_SORT_PATTERN = /^(min|max|count|sum|avg)\(([^().]+)(?:\.([^()]+))?\)$/;
|
|
7
|
-
/**
|
|
8
|
-
* A {@link RelationAggregateSort} as a single string — `min(applications.created_at)`,
|
|
9
|
-
* `count(applications)`.
|
|
10
|
-
*
|
|
11
|
-
* The wire form is a string because every layer below the call site already is
|
|
12
|
-
* one: `OrderByTuple` is `[string, direction]`, the REST parameter is
|
|
13
|
-
* `?orderBy=key:direction`, the driver contract takes `orderBy?: string |
|
|
14
|
-
* OrderByTuple[]`, and a cursor names its keys by string. `_score` established
|
|
15
|
-
* the same pattern — a sort key that is not a column, spelled as one — and this
|
|
16
|
-
* reuses it rather than widening five signatures to carry an object that would
|
|
17
|
-
* be flattened at the end anyway.
|
|
18
|
-
*
|
|
19
|
-
* SQL's own spelling, so the key reads as what it compiles to. Neither `:` nor
|
|
20
|
-
* `,` appears in it, which is what keeps it safe in the colon-delimited wire
|
|
21
|
-
* shorthand.
|
|
22
|
-
*
|
|
23
|
-
* @group Models
|
|
24
|
-
*/
|
|
25
|
-
function encodeRelationAggregateSort(sort) {
|
|
26
|
-
return `${sort.agg}(${sort.relation}${sort.field ? `.${sort.field}` : ""})`;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Read the string spelling back, or `undefined` if it is not one.
|
|
30
|
-
*
|
|
31
|
-
* `undefined` rather than a throw: this is asked of *every* sort key to find
|
|
32
|
-
* out which kind it is, and an ordinary column name is not an error.
|
|
33
|
-
*
|
|
34
|
-
* @group Models
|
|
35
|
-
*/
|
|
36
|
-
function parseRelationAggregateSort(key) {
|
|
37
|
-
const match = RELATION_AGGREGATE_SORT_PATTERN.exec(key);
|
|
38
|
-
if (!match) return void 0;
|
|
39
|
-
const [, agg, relation, field] = match;
|
|
40
|
-
if (!field && agg !== "count") return void 0;
|
|
41
|
-
return {
|
|
42
|
-
agg,
|
|
43
|
-
relation,
|
|
44
|
-
...field && { field }
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/** Is this sort key the object form rather than a field name? */
|
|
48
|
-
function isRelationAggregateSort(key) {
|
|
49
|
-
return typeof key === "object" && key !== null && typeof key.relation === "string" && typeof key.agg === "string";
|
|
50
|
-
}
|
|
51
|
-
/** A sort key in the single-string form every layer below the call site speaks. */
|
|
52
|
-
function sortKeyToString(key) {
|
|
53
|
-
return isRelationAggregateSort(key) ? encodeRelationAggregateSort(key) : key;
|
|
54
|
-
}
|
|
55
|
-
/** Maps canonical operators to their REST short-code equivalents. */
|
|
56
|
-
var CANONICAL_TO_REST = {
|
|
57
|
-
"==": "eq",
|
|
58
|
-
"!=": "neq",
|
|
59
|
-
">": "gt",
|
|
60
|
-
">=": "gte",
|
|
61
|
-
"<": "lt",
|
|
62
|
-
"<=": "lte",
|
|
63
|
-
"in": "in",
|
|
64
|
-
"not-in": "nin",
|
|
65
|
-
"array-contains": "cs",
|
|
66
|
-
"array-contains-any": "csa",
|
|
67
|
-
"like": "like",
|
|
68
|
-
"ilike": "ilike",
|
|
69
|
-
"not-like": "nlike",
|
|
70
|
-
"not-ilike": "nilike",
|
|
71
|
-
"is-null": "isnull",
|
|
72
|
-
"is-not-null": "notnull"
|
|
73
|
-
};
|
|
74
|
-
/** Maps REST short-code operators to their canonical equivalents. */
|
|
75
|
-
var REST_TO_CANONICAL = {
|
|
76
|
-
"eq": "==",
|
|
77
|
-
"neq": "!=",
|
|
78
|
-
"gt": ">",
|
|
79
|
-
"gte": ">=",
|
|
80
|
-
"lt": "<",
|
|
81
|
-
"lte": "<=",
|
|
82
|
-
"in": "in",
|
|
83
|
-
"nin": "not-in",
|
|
84
|
-
"cs": "array-contains",
|
|
85
|
-
"csa": "array-contains-any",
|
|
86
|
-
"like": "like",
|
|
87
|
-
"ilike": "ilike",
|
|
88
|
-
"nlike": "not-like",
|
|
89
|
-
"nilike": "not-ilike",
|
|
90
|
-
"isnull": "is-null",
|
|
91
|
-
"notnull": "is-not-null"
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Operators that test for null/not-null and therefore ignore their value.
|
|
95
|
-
* Codecs normalize the value of these conditions to `null`.
|
|
96
|
-
*/
|
|
97
|
-
var NULL_OPS = /* @__PURE__ */ new Set(["is-null", "is-not-null"]);
|
|
98
|
-
/**
|
|
99
|
-
* Every canonical operator, in a stable order. Useful for engine capability
|
|
100
|
-
* declarations ({@link DataSourceCapabilities.filterOperators}) and for
|
|
101
|
-
* building operator subsets.
|
|
102
|
-
* @group Models
|
|
103
|
-
*/
|
|
104
|
-
var ALL_WHERE_FILTER_OPS = [
|
|
105
|
-
"<",
|
|
106
|
-
"<=",
|
|
107
|
-
"==",
|
|
108
|
-
"!=",
|
|
109
|
-
">=",
|
|
110
|
-
">",
|
|
111
|
-
"in",
|
|
112
|
-
"not-in",
|
|
113
|
-
"array-contains",
|
|
114
|
-
"array-contains-any",
|
|
115
|
-
"like",
|
|
116
|
-
"ilike",
|
|
117
|
-
"not-like",
|
|
118
|
-
"not-ilike",
|
|
119
|
-
"is-null",
|
|
120
|
-
"is-not-null"
|
|
121
|
-
];
|
|
122
|
-
/** All canonical operator strings for runtime validation. */
|
|
123
|
-
var CANONICAL_OPS = new Set(ALL_WHERE_FILTER_OPS);
|
|
124
|
-
/**
|
|
125
|
-
* The REST table as a `Map`, because the key `toCanonicalOp` is handed comes
|
|
126
|
-
* off the wire.
|
|
127
|
-
*
|
|
128
|
-
* Indexed as a plain object, every `Object.prototype` member answered:
|
|
129
|
-
* `toCanonicalOp("valueOf")` returned the inherited *function* as though it
|
|
130
|
-
* were a `WhereFilterOp`, and every caller here treats a defined result as
|
|
131
|
-
* "known operator". Same defect the REST codec's own lookup tables were
|
|
132
|
-
* converted away from in `filter-dialect.ts`; this is the copy that survived
|
|
133
|
-
* one package over, and it now sits under the operator validation the REST
|
|
134
|
-
* parser does, which would otherwise have admitted `["constructor", x]`.
|
|
135
|
-
*/
|
|
136
|
-
var REST_OP_LOOKUP = new Map(Object.entries(REST_TO_CANONICAL));
|
|
137
|
-
/**
|
|
138
|
-
* Resolve any operator string (canonical or REST short-code) to its
|
|
139
|
-
* canonical `WhereFilterOp` form. Returns `undefined` for unknown operators.
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* toCanonicalOp("==") // "=="
|
|
143
|
-
* toCanonicalOp("eq") // "=="
|
|
144
|
-
* toCanonicalOp("cs") // "array-contains"
|
|
145
|
-
* toCanonicalOp("xyz") // undefined
|
|
146
|
-
*/
|
|
147
|
-
function toCanonicalOp(op) {
|
|
148
|
-
if (CANONICAL_OPS.has(op)) return op;
|
|
149
|
-
return REST_OP_LOOKUP.get(op);
|
|
150
|
-
}
|
|
151
|
-
//#endregion
|
|
152
|
-
//#region ../types/src/types/data_source.ts
|
|
153
|
-
/**
|
|
154
|
-
* The default data-source key, used when a collection does not name a
|
|
155
|
-
* `dataSource`. Shared by the frontend router and the backend driver
|
|
156
|
-
* registry so both agree on "the default database".
|
|
157
|
-
* @group Models
|
|
158
|
-
*/
|
|
159
|
-
var DEFAULT_DATA_SOURCE_KEY = "(default)";
|
|
160
|
-
/**
|
|
161
|
-
* Relation kinds assumed filterable when a driver does not say.
|
|
162
|
-
*
|
|
163
|
-
* `belongsTo` alone: its filter is a comparison on a column of the row being
|
|
164
|
-
* filtered, the one shape that needs no query construction a driver might not
|
|
165
|
-
* have. Everything else is a correlated subquery over another table.
|
|
166
|
-
*
|
|
167
|
-
* @group Models
|
|
168
|
-
*/
|
|
169
|
-
var DEFAULT_FILTERABLE_RELATION_KINDS = ["belongsTo"];
|
|
170
|
-
/** @group Models */
|
|
171
|
-
var POSTGRES_CAPABILITIES = {
|
|
172
|
-
key: "postgres",
|
|
173
|
-
label: "PostgreSQL",
|
|
174
|
-
supportsRelations: true,
|
|
175
|
-
supportsSubcollections: false,
|
|
176
|
-
supportsRLS: true,
|
|
177
|
-
supportsReferences: false,
|
|
178
|
-
supportsColumnTypes: true,
|
|
179
|
-
supportsRealtime: true,
|
|
180
|
-
supportsVectors: true,
|
|
181
|
-
filterOperators: ALL_WHERE_FILTER_OPS,
|
|
182
|
-
filterableRelationKinds: [
|
|
183
|
-
"belongsTo",
|
|
184
|
-
"manyToMany",
|
|
185
|
-
"hasMany",
|
|
186
|
-
"hasOne"
|
|
187
|
-
],
|
|
188
|
-
supportsRelationFieldFilters: true,
|
|
189
|
-
relationAggregateSorts: true,
|
|
190
|
-
supportsSQLAdmin: true,
|
|
191
|
-
supportsDocumentAdmin: false,
|
|
192
|
-
supportsSchemaAdmin: true
|
|
193
|
-
};
|
|
194
|
-
/** @group Models */
|
|
195
|
-
var FIREBASE_CAPABILITIES = {
|
|
196
|
-
key: "firestore",
|
|
197
|
-
label: "Firebase / Firestore",
|
|
198
|
-
supportsRelations: false,
|
|
199
|
-
supportsSubcollections: true,
|
|
200
|
-
supportsRLS: false,
|
|
201
|
-
supportsReferences: true,
|
|
202
|
-
supportsColumnTypes: false,
|
|
203
|
-
supportsRealtime: true,
|
|
204
|
-
supportsVectors: false,
|
|
205
|
-
filterOperators: ALL_WHERE_FILTER_OPS.filter((op) => op !== "like" && op !== "ilike" && op !== "not-like" && op !== "not-ilike"),
|
|
206
|
-
filterableRelationKinds: [],
|
|
207
|
-
supportsRelationFieldFilters: false,
|
|
208
|
-
relationAggregateSorts: false,
|
|
209
|
-
supportsSQLAdmin: false,
|
|
210
|
-
supportsDocumentAdmin: false,
|
|
211
|
-
supportsSchemaAdmin: false
|
|
212
|
-
};
|
|
213
|
-
/** @group Models */
|
|
214
|
-
var MONGODB_CAPABILITIES = {
|
|
215
|
-
key: "mongodb",
|
|
216
|
-
label: "MongoDB",
|
|
217
|
-
supportsRelations: false,
|
|
218
|
-
supportsSubcollections: true,
|
|
219
|
-
supportsRLS: false,
|
|
220
|
-
supportsReferences: true,
|
|
221
|
-
supportsColumnTypes: false,
|
|
222
|
-
supportsRealtime: false,
|
|
223
|
-
supportsVectors: false,
|
|
224
|
-
filterOperators: ALL_WHERE_FILTER_OPS,
|
|
225
|
-
filterableRelationKinds: [],
|
|
226
|
-
supportsRelationFieldFilters: false,
|
|
227
|
-
relationAggregateSorts: false,
|
|
228
|
-
supportsSQLAdmin: false,
|
|
229
|
-
supportsDocumentAdmin: true,
|
|
230
|
-
supportsSchemaAdmin: true
|
|
231
|
-
};
|
|
232
|
-
/**
|
|
233
|
-
* Fallback capabilities when the driver is unknown.
|
|
234
|
-
* Enables everything so nothing is hidden unexpectedly.
|
|
235
|
-
* @group Models
|
|
236
|
-
*/
|
|
237
|
-
var DEFAULT_CAPABILITIES = {
|
|
238
|
-
key: "(default)",
|
|
239
|
-
label: "Default",
|
|
240
|
-
supportsRelations: true,
|
|
241
|
-
supportsSubcollections: true,
|
|
242
|
-
supportsRLS: true,
|
|
243
|
-
supportsReferences: true,
|
|
244
|
-
supportsColumnTypes: true,
|
|
245
|
-
supportsRealtime: true,
|
|
246
|
-
supportsVectors: true,
|
|
247
|
-
filterOperators: ALL_WHERE_FILTER_OPS,
|
|
248
|
-
filterableRelationKinds: DEFAULT_FILTERABLE_RELATION_KINDS,
|
|
249
|
-
supportsRelationFieldFilters: false,
|
|
250
|
-
relationAggregateSorts: false,
|
|
251
|
-
supportsSQLAdmin: true,
|
|
252
|
-
supportsDocumentAdmin: true,
|
|
253
|
-
supportsSchemaAdmin: true
|
|
254
|
-
};
|
|
255
|
-
var CAPABILITIES_REGISTRY = {
|
|
256
|
-
postgres: POSTGRES_CAPABILITIES,
|
|
257
|
-
firestore: FIREBASE_CAPABILITIES,
|
|
258
|
-
mongodb: MONGODB_CAPABILITIES,
|
|
259
|
-
"(default)": DEFAULT_CAPABILITIES
|
|
260
|
-
};
|
|
261
|
-
/**
|
|
262
|
-
* Look up capabilities for a given engine key.
|
|
263
|
-
* If `engine` is undefined or not found, returns `DEFAULT_CAPABILITIES`.
|
|
264
|
-
* @group Models
|
|
265
|
-
*/
|
|
266
|
-
function getDataSourceCapabilities(engine) {
|
|
267
|
-
if (!engine) return POSTGRES_CAPABILITIES;
|
|
268
|
-
return CAPABILITIES_REGISTRY[engine] ?? DEFAULT_CAPABILITIES;
|
|
269
|
-
}
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region ../types/src/types/collections.ts
|
|
272
|
-
/**
|
|
273
|
-
* Type guard for PostgreSQL collections.
|
|
274
|
-
* Returns true if the collection uses the Postgres engine (or the default engine).
|
|
275
|
-
*
|
|
276
|
-
* Generic over the *input* type, and narrows by intersection rather than
|
|
277
|
-
* replacement. Narrowing to a bare `PostgresCollectionConfig` discarded whatever
|
|
278
|
-
* the caller actually had — most visibly the admin panel's view model, whose
|
|
279
|
-
* flattened presentation fields vanished the moment a collection passed through
|
|
280
|
-
* one of these guards.
|
|
281
|
-
*
|
|
282
|
-
* @group Models
|
|
283
|
-
*/
|
|
284
|
-
function isPostgresCollectionConfig(collection) {
|
|
285
|
-
return !collection.engine || collection.engine === "postgres";
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Narrows to the SQL collection fields — `table`, `relations`,
|
|
289
|
-
* `disableDefaultPolicies` — by asking the engine's declared capabilities
|
|
290
|
-
* rather than by naming Postgres.
|
|
291
|
-
*
|
|
292
|
-
* The two halves of this already existed and were never joined. The engine
|
|
293
|
-
* split (`PostgresCollectionConfig` / `FirebaseCollectionConfig` /
|
|
294
|
-
* `MongoDBCollectionConfig`) said which fields belong to which engine at the
|
|
295
|
-
* type level; {@link DataSourceCapabilities} said the same thing at runtime,
|
|
296
|
-
* down to a `supportsRelations` flag. So call sites guarded on the capability
|
|
297
|
-
* and then read a field the base type had to declare for them — which is why
|
|
298
|
-
* those fields were on the base, and why a MongoDB collection could be written
|
|
299
|
-
* with a `table`.
|
|
300
|
-
*
|
|
301
|
-
* Prefer this over {@link isPostgresCollectionConfig} wherever the question is
|
|
302
|
-
* "does this collection live in a SQL table", so a custom SQL engine
|
|
303
|
-
* registered through `registerDataSourceCapabilities` is included.
|
|
304
|
-
*
|
|
305
|
-
* @group Models
|
|
306
|
-
*/
|
|
307
|
-
function isRelationalCollectionConfig(collection) {
|
|
308
|
-
return getDataSourceCapabilities(collection.engine).supportsRelations;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Reads a collection's driver-declared subcollections thunk (the `subcollections`
|
|
312
|
-
* field) independent of engine identity, so engine-agnostic code doesn't have to
|
|
313
|
-
* type-guard against a specific driver. Returns `undefined` when the collection
|
|
314
|
-
* declares none.
|
|
315
|
-
*
|
|
316
|
-
* Pair with `getDataSourceCapabilities(engine).supportsSubcollections` to decide
|
|
317
|
-
* whether the engine honours subcollections at all before reading them.
|
|
318
|
-
* @group Models
|
|
319
|
-
*/
|
|
320
|
-
function getDeclaredSubcollections(collection) {
|
|
321
|
-
return collection.subcollections;
|
|
322
|
-
}
|
|
323
|
-
//#endregion
|
|
324
|
-
//#region ../types/src/types/rls-functions.ts
|
|
325
|
-
/**
|
|
326
|
-
* The SQL helper functions RLS policies call, and the schema they live in.
|
|
327
|
-
*
|
|
328
|
-
* ## One schema, and it is ours
|
|
329
|
-
*
|
|
330
|
-
* Rebase creates exactly one schema in a project's database: `rebase`. These
|
|
331
|
-
* three functions live in it alongside the framework's own tables, and that is
|
|
332
|
-
* the whole contract — a reader can look at a database and know precisely which
|
|
333
|
-
* namespace belongs to the framework and that nothing else was touched.
|
|
334
|
-
*
|
|
335
|
-
* It used to be two. `uid()`, `jwt()` and `roles()` sat in a schema called
|
|
336
|
-
* `auth`, which is Supabase's name, chosen so that a developer who had written
|
|
337
|
-
* Supabase RLS would recognise `auth.uid()`. The familiarity was real but the
|
|
338
|
-
* name was not Rebase's to take, and taking it had a concrete cost: pointing
|
|
339
|
-
* Rebase at a database that already had a Supabase `auth` schema meant
|
|
340
|
-
* `CREATE OR REPLACE FUNCTION auth.uid() RETURNS text` against Supabase's
|
|
341
|
-
* `RETURNS uuid`, which Postgres rejects outright —
|
|
342
|
-
*
|
|
343
|
-
* ERROR: cannot change return type of existing function
|
|
344
|
-
* HINT: Use DROP FUNCTION auth.uid() first.
|
|
345
|
-
*
|
|
346
|
-
* — and the failure landed inside a catch-all that logged a warning and carried
|
|
347
|
-
* on, leaving a database with auth tables, no helper functions, and policies
|
|
348
|
-
* calling functions that did not exist. Under `rebase db migrate` the same
|
|
349
|
-
* statements aborted the migration instead.
|
|
350
|
-
*
|
|
351
|
-
* `rebase.uid()` collides with nobody. A Supabase database keeps its `auth`
|
|
352
|
-
* schema untouched and gains a `rebase` one, which is what a gradual migration
|
|
353
|
-
* needs.
|
|
354
|
-
*
|
|
355
|
-
* ## Why functions at all, rather than inlining `current_setting`
|
|
356
|
-
*
|
|
357
|
-
* Because the indirection has already been spent once. `uid()` resolves
|
|
358
|
-
* `app.uid` and falls back to the pre-rename `app.user_id`, so that during a
|
|
359
|
-
* rolling deploy — old and new pods serving one database — both eras resolve
|
|
360
|
-
* the principal. That was a single `CREATE OR REPLACE`. Inlined into policy
|
|
361
|
-
* bodies it would have been a rewrite of every policy on every table.
|
|
362
|
-
*
|
|
363
|
-
* ## Why the name is not configurable
|
|
364
|
-
*
|
|
365
|
-
* A policy body is stored SQL: Postgres parses `USING (…)` once and keeps it, so
|
|
366
|
-
* these strings are written into every policy in every database Rebase has
|
|
367
|
-
* provisioned. Everything that reads policies back — the SQL-to-policy parser
|
|
368
|
-
* behind the admin UI, the drift checker, `rls-check` — would have to know the
|
|
369
|
-
* configured value to recognise its own output. One frozen name is the feature.
|
|
370
|
-
*/
|
|
371
|
-
/** The schema Rebase owns. The only schema Rebase creates. */
|
|
372
|
-
var REBASE_SCHEMA = "rebase";
|
|
373
|
-
/**
|
|
374
|
-
* The principal of the current request, as text, or NULL in the server context.
|
|
375
|
-
*
|
|
376
|
-
* Never NULL for a user request — an anonymous one carries
|
|
377
|
-
* {@link ANONYMOUS_USER_ID} — which is what makes `IS NULL` a reliable test for
|
|
378
|
-
* the trusted server plane and `IS NOT NULL` a tautology.
|
|
379
|
-
*/
|
|
380
|
-
var RLS_UID_SQL = `${REBASE_SCHEMA}.uid()`;
|
|
381
|
-
/** The request's roles as a comma-separated string, for `string_to_array`. */
|
|
382
|
-
var RLS_ROLES_SQL = `${REBASE_SCHEMA}.roles()`;
|
|
383
|
-
`${REBASE_SCHEMA}`;
|
|
384
|
-
/**
|
|
385
|
-
* The pre-1.0 spellings, for recognising policies and hand-written SQL that
|
|
386
|
-
* predate the move.
|
|
387
|
-
*
|
|
388
|
-
* Kept because policies outlive the server that wrote them: a database migrated
|
|
389
|
-
* by an older release still holds `auth.uid()` in its policy bodies until the
|
|
390
|
-
* next push or boot recompiles them, and anything that reads policies back has
|
|
391
|
-
* to recognise both eras or report the framework's own output as foreign drift.
|
|
392
|
-
* Also used to give a project whose `securityRules` contain raw `auth.uid()` a
|
|
393
|
-
* message naming the replacement, instead of a parse failure.
|
|
394
|
-
*/
|
|
395
|
-
var LEGACY_RLS_SCHEMA = "auth";
|
|
396
|
-
`${LEGACY_RLS_SCHEMA}`;
|
|
397
|
-
`${LEGACY_RLS_SCHEMA}`;
|
|
398
|
-
`${LEGACY_RLS_SCHEMA}`;
|
|
399
|
-
/**
|
|
400
|
-
* Rewrites the pre-1.0 function calls in a fragment of policy SQL.
|
|
401
|
-
*
|
|
402
|
-
* Deliberately anchored on a word boundary and the schema qualifier, so a column
|
|
403
|
-
* called `auth_uid` or a table named `auth` is left alone.
|
|
404
|
-
*/
|
|
405
|
-
function rewriteLegacyRlsFunctions(sql) {
|
|
406
|
-
return sql.replace(/\bauth\.(uid|jwt|roles)\s*\(\s*\)/gi, (_match, fn) => `${REBASE_SCHEMA}.${fn.toLowerCase()}()`);
|
|
407
|
-
}
|
|
408
|
-
/** Whether a fragment of SQL still calls the pre-1.0 functions. */
|
|
409
|
-
function usesLegacyRlsFunctions(sql) {
|
|
410
|
-
return /\bauth\.(uid|jwt|roles)\s*\(\s*\)/i.test(sql);
|
|
411
|
-
}
|
|
412
|
-
//#endregion
|
|
413
|
-
//#region ../types/src/types/resources.ts
|
|
414
|
-
var GLOBAL_KEY = Symbol.for("@rebasepro/types.resourceRegistry");
|
|
415
|
-
function registry() {
|
|
416
|
-
const g = globalThis;
|
|
417
|
-
let existing = g[GLOBAL_KEY];
|
|
418
|
-
if (!existing) {
|
|
419
|
-
existing = {
|
|
420
|
-
kinds: /* @__PURE__ */ new Map(),
|
|
421
|
-
declarations: /* @__PURE__ */ new Map()
|
|
422
|
-
};
|
|
423
|
-
g[GLOBAL_KEY] = existing;
|
|
424
|
-
}
|
|
425
|
-
return existing;
|
|
426
|
-
}
|
|
427
|
-
/** Register a resource kind. Idempotent for an identical spec; throws on a conflicting one. */
|
|
428
|
-
function registerResourceKind(spec) {
|
|
429
|
-
const existing = registry().kinds.get(spec.kind);
|
|
430
|
-
if (existing && JSON.stringify(existing) !== JSON.stringify(spec)) throw new Error(`Resource kind "${spec.kind}" is already registered with a different definition. Two packages cannot define the same kind.`);
|
|
431
|
-
registry().kinds.set(spec.kind, spec);
|
|
432
|
-
}
|
|
433
|
-
/** Every declared resource, in declaration order, optionally filtered by kind. */
|
|
434
|
-
function declaredResources(kind) {
|
|
435
|
-
const all = [...registry().declarations.values()];
|
|
436
|
-
return kind ? all.filter((r) => r.kind === kind) : all;
|
|
437
|
-
}
|
|
438
|
-
//#endregion
|
|
439
|
-
//#region ../types/src/types/resource_kinds.ts
|
|
440
|
-
/**
|
|
441
|
-
* The kinds Rebase ships, and the constructors a project declares them with.
|
|
442
|
-
*
|
|
443
|
-
* Each kind is registered rather than hardcoded, so a fourth one arrives
|
|
444
|
-
* without editing a manifest schema, a validator and a switch statement. That
|
|
445
|
-
* cost is precisely why databases and buckets ended up declared in different
|
|
446
|
-
* files with different rules — the cheapest thing to do was always to bolt the
|
|
447
|
-
* new kind onto whichever home was nearest.
|
|
448
|
-
*
|
|
449
|
-
* A kind owns its engine list. `custom:<id>` is always accepted, so a build
|
|
450
|
-
* that ships an engine this package has never heard of says so at the call site
|
|
451
|
-
* instead of looking like a typo of one that exists.
|
|
452
|
-
*/
|
|
453
|
-
registerResourceKind({
|
|
454
|
-
kind: "database",
|
|
455
|
-
engines: [
|
|
456
|
-
"postgres",
|
|
457
|
-
"mongodb",
|
|
458
|
-
"firestore",
|
|
459
|
-
"sqlite"
|
|
460
|
-
],
|
|
461
|
-
defaultEngine: "postgres",
|
|
462
|
-
envBases: [
|
|
463
|
-
"DATABASE_URL",
|
|
464
|
-
"REBASE_DRIVER",
|
|
465
|
-
"REBASE_DB_POOL_MAX"
|
|
466
|
-
],
|
|
467
|
-
optionKeys: [
|
|
468
|
-
"databaseId",
|
|
469
|
-
"migrations",
|
|
470
|
-
"extensions"
|
|
471
|
-
],
|
|
472
|
-
implicitDefault: true
|
|
473
|
-
});
|
|
474
|
-
/**
|
|
475
|
-
* The extensions the project's databases gave Rebase leave to install.
|
|
476
|
-
*
|
|
477
|
-
* A flat union rather than a per-database answer, because the surfaces that ask
|
|
478
|
-
* — `rebase db push` and the boot schema-ensure — drive one connection and
|
|
479
|
-
* generate one `schema.sql` for every collection regardless of `dataSource`.
|
|
480
|
-
* Splitting the permission by data source would be a distinction the rest of
|
|
481
|
-
* that pipeline does not make, and a false precision is worse than none.
|
|
482
|
-
*
|
|
483
|
-
* Empty for a project that declared nothing, which is every project that has
|
|
484
|
-
* not opted in — so this reads as a refusal by default, on purpose.
|
|
485
|
-
*/
|
|
486
|
-
function declaredDatabaseExtensions() {
|
|
487
|
-
const names = /* @__PURE__ */ new Set();
|
|
488
|
-
for (const declaration of declaredResources("database")) {
|
|
489
|
-
const declared = declaration.options.extensions;
|
|
490
|
-
if (!Array.isArray(declared)) continue;
|
|
491
|
-
for (const name of declared) if (typeof name === "string" && name.trim()) names.add(name.trim());
|
|
492
|
-
}
|
|
493
|
-
return [...names].sort();
|
|
494
|
-
}
|
|
495
|
-
registerResourceKind({
|
|
496
|
-
kind: "bucket",
|
|
497
|
-
engines: [
|
|
498
|
-
"local",
|
|
499
|
-
"s3",
|
|
500
|
-
"gcs",
|
|
501
|
-
"azure",
|
|
502
|
-
"firebase"
|
|
503
|
-
],
|
|
504
|
-
defaultEngine: "local",
|
|
505
|
-
envBases: [
|
|
506
|
-
"S3_BUCKET",
|
|
507
|
-
"GCS_BUCKET",
|
|
508
|
-
"STORAGE_BUCKET",
|
|
509
|
-
"STORAGE_PUBLIC_URL"
|
|
510
|
-
],
|
|
511
|
-
envBasesByEngine: {
|
|
512
|
-
local: ["STORAGE_BUCKET"],
|
|
513
|
-
s3: [
|
|
514
|
-
"S3_BUCKET",
|
|
515
|
-
"STORAGE_ENDPOINT",
|
|
516
|
-
"STORAGE_REGION",
|
|
517
|
-
"STORAGE_PUBLIC_URL"
|
|
518
|
-
],
|
|
519
|
-
gcs: ["GCS_BUCKET", "STORAGE_PUBLIC_URL"],
|
|
520
|
-
azure: ["STORAGE_BUCKET", "STORAGE_PUBLIC_URL"],
|
|
521
|
-
firebase: ["STORAGE_BUCKET", "STORAGE_PUBLIC_URL"]
|
|
522
|
-
},
|
|
523
|
-
optionKeys: [
|
|
524
|
-
"publicRead",
|
|
525
|
-
"prefix",
|
|
526
|
-
"account"
|
|
527
|
-
],
|
|
528
|
-
implicitDefault: false
|
|
529
|
-
});
|
|
530
|
-
registerResourceKind({
|
|
531
|
-
kind: "topic",
|
|
532
|
-
engines: ["jobs"],
|
|
533
|
-
defaultEngine: "jobs",
|
|
534
|
-
envBases: ["REBASE_TOPIC_URL"],
|
|
535
|
-
optionKeys: ["delivery", "maxAttempts"],
|
|
536
|
-
implicitDefault: false
|
|
537
|
-
});
|
|
538
|
-
//#endregion
|
|
539
|
-
export { encodeRelationAggregateSort as _, RLS_UID_SQL as a, sortKeyToString as b, getDeclaredSubcollections as c, DEFAULT_DATA_SOURCE_KEY as d, getDataSourceCapabilities as f, REST_TO_CANONICAL as g, NULL_OPS as h, RLS_ROLES_SQL as i, isPostgresCollectionConfig as l, CANONICAL_TO_REST as m, LEGACY_RLS_SCHEMA as n, rewriteLegacyRlsFunctions as o, ALL_WHERE_FILTER_OPS as p, REBASE_SCHEMA as r, usesLegacyRlsFunctions as s, declaredDatabaseExtensions as t, isRelationalCollectionConfig as u, isRelationAggregateSort as v, toCanonicalOp as x, parseRelationAggregateSort as y };
|
|
540
|
-
|
|
541
|
-
//# sourceMappingURL=src-DiB5RP2Z.js.map
|