@rebasepro/types 0.10.1-canary.b1e3dbf → 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 (86) 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 +2 -2
  5. package/dist/controllers/index.d.ts +1 -10
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.es.js +94 -2
  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 +18 -0
  11. package/dist/types/collections.d.ts +32 -786
  12. package/dist/types/component_ref.d.ts +39 -6
  13. package/dist/types/entity_callbacks.d.ts +1 -1
  14. package/dist/types/index.d.ts +2 -15
  15. package/dist/types/properties.d.ts +2 -2
  16. package/dist/types/security_rules.d.ts +320 -0
  17. package/dist/types/storage_authorize.d.ts +32 -0
  18. package/package.json +1 -4
  19. package/src/call_context.ts +56 -0
  20. package/src/controllers/auth_state.ts +24 -0
  21. package/src/controllers/collection_registry.ts +5 -1
  22. package/src/controllers/data_driver.ts +2 -2
  23. package/src/controllers/index.ts +1 -10
  24. package/src/index.ts +1 -1
  25. package/src/types/admin_block.ts +93 -0
  26. package/src/types/backend.ts +21 -0
  27. package/src/types/collection_contract.ts +30 -1
  28. package/src/types/collections.ts +41 -846
  29. package/src/types/component_ref.ts +40 -6
  30. package/src/types/entity_callbacks.ts +1 -1
  31. package/src/types/index.ts +2 -15
  32. package/src/types/properties.ts +2 -2
  33. package/src/types/security_rules.ts +344 -0
  34. package/src/types/storage_authorize.ts +31 -0
  35. package/dist/controllers/analytics_controller.d.ts +0 -7
  36. package/dist/controllers/auth.d.ts +0 -110
  37. package/dist/controllers/customization_controller.d.ts +0 -61
  38. package/dist/controllers/dialogs_controller.d.ts +0 -36
  39. package/dist/controllers/local_config_persistence.d.ts +0 -20
  40. package/dist/controllers/navigation.d.ts +0 -225
  41. package/dist/controllers/registry.d.ts +0 -80
  42. package/dist/controllers/side_dialogs_controller.d.ts +0 -67
  43. package/dist/controllers/side_panel_controller.d.ts +0 -97
  44. package/dist/controllers/snackbar.d.ts +0 -24
  45. package/dist/rebase_context.d.ts +0 -110
  46. package/dist/types/breadcrumbs.d.ts +0 -26
  47. package/dist/types/builders.d.ts +0 -15
  48. package/dist/types/component_overrides.d.ts +0 -196
  49. package/dist/types/entity_actions.d.ts +0 -104
  50. package/dist/types/entity_link_builder.d.ts +0 -7
  51. package/dist/types/entity_views.d.ts +0 -95
  52. package/dist/types/export_import.d.ts +0 -21
  53. package/dist/types/formex.d.ts +0 -40
  54. package/dist/types/locales.d.ts +0 -4
  55. package/dist/types/modify_collections.d.ts +0 -5
  56. package/dist/types/plugins.d.ts +0 -277
  57. package/dist/types/property_config.d.ts +0 -74
  58. package/dist/types/slots.d.ts +0 -262
  59. package/dist/types/translations.d.ts +0 -915
  60. package/dist/types/user_management_delegate.d.ts +0 -22
  61. package/src/controllers/analytics_controller.tsx +0 -57
  62. package/src/controllers/auth.tsx +0 -121
  63. package/src/controllers/customization_controller.tsx +0 -72
  64. package/src/controllers/dialogs_controller.tsx +0 -37
  65. package/src/controllers/local_config_persistence.tsx +0 -22
  66. package/src/controllers/navigation.ts +0 -267
  67. package/src/controllers/registry.ts +0 -95
  68. package/src/controllers/side_dialogs_controller.tsx +0 -82
  69. package/src/controllers/side_panel_controller.tsx +0 -112
  70. package/src/controllers/snackbar.ts +0 -29
  71. package/src/rebase_context.tsx +0 -130
  72. package/src/types/breadcrumbs.ts +0 -27
  73. package/src/types/builders.ts +0 -17
  74. package/src/types/component_overrides.ts +0 -244
  75. package/src/types/entity_actions.tsx +0 -125
  76. package/src/types/entity_link_builder.ts +0 -8
  77. package/src/types/entity_views.tsx +0 -114
  78. package/src/types/export_import.ts +0 -26
  79. package/src/types/formex.ts +0 -45
  80. package/src/types/locales.ts +0 -81
  81. package/src/types/modify_collections.tsx +0 -6
  82. package/src/types/plugins.tsx +0 -346
  83. package/src/types/property_config.tsx +0 -95
  84. package/src/types/slots.tsx +0 -307
  85. package/src/types/translations.ts +0 -1026
  86. 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
  */
@@ -240,7 +240,7 @@ export interface DataDriver {
240
240
  delegateToCMSModel?: (data: unknown) => unknown;
241
241
  cmsToDelegateModel?: (data: unknown) => unknown;
242
242
  initTextSearch?: (props: {
243
- context: RebaseContext;
243
+ context: RebaseCallContext;
244
244
  path: string;
245
245
  databaseId?: string;
246
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) {
@@ -658,12 +726,36 @@ function toSerializable(value, seen, depth, state, key) {
658
726
  * — does not depend on filesystem ordering.
659
727
  */
660
728
  function serializeCollections(collections) {
661
- return [...collections].sort((a, b) => String(a.slug ?? "").localeCompare(String(b.slug ?? ""))).map((collection) => toSerializable(collection, /* @__PURE__ */ new WeakSet(), 0, {
729
+ return [...collections].sort((a, b) => String(a.slug ?? "").localeCompare(String(b.slug ?? ""))).map((collection) => toSerializable(withoutAdminBlock(collection), /* @__PURE__ */ new WeakSet(), 0, {
662
730
  memo: /* @__PURE__ */ new WeakMap(),
663
731
  truncations: 0
664
732
  })).filter((c) => c !== void 0);
665
733
  }
666
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
+ /**
667
759
  * Rebuild collections received from a contract endpoint.
668
760
  *
669
761
  * Relation refs become real thunks resolving through the returned set, so
@@ -837,6 +929,6 @@ function isPublicStoragePath(path) {
837
929
  return p.startsWith("public/") || p.startsWith(`default/public/`);
838
930
  }
839
931
  //#endregion
840
- export { 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 };
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 };
841
933
 
842
934
  //# sourceMappingURL=index.es.js.map