@rebasepro/types 0.10.1-canary.a54c057 → 0.10.1-canary.bc2a92e

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.
Files changed (94) hide show
  1. package/dist/call_context.d.ts +51 -0
  2. package/dist/controllers/auth_state.d.ts +23 -0
  3. package/dist/controllers/collection_registry.d.ts +5 -1
  4. package/dist/controllers/data_driver.d.ts +31 -2
  5. package/dist/controllers/index.d.ts +1 -10
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.es.js +362 -1
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/types/admin_block.d.ts +52 -0
  10. package/dist/types/backend.d.ts +30 -1
  11. package/dist/types/channel_bus.d.ts +192 -0
  12. package/dist/types/collection_contract.d.ts +43 -0
  13. package/dist/types/collections.d.ts +32 -786
  14. package/dist/types/component_ref.d.ts +39 -6
  15. package/dist/types/entity_callbacks.d.ts +1 -1
  16. package/dist/types/index.d.ts +7 -15
  17. package/dist/types/project_manifest.d.ts +336 -0
  18. package/dist/types/properties.d.ts +2 -2
  19. package/dist/types/schema_version.d.ts +18 -0
  20. package/dist/types/security_rules.d.ts +320 -0
  21. package/dist/types/storage_authorize.d.ts +74 -0
  22. package/package.json +1 -4
  23. package/src/call_context.ts +56 -0
  24. package/src/controllers/auth_state.ts +24 -0
  25. package/src/controllers/collection_registry.ts +5 -1
  26. package/src/controllers/data_driver.ts +58 -2
  27. package/src/controllers/index.ts +1 -10
  28. package/src/index.ts +1 -1
  29. package/src/types/admin_block.ts +93 -0
  30. package/src/types/backend.ts +33 -1
  31. package/src/types/channel_bus.ts +202 -0
  32. package/src/types/collection_contract.ts +278 -0
  33. package/src/types/collections.ts +41 -846
  34. package/src/types/component_ref.ts +40 -6
  35. package/src/types/entity_callbacks.ts +1 -1
  36. package/src/types/index.ts +7 -15
  37. package/src/types/policy.ts +25 -11
  38. package/src/types/project_manifest.ts +362 -0
  39. package/src/types/properties.ts +2 -2
  40. package/src/types/schema_version.ts +112 -0
  41. package/src/types/security_rules.ts +344 -0
  42. package/src/types/storage_authorize.ts +77 -0
  43. package/dist/controllers/analytics_controller.d.ts +0 -7
  44. package/dist/controllers/auth.d.ts +0 -110
  45. package/dist/controllers/customization_controller.d.ts +0 -61
  46. package/dist/controllers/dialogs_controller.d.ts +0 -36
  47. package/dist/controllers/local_config_persistence.d.ts +0 -20
  48. package/dist/controllers/navigation.d.ts +0 -225
  49. package/dist/controllers/registry.d.ts +0 -80
  50. package/dist/controllers/side_dialogs_controller.d.ts +0 -67
  51. package/dist/controllers/side_panel_controller.d.ts +0 -97
  52. package/dist/controllers/snackbar.d.ts +0 -24
  53. package/dist/rebase_context.d.ts +0 -110
  54. package/dist/types/breadcrumbs.d.ts +0 -26
  55. package/dist/types/builders.d.ts +0 -15
  56. package/dist/types/component_overrides.d.ts +0 -196
  57. package/dist/types/entity_actions.d.ts +0 -104
  58. package/dist/types/entity_link_builder.d.ts +0 -7
  59. package/dist/types/entity_views.d.ts +0 -95
  60. package/dist/types/export_import.d.ts +0 -21
  61. package/dist/types/formex.d.ts +0 -40
  62. package/dist/types/locales.d.ts +0 -4
  63. package/dist/types/modify_collections.d.ts +0 -5
  64. package/dist/types/plugins.d.ts +0 -277
  65. package/dist/types/property_config.d.ts +0 -74
  66. package/dist/types/slots.d.ts +0 -262
  67. package/dist/types/translations.d.ts +0 -915
  68. package/dist/types/user_management_delegate.d.ts +0 -22
  69. package/src/controllers/analytics_controller.tsx +0 -57
  70. package/src/controllers/auth.tsx +0 -121
  71. package/src/controllers/customization_controller.tsx +0 -72
  72. package/src/controllers/dialogs_controller.tsx +0 -37
  73. package/src/controllers/local_config_persistence.tsx +0 -22
  74. package/src/controllers/navigation.ts +0 -267
  75. package/src/controllers/registry.ts +0 -95
  76. package/src/controllers/side_dialogs_controller.tsx +0 -82
  77. package/src/controllers/side_panel_controller.tsx +0 -112
  78. package/src/controllers/snackbar.ts +0 -29
  79. package/src/rebase_context.tsx +0 -130
  80. package/src/types/breadcrumbs.ts +0 -27
  81. package/src/types/builders.ts +0 -17
  82. package/src/types/component_overrides.ts +0 -244
  83. package/src/types/entity_actions.tsx +0 -125
  84. package/src/types/entity_link_builder.ts +0 -8
  85. package/src/types/entity_views.tsx +0 -114
  86. package/src/types/export_import.ts +0 -26
  87. package/src/types/formex.ts +0 -45
  88. package/src/types/locales.ts +0 -81
  89. package/src/types/modify_collections.tsx +0 -6
  90. package/src/types/plugins.tsx +0 -346
  91. package/src/types/property_config.tsx +0 -95
  92. package/src/types/slots.tsx +0 -307
  93. package/src/types/translations.ts +0 -1026
  94. package/src/types/user_management_delegate.ts +0 -23
