@rebasepro/types 0.13.0 → 0.13.1-canary.g18cfeb7
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/call_context.d.ts +61 -4
- package/dist/controllers/client.d.ts +16 -59
- package/dist/controllers/data.d.ts +150 -16
- package/dist/controllers/data_driver.d.ts +44 -0
- package/dist/errors.d.ts +30 -4
- package/dist/index.es.js +97 -5
- package/dist/index.es.js.map +1 -1
- package/dist/types/admin_block.d.ts +1 -1
- package/dist/types/collections.d.ts +21 -3
- package/dist/types/cron.d.ts +50 -9
- package/dist/types/entity_callbacks.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/policy.d.ts +13 -13
- package/dist/types/properties.d.ts +22 -4
- package/dist/types/rls-functions.d.ts +84 -0
- package/package.json +2 -2
- package/src/call_context.ts +59 -4
- package/src/controllers/client.ts +16 -80
- package/src/controllers/data.ts +148 -16
- package/src/controllers/data_driver.ts +45 -0
- package/src/errors.ts +43 -4
- package/src/types/admin_block.ts +2 -0
- package/src/types/collections.ts +21 -3
- package/src/types/cron.ts +51 -9
- package/src/types/entity_callbacks.ts +2 -1
- package/src/types/index.ts +1 -0
- package/src/types/policy.ts +13 -13
- package/src/types/properties.ts +23 -4
- package/src/types/rls-functions.ts +98 -0
package/dist/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
var RebaseApiError = class extends Error {
|
|
27
27
|
/** HTTP status code, or `undefined` for non-HTTP errors. */
|
|
28
28
|
status;
|
|
29
|
-
/** Stable machine-readable error code, when the server supplied one. */
|
|
29
|
+
/** Stable machine-readable error code, when the server supplied one. See {@link RebaseErrorCode}. */
|
|
30
30
|
code;
|
|
31
31
|
/** Structured error payload from the server, when present. */
|
|
32
32
|
details;
|
|
@@ -307,6 +307,7 @@ var ADMIN_COLLECTION_KEYS = [
|
|
|
307
307
|
"defaultSize",
|
|
308
308
|
"defaultViewMode",
|
|
309
309
|
"disableDefaultActions",
|
|
310
|
+
"display",
|
|
310
311
|
"enabledViews",
|
|
311
312
|
"entityActions",
|
|
312
313
|
"entityViews",
|
|
@@ -317,6 +318,7 @@ var ADMIN_COLLECTION_KEYS = [
|
|
|
317
318
|
"formAutoSave",
|
|
318
319
|
"formView",
|
|
319
320
|
"group",
|
|
321
|
+
"hideFromEntityViews",
|
|
320
322
|
"hideFromNavigation",
|
|
321
323
|
"hideIdFromCollection",
|
|
322
324
|
"hideIdFromForm",
|
|
@@ -593,7 +595,7 @@ function isToMany(relation) {
|
|
|
593
595
|
//#endregion
|
|
594
596
|
//#region src/types/policy.ts
|
|
595
597
|
/**
|
|
596
|
-
* The id a request without a logged-in user reports as `
|
|
598
|
+
* The id a request without a logged-in user reports as `rebase.uid()`.
|
|
597
599
|
*
|
|
598
600
|
* A user-context request always sets `app.uid`: blank would read back as
|
|
599
601
|
* `NULL`, and `NULL` is how the trusted server context is recognised, so an
|
|
@@ -601,7 +603,7 @@ function isToMany(relation) {
|
|
|
601
603
|
* therefore substitutes this sentinel at the single chokepoint where the GUC
|
|
602
604
|
* is set.
|
|
603
605
|
*
|
|
604
|
-
* The consequence for policy authors is that **`
|
|
606
|
+
* The consequence for policy authors is that **`rebase.uid() IS NOT NULL` is a
|
|
605
607
|
* tautology on the user path** — it is true for anonymous visitors too. Use
|
|
606
608
|
* {@link policy.authenticated} to mean "signed in", and
|
|
607
609
|
* {@link policy.serverContext} to mean "the trusted server context". Do not
|
|
@@ -618,7 +620,7 @@ var ANONYMOUS_USER_ID = "anonymous";
|
|
|
618
620
|
* JavaScript evaluator and the linter were all built on
|
|
619
621
|
* {@link ANONYMOUS_USER_ID}, while the request path scoped unauthenticated
|
|
620
622
|
* callers as `'anon'` — so `policy.authenticated()`, which compiled to
|
|
621
|
-
* `
|
|
623
|
+
* `rebase.uid() <> 'anonymous'`, was *true* for an anonymous visitor. The
|
|
622
624
|
* sanctioned way to write "signed in" granted to everyone, and the linter
|
|
623
625
|
* flagged the spelling that actually worked as a foreign convention.
|
|
624
626
|
*
|
|
@@ -700,6 +702,96 @@ var policy = {
|
|
|
700
702
|
authRoles: () => ({ kind: "authRoles" })
|
|
701
703
|
};
|
|
702
704
|
//#endregion
|
|
705
|
+
//#region src/types/rls-functions.ts
|
|
706
|
+
/**
|
|
707
|
+
* The SQL helper functions RLS policies call, and the schema they live in.
|
|
708
|
+
*
|
|
709
|
+
* ## One schema, and it is ours
|
|
710
|
+
*
|
|
711
|
+
* Rebase creates exactly one schema in a project's database: `rebase`. These
|
|
712
|
+
* three functions live in it alongside the framework's own tables, and that is
|
|
713
|
+
* the whole contract — a reader can look at a database and know precisely which
|
|
714
|
+
* namespace belongs to the framework and that nothing else was touched.
|
|
715
|
+
*
|
|
716
|
+
* It used to be two. `uid()`, `jwt()` and `roles()` sat in a schema called
|
|
717
|
+
* `auth`, which is Supabase's name, chosen so that a developer who had written
|
|
718
|
+
* Supabase RLS would recognise `auth.uid()`. The familiarity was real but the
|
|
719
|
+
* name was not Rebase's to take, and taking it had a concrete cost: pointing
|
|
720
|
+
* Rebase at a database that already had a Supabase `auth` schema meant
|
|
721
|
+
* `CREATE OR REPLACE FUNCTION auth.uid() RETURNS text` against Supabase's
|
|
722
|
+
* `RETURNS uuid`, which Postgres rejects outright —
|
|
723
|
+
*
|
|
724
|
+
* ERROR: cannot change return type of existing function
|
|
725
|
+
* HINT: Use DROP FUNCTION auth.uid() first.
|
|
726
|
+
*
|
|
727
|
+
* — and the failure landed inside a catch-all that logged a warning and carried
|
|
728
|
+
* on, leaving a database with auth tables, no helper functions, and policies
|
|
729
|
+
* calling functions that did not exist. Under `rebase db migrate` the same
|
|
730
|
+
* statements aborted the migration instead.
|
|
731
|
+
*
|
|
732
|
+
* `rebase.uid()` collides with nobody. A Supabase database keeps its `auth`
|
|
733
|
+
* schema untouched and gains a `rebase` one, which is what a gradual migration
|
|
734
|
+
* needs.
|
|
735
|
+
*
|
|
736
|
+
* ## Why functions at all, rather than inlining `current_setting`
|
|
737
|
+
*
|
|
738
|
+
* Because the indirection has already been spent once. `uid()` resolves
|
|
739
|
+
* `app.uid` and falls back to the pre-rename `app.user_id`, so that during a
|
|
740
|
+
* rolling deploy — old and new pods serving one database — both eras resolve
|
|
741
|
+
* the principal. That was a single `CREATE OR REPLACE`. Inlined into policy
|
|
742
|
+
* bodies it would have been a rewrite of every policy on every table.
|
|
743
|
+
*
|
|
744
|
+
* ## Why the name is not configurable
|
|
745
|
+
*
|
|
746
|
+
* A policy body is stored SQL: Postgres parses `USING (…)` once and keeps it, so
|
|
747
|
+
* these strings are written into every policy in every database Rebase has
|
|
748
|
+
* provisioned. Everything that reads policies back — the SQL-to-policy parser
|
|
749
|
+
* behind the admin UI, the drift checker, `rls-check` — would have to know the
|
|
750
|
+
* configured value to recognise its own output. One frozen name is the feature.
|
|
751
|
+
*/
|
|
752
|
+
/** The schema Rebase owns. The only schema Rebase creates. */
|
|
753
|
+
var REBASE_SCHEMA = "rebase";
|
|
754
|
+
/**
|
|
755
|
+
* The principal of the current request, as text, or NULL in the server context.
|
|
756
|
+
*
|
|
757
|
+
* Never NULL for a user request — an anonymous one carries
|
|
758
|
+
* {@link ANONYMOUS_USER_ID} — which is what makes `IS NULL` a reliable test for
|
|
759
|
+
* the trusted server plane and `IS NOT NULL` a tautology.
|
|
760
|
+
*/
|
|
761
|
+
var RLS_UID_SQL = `${REBASE_SCHEMA}.uid()`;
|
|
762
|
+
/** The request's roles as a comma-separated string, for `string_to_array`. */
|
|
763
|
+
var RLS_ROLES_SQL = `${REBASE_SCHEMA}.roles()`;
|
|
764
|
+
/** The request's JWT claims as `jsonb`, or `{}`. */
|
|
765
|
+
var RLS_JWT_SQL = `${REBASE_SCHEMA}.jwt()`;
|
|
766
|
+
/**
|
|
767
|
+
* The pre-1.0 spellings, for recognising policies and hand-written SQL that
|
|
768
|
+
* predate the move.
|
|
769
|
+
*
|
|
770
|
+
* Kept because policies outlive the server that wrote them: a database migrated
|
|
771
|
+
* by an older release still holds `auth.uid()` in its policy bodies until the
|
|
772
|
+
* next push or boot recompiles them, and anything that reads policies back has
|
|
773
|
+
* to recognise both eras or report the framework's own output as foreign drift.
|
|
774
|
+
* Also used to give a project whose `securityRules` contain raw `auth.uid()` a
|
|
775
|
+
* message naming the replacement, instead of a parse failure.
|
|
776
|
+
*/
|
|
777
|
+
var LEGACY_RLS_SCHEMA = "auth";
|
|
778
|
+
var LEGACY_RLS_UID_SQL = `${LEGACY_RLS_SCHEMA}.uid()`;
|
|
779
|
+
var LEGACY_RLS_ROLES_SQL = `${LEGACY_RLS_SCHEMA}.roles()`;
|
|
780
|
+
var LEGACY_RLS_JWT_SQL = `${LEGACY_RLS_SCHEMA}.jwt()`;
|
|
781
|
+
/**
|
|
782
|
+
* Rewrites the pre-1.0 function calls in a fragment of policy SQL.
|
|
783
|
+
*
|
|
784
|
+
* Deliberately anchored on a word boundary and the schema qualifier, so a column
|
|
785
|
+
* called `auth_uid` or a table named `auth` is left alone.
|
|
786
|
+
*/
|
|
787
|
+
function rewriteLegacyRlsFunctions(sql) {
|
|
788
|
+
return sql.replace(/\bauth\.(uid|jwt|roles)\s*\(\s*\)/gi, (_match, fn) => `${REBASE_SCHEMA}.${fn.toLowerCase()}()`);
|
|
789
|
+
}
|
|
790
|
+
/** Whether a fragment of SQL still calls the pre-1.0 functions. */
|
|
791
|
+
function usesLegacyRlsFunctions(sql) {
|
|
792
|
+
return /\bauth\.(uid|jwt|roles)\s*\(\s*\)/i.test(sql);
|
|
793
|
+
}
|
|
794
|
+
//#endregion
|
|
703
795
|
//#region src/types/backend.ts
|
|
704
796
|
/**
|
|
705
797
|
* Type guard: does this admin support SQL operations?
|
|
@@ -1180,6 +1272,6 @@ function isPublicStoragePath(path) {
|
|
|
1180
1272
|
return p.startsWith("public/") || p.startsWith(`default/public/`);
|
|
1181
1273
|
}
|
|
1182
1274
|
//#endregion
|
|
1183
|
-
export { ADMIN_COLLECTION_KEYS, ADMIN_PROPERTY_KEYS, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, ANONYMOUS_USER_IDS, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DEFAULT_CAPABILITIES, DEFAULT_DATA_SOURCE_KEY, DEFAULT_FILTERABLE_RELATION_KINDS, DEFAULT_LIST_LIMIT, DEFAULT_STORAGE_SOURCE_KEY, DEFAULT_VECTOR_LIST_LIMIT, EntityReference, EntityRelation, FIREBASE_CAPABILITIES, GeoPoint, MAX_LIST_LIMIT, MONGODB_CAPABILITIES, NULL_OPS, POSTGRES_CAPABILITIES, PUBLIC_STORAGE_PREFIX, REST_TO_CANONICAL, RUNTIME_CONTRACT_VERSION, RebaseApiError, RebaseClientError, SCHEMA_VERSION_HEADER, Vector, canonicalSchemaPayload, computeSchemaVersion, deserializeCollections, findStorageSuffixCollision, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, hasForeignKeyOnTarget, isAnonymousUid, isBranchAdmin, isChannelBusInstance, isDocumentAdmin, isFirebaseCollectionConfig, isLazyComponentRef, isManyToMany, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStoragePath, isRelationalCollectionConfig, isSQLAdmin, isSchemaAdmin, isSerializedCollectionRef, isToMany, normalizeStorageSources, policy, registerDataSourceCapabilities, resolveClientListLimit, serializeCollections, storageEnvSuffix, toCanonicalOp };
|
|
1275
|
+
export { ADMIN_COLLECTION_KEYS, ADMIN_PROPERTY_KEYS, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, ANONYMOUS_USER_IDS, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DEFAULT_CAPABILITIES, DEFAULT_DATA_SOURCE_KEY, DEFAULT_FILTERABLE_RELATION_KINDS, DEFAULT_LIST_LIMIT, DEFAULT_STORAGE_SOURCE_KEY, DEFAULT_VECTOR_LIST_LIMIT, EntityReference, EntityRelation, FIREBASE_CAPABILITIES, GeoPoint, LEGACY_RLS_JWT_SQL, LEGACY_RLS_ROLES_SQL, LEGACY_RLS_SCHEMA, LEGACY_RLS_UID_SQL, MAX_LIST_LIMIT, MONGODB_CAPABILITIES, NULL_OPS, POSTGRES_CAPABILITIES, PUBLIC_STORAGE_PREFIX, REBASE_SCHEMA, REST_TO_CANONICAL, RLS_JWT_SQL, RLS_ROLES_SQL, RLS_UID_SQL, RUNTIME_CONTRACT_VERSION, RebaseApiError, RebaseClientError, SCHEMA_VERSION_HEADER, Vector, canonicalSchemaPayload, computeSchemaVersion, deserializeCollections, findStorageSuffixCollision, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, hasForeignKeyOnTarget, isAnonymousUid, isBranchAdmin, isChannelBusInstance, isDocumentAdmin, isFirebaseCollectionConfig, isLazyComponentRef, isManyToMany, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStoragePath, isRelationalCollectionConfig, isSQLAdmin, isSchemaAdmin, isSerializedCollectionRef, isToMany, normalizeStorageSources, policy, registerDataSourceCapabilities, resolveClientListLimit, rewriteLegacyRlsFunctions, serializeCollections, storageEnvSuffix, toCanonicalOp, usesLegacyRlsFunctions };
|
|
1184
1276
|
|
|
1185
1277
|
//# sourceMappingURL=index.es.js.map
|