@@ -0,0 +1,51 @@
1
+ import type { StorageSource } from "./controllers/storage";
2
+ import type { RebaseClient } from "./controllers/client";
3
+ import type { RebaseSdkData } from "./controllers/data";
4
+ import type { User } from "./users";
5
+ /**
6
+ * Context that is provided to entity callbacks (hooks).
7
+ * It contains only the dependencies that are available in both the frontend and the backend.
8
+ *
9
+ * This is the *whole* context a collection callback gets, and it lives apart from
10
+ * {@link RebaseContext} on purpose. `RebaseContext` widens it with nine admin-panel
11
+ * controllers — navigation, side dialogs, snackbars — none of which exist in a
12
+ * backend process. Keeping them in one type meant every backend module that
13
+ * touched a callback signature transitively named the admin UI.
14
+ *
15
+ * @group Hooks and utilities
16
+ */
17
+ export type RebaseCallContext<USER extends User = User> = {
18
+ /**
19
+ * The Rebase client instance.
20
+ * Available in all entity callbacks (beforeSave, afterSave, afterRead,
21
+ * beforeDelete, afterDelete) and in CollectionActionsProps via context.
22
+ * Use it to call backend functions, access data, storage, etc.
23
+ *
24
+ * @example
25
+ * // In a beforeSave callback:
26
+ * const result = await context.client.functions.invoke('my-function', { ... });
27
+ *
28
+ * @example
29
+ * // In a CollectionAction component:
30
+ * const { client } = props.context;
31
+ * const result = await client.functions.invoke('extract-job', { url });
32
+ */
33
+ client: RebaseClient;
34
+ /**
35
+ * Unified data access — `context.data.products.create(...)`.
36
+ * Access any collection as a dynamic property.
37
+ *
38
+ * Returns flat rows (`{ id, ...columns }`), identical to the frontend SDK
39
+ * client — so `context.data` in a backend callback and `client.data` in the
40
+ * frontend behave the same way (`row.title`, never `row.values.title`).
41
+ */
42
+ data: RebaseSdkData;
43
+ /**
44
+ * Used storage implementation
45
+ */
46
+ storageSource: StorageSource;
47
+ /**
48
+ * Set by the backend when callbacks are executed on the server.
49
+ */
50
+ user?: USER;
51
+ };
@@ -0,0 +1,23 @@
1
+ import type { User } from "../users";
2
+ /**
3
+ * The read-only slice of authentication state that property resolution needs.
4
+ *
5
+ * `dynamicProps`, `conditions` and the JSON-Logic condition context all want the
6
+ * same one thing: who is asking. They used to be handed the entire
7
+ * {@link AuthController} — `signOut`, `googleLogin`, `authLoading`, thirty-odd
8
+ * members of frontend machinery — which meant `properties.ts` named a frontend
9
+ * controller, and so did `resolveProperty` in `@rebasepro/common`, which the
10
+ * Postgres schema generator calls at build time. A backend generating DDL had to
11
+ * satisfy a type with a login method in it.
12
+ *
13
+ * `User` already carries `roles` and `metadata`, so this is not a reduction in
14
+ * what a dynamic property can decide on — only in what it has to be given.
15
+ * An `AuthController` satisfies this structurally, so the frontend passes the
16
+ * controller it already has.
17
+ *
18
+ * @group Hooks and utilities
19
+ */
20
+ export interface AuthState<USER extends User = User> {
21
+ /** The signed-in user, or `null` when nobody is. */
22
+ user: USER | null;
23
+ }
@@ -10,8 +10,12 @@ export type CollectionRegistryController<DB = Record<string, unknown>, EC extend
10
10
  * Each entry relates to a collection in the root database.
11
11
  * Each of the navigation entries in this field
12
12
  * generates an entry in the main menu.
13
+ *
14
+ * `EC`, like {@link getCollection} — this was hardcoded to `CollectionConfig`
15
+ * while `getCollection` honoured the parameter, so the admin panel got its
16
+ * view model from one and the raw contract from the other.
13
17
  */
14
- collections?: CollectionConfig[];
18
+ collections?: EC[];
15
19
  /**
16
20
  * Is the registry ready to be used
17
21
  */
@@ -1,6 +1,6 @@
1
1
  import type { EntityStatus, EntityValues } from "../types/entities";
2
2
  import type { CollectionConfig, FilterValues } from "../types/collections";
3
- import type { RebaseContext } from "../rebase_context";
3
+ import type { RebaseCallContext } from "../call_context";
4
4
  /**
5
5
  * @internal
6
6
  */
@@ -32,6 +32,35 @@ export interface VectorSearchParams {
32
32
  /** Only return results within this distance threshold */
33
33
  threshold?: number;
34
34
  }
35
+ /** Rows returned for a plain / text-search list read when the client sends no `limit`. */
36
+ export declare const DEFAULT_LIST_LIMIT = 50;
37
+ /** Rows returned for a vector-search list read when the client sends no `limit`. */
38
+ export declare const DEFAULT_VECTOR_LIST_LIMIT = 10;
39
+ /** Hard ceiling clamped onto any client-supplied `limit`, on every surface. */
40
+ export declare const MAX_LIST_LIMIT = 1000;
41
+ /** Overridable bounds for {@link resolveClientListLimit}. */
42
+ export interface ListLimitBounds {
43
+ /** Default page size for plain and text-search reads. */
44
+ defaultLimit?: number;
45
+ /** Default page size for vector-search reads. */
46
+ vectorDefaultLimit?: number;
47
+ /** Upper bound clamped onto any client-supplied limit. */
48
+ maxLimit?: number;
49
+ }
50
+ /**
51
+ * Resolve a client-supplied list `limit` into a safe, always-defined value.
52
+ *
53
+ * - A provided limit is coerced to an integer and clamped to `[1, maxLimit]`,
54
+ * so `0`, negatives, and absurd values can never bypass the cap.
55
+ * - An absent / blank / non-numeric limit falls back to the mode default:
56
+ * `vectorDefaultLimit` for a vector search, otherwise `defaultLimit`.
57
+ *
58
+ * The return is never `undefined` — no ingress that routes its client limit
59
+ * through this can produce an unbounded read.
60
+ */
61
+ export declare function resolveClientListLimit(rawLimit: number | string | null | undefined, opts?: ListLimitBounds & {
62
+ vectorSearch?: boolean;
63
+ }): number;
35
64
  /**
36
65
  * @internal
37
66
  */
@@ -211,7 +240,7 @@ export interface DataDriver {
211
240
  delegateToCMSModel?: (data: unknown) => unknown;
212
241
  cmsToDelegateModel?: (data: unknown) => unknown;
213
242
  initTextSearch?: (props: {
214
- context: RebaseContext;
243
+ context: RebaseCallContext;
215
244
  path: string;
216
245
  databaseId?: string;
217
246
  collection: CollectionConfig;
@@ -1,18 +1,9 @@
1
1
  export * from "./collection_registry";
2
- export * from "./analytics_controller";
3
- export * from "./auth";
2
+ export * from "./auth_state";
4
3
  export * from "./data";
5
4
  export * from "./database_admin";
6
5
  export * from "./data_driver";
7
- export * from "./local_config_persistence";
8
- export * from "./navigation";
9
6
  export * from "./effective_role";
10
7
  export * from "./storage";
11
8
  export * from "./email";
12
9
  export * from "./client";
13
- export * from "./customization_controller";
14
- export * from "./side_panel_controller";
15
- export * from "./side_dialogs_controller";
16
- export * from "./dialogs_controller";
17
- export * from "./snackbar";
18
- export * from "./registry";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./errors";
2
- export * from "./rebase_context";
2
+ export * from "./call_context";
3
3
  export * from "./types";
4
4
  export * from "./controllers";
5
5
  export * from "./users";
package/dist/index.es.js CHANGED
@@ -264,10 +264,78 @@ function toCanonicalOp(op) {
264
264
  return REST_TO_CANONICAL[op];
265
265
  }
266
266
  //#endregion
267
+ //#region src/types/admin_block.ts
268
+ /**
269
+ * Every key that belongs inside a collection's `admin` block, as data.
270
+ *
271
+ * The type that describes these fields is `AdminCollectionOptions` in
272
+ * `@rebasepro/admin-types`, and it is erased at build time — but three runtime
273
+ * consumers need the list, and two of them are core:
274
+ *
275
+ * - `serializeCollections`, to drop the block from the contract
276
+ * - the ts-morph schema editor in `@rebasepro/server`, which rewrites collection
277
+ * files on disk from the admin panel and has to know where each key goes. A key
278
+ * missing from this list gets written to the *top level* of the file, where the
279
+ * backend ignores it and the panel never finds it again.
280
+ * - the `collections-admin-block` codemod
281
+ *
282
+ * `@rebasepro/admin-types` re-exports this and asserts it names only real option
283
+ * keys; the count is pinned by a test there.
284
+ *
285
+ * @group Models
286
+ */
287
+ var ADMIN_COLLECTION_KEYS = [
288
+ "Actions",
289
+ "additionalFields",
290
+ "alwaysApplyDefaultValues",
291
+ "components",
292
+ "defaultEntityAction",
293
+ "defaultFilter",
294
+ "defaultSelectedView",
295
+ "defaultSize",
296
+ "defaultViewMode",
297
+ "disableDefaultActions",
298
+ "enabledViews",
299
+ "entityActions",
300
+ "entityViews",
301
+ "exportable",
302
+ "filterPresets",
303
+ "fixedFilter",
304
+ "formAutoSave",
305
+ "formView",
306
+ "group",
307
+ "hideFromNavigation",
308
+ "hideIdFromCollection",
309
+ "hideIdFromForm",
310
+ "icon",
311
+ "includeJsonView",
312
+ "inlineEditing",
313
+ "kanban",
314
+ "listProperties",
315
+ "localChangesBackup",
316
+ "openEntityMode",
317
+ "orderProperty",
318
+ "pagination",
319
+ "previewProperties",
320
+ "propertiesOrder",
321
+ "selectionController",
322
+ "selectionEnabled",
323
+ "sideDialogWidth",
324
+ "sort",
325
+ "titleProperty"
326
+ ];
327
+ //#endregion
267
328
  //#region src/types/collections.ts
268
329
  /**
269
330
  * Type guard for PostgreSQL collections.
270
331
  * Returns true if the collection uses the Postgres engine (or the default engine).
332
+ *
333
+ * Generic over the *input* type, and narrows by intersection rather than
334
+ * replacement. Narrowing to a bare `PostgresCollectionConfig` discarded whatever
335
+ * the caller actually had — most visibly the admin panel's view model, whose
336
+ * flattened presentation fields vanished the moment a collection passed through
337
+ * one of these guards.
338
+ *
271
339
  * @group Models
272
340
  */
273
341
  function isPostgresCollectionConfig(collection) {
@@ -416,6 +484,19 @@ function isBranchAdmin(admin) {
416
484
  return !!admin && typeof admin.createBranch === "function";
417
485
  }
418
486
  //#endregion
487
+ //#region src/types/channel_bus.ts
488
+ /**
489
+ * Whether `setting` is an already-constructed transport rather than a request
490
+ * for a built-in one.
491
+ *
492
+ * Structural rather than nominal so that an instance from a *different copy* of
493
+ * `@rebasepro/types` — an entirely normal outcome of a separately versioned
494
+ * transport package — is still recognised.
495
+ */
496
+ function isChannelBusInstance(setting) {
497
+ return typeof setting?.publish === "function";
498
+ }
499
+ //#endregion
419
500
  //#region src/types/data_source.ts
420
501
  /**
421
502
  * The default data-source key, used when a collection does not name a
@@ -541,6 +622,286 @@ function isLazyComponentRef(ref) {
541
622
  return typeof ref === "object" && ref !== null && "__rebaseLazy" in ref && ref.__rebaseLazy === true;
542
623
  }
543
624
  //#endregion
625
+ //#region src/types/project_manifest.ts
626
+ /**
627
+ * Version of the bundle *format* itself.
628
+ *
629
+ * Bumped only when the on-disk layout changes in a way an older runtime could
630
+ * not read. A runtime accepts any bundle whose `bundleFormat` is less than or
631
+ * equal to its own — old bundles keep booting on new runtimes, which is the
632
+ * whole point of separating the artifact from the engine.
633
+ */
634
+ var BUNDLE_FORMAT_VERSION = 1;
635
+ /**
636
+ * The runtime contract major.
637
+ *
638
+ * Distinct from the `@rebasepro/server` package version: the package may release
639
+ * any number of minors and patches while this stays put. It changes only when
640
+ * the bundle/runtime contract breaks compatibility, and a project's
641
+ * `manifest.runtime` range is matched against *this*.
642
+ */
643
+ var RUNTIME_CONTRACT_VERSION = 1;
644
+ /** Header carrying the schema version an SDK was generated from. */
645
+ var SCHEMA_VERSION_HEADER = "x-rebase-schema";
646
+ //#endregion
647
+ //#region src/types/collection_contract.ts
648
+ function isSerializedCollectionRef(value) {
649
+ return typeof value === "object" && value !== null && typeof value.__collectionRef === "string";
650
+ }
651
+ /** Depth limit for the walk — deep enough for real configs, finite for cyclic ones. */
652
+ var MAX_DEPTH = 64;
653
+ /**
654
+ * Resolve whatever a `target` thunk returns down to a collection.
655
+ *
656
+ * A target may be the collection, a module namespace (when the authoring file
657
+ * used `import * as`), or a default-export wrapper. All three appear in real
658
+ * projects, and the SDK generator already unwraps them the same way.
659
+ */
660
+ function unwrapTarget(value) {
661
+ if (!value || typeof value !== "object") return void 0;
662
+ const candidate = value;
663
+ if (candidate.default || candidate.__esModule) {
664
+ const inner = candidate.default;
665
+ if (inner && typeof inner === "object") return inner;
666
+ }
667
+ if (candidate.properties) return value;
668
+ }
669
+ /** The identity a serialized reference uses. Slug first — it is the routing key. */
670
+ function refFor(collection) {
671
+ if (!collection) return void 0;
672
+ const withPath = collection;
673
+ return collection.slug || withPath.path || collection.name;
674
+ }
675
+ function toSerializable(value, seen, depth, state, key) {
676
+ if (depth > MAX_DEPTH) {
677
+ state.truncations++;
678
+ return;
679
+ }
680
+ if (typeof value === "function") {
681
+ if (key === "target") try {
682
+ const ref = refFor(unwrapTarget(value()));
683
+ return ref ? { __collectionRef: ref } : void 0;
684
+ } catch {
685
+ return;
686
+ }
687
+ return;
688
+ }
689
+ if (value === null || typeof value !== "object") return value;
690
+ if (value instanceof Date) return value.toISOString();
691
+ if (value instanceof RegExp) return value.source;
692
+ if (seen.has(value)) {
693
+ state.truncations++;
694
+ return;
695
+ }
696
+ const cached = state.memo.get(value);
697
+ if (cached !== void 0) return cached;
698
+ seen.add(value);
699
+ const truncationsBefore = state.truncations;
700
+ const memoize = (result) => {
701
+ if (result !== void 0 && state.truncations === truncationsBefore) state.memo.set(value, result);
702
+ return result;
703
+ };
704
+ try {
705
+ if (Array.isArray(value)) {
706
+ const items = value.map((item) => toSerializable(item, seen, depth + 1, state)).filter((item) => item !== void 0);
707
+ return memoize(value.length > 0 && items.length === 0 ? void 0 : items);
708
+ }
709
+ if ("$$typeof" in value) return void 0;
710
+ const entries = Object.entries(value);
711
+ const out = {};
712
+ for (const [k, v] of entries) {
713
+ const converted = toSerializable(v, seen, depth + 1, state, k);
714
+ if (converted !== void 0) out[k] = converted;
715
+ }
716
+ if (entries.length > 0 && Object.keys(out).length === 0) return void 0;
717
+ return memoize(out);
718
+ } finally {
719
+ seen.delete(value);
720
+ }
721
+ }
722
+ /**
723
+ * Serialize collections for transport over the contract endpoint.
724
+ *
725
+ * Sorted by slug so the output — and therefore the schema hash computed from it
726
+ * — does not depend on filesystem ordering.
727
+ */
728
+ function serializeCollections(collections) {
729
+ return [...collections].sort((a, b) => String(a.slug ?? "").localeCompare(String(b.slug ?? ""))).map((collection) => toSerializable(withoutAdminBlock(collection), /* @__PURE__ */ new WeakSet(), 0, {
730
+ memo: /* @__PURE__ */ new WeakMap(),
731
+ truncations: 0
732
+ })).filter((c) => c !== void 0);
733
+ }
734
+ /**
735
+ * Drop the admin block before the walk.
736
+ *
737
+ * Nothing downstream of serialization is an admin panel. The contract endpoint
738
+ * feeds remote SDK generation, and `rebase build` writes the result into a bundle
739
+ * manifest that only the backend runtime reads. The block would survive the walk
740
+ * as a husk anyway — its React elements and component functions are dropped
741
+ * individually — and that husk has two costs worth avoiding: it puts every custom
742
+ * component's *file path* on an endpoint whose job is to describe data shapes, and
743
+ * it grows a payload that is fetched and cached per project.
744
+ *
745
+ * Removing it here rather than at each call site means one chokepoint, so a future
746
+ * consumer of `serializeCollections` cannot forget.
747
+ *
748
+ * Child collections carry their own block, so this recurses — stripping only the
749
+ * top level was the mistake `stripNonClientFields` in the contract routes already
750
+ * had to fix once for security rules.
751
+ */
752
+ function withoutAdminBlock(collection) {
753
+ const { admin: _admin, ...rest } = collection;
754
+ const nested = rest;
755
+ if (Array.isArray(nested.subcollections)) nested.subcollections = nested.subcollections.map((child) => withoutAdminBlock(child));
756
+ return rest;
757
+ }
758
+ /**
759
+ * Rebuild collections received from a contract endpoint.
760
+ *
761
+ * Relation refs become real thunks resolving through the returned set, so
762
+ * downstream consumers — the SDK generator above all — see exactly the shape
763
+ * they would have seen had the collections been imported from source.
764
+ *
765
+ * A ref naming a collection that is not in the payload resolves to `undefined`
766
+ * rather than throwing: the generator already tolerates an unresolvable target
767
+ * by falling back to a permissive key type, and a partial contract should still
768
+ * produce a usable SDK.
769
+ */
770
+ function deserializeCollections(payload) {
771
+ const collections = payload.filter((c) => typeof c === "object" && c !== null).map((c) => ({ ...c }));
772
+ const bySlug = /* @__PURE__ */ new Map();
773
+ for (const collection of collections) {
774
+ const ref = refFor(collection);
775
+ if (ref) bySlug.set(ref, collection);
776
+ }
777
+ const rehydrate = (value, depth) => {
778
+ if (depth > MAX_DEPTH || !value || typeof value !== "object") return;
779
+ if (Array.isArray(value)) {
780
+ for (const item of value) rehydrate(item, depth + 1);
781
+ return;
782
+ }
783
+ const record = value;
784
+ for (const [key, child] of Object.entries(record)) {
785
+ if (key === "target" && isSerializedCollectionRef(child)) {
786
+ const slug = child.__collectionRef;
787
+ record.target = () => bySlug.get(slug);
788
+ continue;
789
+ }
790
+ rehydrate(child, depth + 1);
791
+ }
792
+ };
793
+ for (const collection of collections) rehydrate(collection, 0);
794
+ return collections;
795
+ }
796
+ //#endregion
797
+ //#region src/types/schema_version.ts
798
+ /**
799
+ * The schema version stamp.
800
+ *
801
+ * One function, used in three places that must agree or the whole drift-detection
802
+ * story is noise: `rebase build` writes it into a bundle manifest, the runtime
803
+ * serves it from the contract endpoint, and a generated SDK records the value it
804
+ * was built from. If any two of those computed it differently, every client would
805
+ * look permanently out of date.
806
+ *
807
+ * It covers **collections only** — the client's contract is the shape of the
808
+ * data, so editing a hook or a server function must not invalidate every SDK in
809
+ * every repository. That is a deliberate narrowing, not an oversight.
810
+ */
811
+ /** Stable stringify: object keys sorted at every level, so key order cannot alter the hash. */
812
+ function canonicalize(value) {
813
+ if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
814
+ if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
815
+ return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonicalize(v)}`).join(",")}}`;
816
+ }
817
+ /**
818
+ * Reduce a collection to the parts a generated client is actually built from.
819
+ *
820
+ * The version answers one question — "is this SDK stale?" — so it must change
821
+ * exactly when the generated types could change, and never otherwise. Hashing a
822
+ * whole collection fails both halves of that:
823
+ *
824
+ * - Security rules, callbacks, icons, groups and UI settings do not appear in a
825
+ * generated client, so including them reports perfectly current SDKs as stale.
826
+ * - Worse, they are not stable *inputs*. The runtime applies default security
827
+ * rules when it loads collections, so the same source hashed before and after
828
+ * loading produced two different answers — a build-time stamp that could never
829
+ * match the server that served it.
830
+ *
831
+ * Codegen reads the slug (for the `Database` key and type names), the properties,
832
+ * and the relations. That is the projection.
833
+ */
834
+ function projectForCodegen(collection) {
835
+ const source = collection;
836
+ return {
837
+ slug: collection.slug ?? source.path,
838
+ properties: collection.properties,
839
+ relations: source.relations,
840
+ engine: source.engine,
841
+ dataSource: source.dataSource,
842
+ subcollections: source.subcollections?.map(projectForCodegen)
843
+ };
844
+ }
845
+ /**
846
+ * Compute the canonical string a schema version hashes.
847
+ *
848
+ * Exposed separately so the hashing itself can differ by environment: Node has
849
+ * `crypto`, and callers without it can still compare canonical forms directly.
850
+ */
851
+ function canonicalSchemaPayload(collections) {
852
+ return canonicalize(serializeCollections(collections).map((collection) => projectForCodegen(collection)));
853
+ }
854
+ /**
855
+ * A short, non-cryptographic digest of the canonical payload.
856
+ *
857
+ * FNV-1a style, 64 bits, as two 32-bit halves. This is an identity, not a
858
+ * security boundary: nothing trusts a schema version to prove anything, it only
859
+ * answers "is this the same schema as before". A hand-rolled hash keeps this
860
+ * module free of `node:crypto`, so the identical function runs in the browser,
861
+ * in the CLI, and in the runtime — which is the property that actually matters.
862
+ */
863
+ function computeSchemaVersion(collections) {
864
+ const payload = canonicalSchemaPayload(collections);
865
+ let h1 = 2166136261;
866
+ let h2 = 16777619;
867
+ for (let i = 0; i < payload.length; i++) {
868
+ const code = payload.charCodeAt(i);
869
+ h1 ^= code;
870
+ h1 = h1 + ((h1 << 1) + (h1 << 4) + (h1 << 7) + (h1 << 8) + (h1 << 24)) >>> 0;
871
+ h2 ^= code + i;
872
+ h2 = h2 + ((h2 << 1) + (h2 << 5) + (h2 << 9) + (h2 << 15) + (h2 << 24)) >>> 0;
873
+ }
874
+ const hex = (n) => n.toString(16).padStart(8, "0");
875
+ return `v1:${hex(h1)}${hex(h2)}`;
876
+ }
877
+ //#endregion
878
+ //#region src/controllers/data_driver.ts
879
+ /** Rows returned for a plain / text-search list read when the client sends no `limit`. */
880
+ var DEFAULT_LIST_LIMIT = 50;
881
+ /** Rows returned for a vector-search list read when the client sends no `limit`. */
882
+ var DEFAULT_VECTOR_LIST_LIMIT = 10;
883
+ /** Hard ceiling clamped onto any client-supplied `limit`, on every surface. */
884
+ var MAX_LIST_LIMIT = 1e3;
885
+ /**
886
+ * Resolve a client-supplied list `limit` into a safe, always-defined value.
887
+ *
888
+ * - A provided limit is coerced to an integer and clamped to `[1, maxLimit]`,
889
+ * so `0`, negatives, and absurd values can never bypass the cap.
890
+ * - An absent / blank / non-numeric limit falls back to the mode default:
891
+ * `vectorDefaultLimit` for a vector search, otherwise `defaultLimit`.
892
+ *
893
+ * The return is never `undefined` — no ingress that routes its client limit
894
+ * through this can produce an unbounded read.
895
+ */
896
+ function resolveClientListLimit(rawLimit, opts = {}) {
897
+ const maxLimit = opts.maxLimit ?? 1e3;
898
+ if (rawLimit != null && String(rawLimit).trim() !== "") {
899
+ const parsed = typeof rawLimit === "number" ? rawLimit : parseInt(String(rawLimit), 10);
900
+ if (Number.isFinite(parsed)) return Math.min(Math.max(1, Math.floor(parsed)), maxLimit);
901
+ }
902
+ return opts.vectorSearch ? opts.vectorDefaultLimit ?? 10 : opts.defaultLimit ?? 50;
903
+ }
904
+ //#endregion
544
905
  //#region src/controllers/storage.ts
545
906
  /**
546
907
  * Path prefix that marks an object as **public**. Files stored under this
@@ -568,6 +929,6 @@ function isPublicStoragePath(path) {
568
929
  return p.startsWith("public/") || p.startsWith(`default/public/`);
569
930
  }
570
931
  //#endregion
571
- export { ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, CANONICAL_TO_REST, DEFAULT_CAPABILITIES, DEFAULT_DATA_SOURCE_KEY, DEFAULT_STORAGE_SOURCE_KEY, EntityReference, EntityRelation, FIREBASE_CAPABILITIES, GeoPoint, MONGODB_CAPABILITIES, NULL_OPS, POSTGRES_CAPABILITIES, PUBLIC_STORAGE_PREFIX, REST_TO_CANONICAL, RebaseApiError, RebaseClientError, Vector, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, isBranchAdmin, isDocumentAdmin, isFirebaseCollectionConfig, isLazyComponentRef, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStoragePath, isSQLAdmin, isSchemaAdmin, policy, registerDataSourceCapabilities, toCanonicalOp };
932
+ export { ADMIN_COLLECTION_KEYS, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DEFAULT_CAPABILITIES, DEFAULT_DATA_SOURCE_KEY, 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, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, isBranchAdmin, isChannelBusInstance, isDocumentAdmin, isFirebaseCollectionConfig, isLazyComponentRef, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStoragePath, isSQLAdmin, isSchemaAdmin, isSerializedCollectionRef, policy, registerDataSourceCapabilities, resolveClientListLimit, serializeCollections, toCanonicalOp };
572
933
 
573
934
  //# sourceMappingURL=index.es.js.map