@rebasepro/types 0.10.1-canary.d8d45b2 → 0.10.1-canary.ff9ccd6

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 (82) 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 +106 -2
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/types/admin_block.d.ts +34 -0
  10. package/dist/types/collections.d.ts +17 -789
  11. package/dist/types/component_ref.d.ts +39 -6
  12. package/dist/types/entity_callbacks.d.ts +1 -1
  13. package/dist/types/index.d.ts +2 -15
  14. package/dist/types/properties.d.ts +12 -157
  15. package/dist/types/security_rules.d.ts +320 -0
  16. package/package.json +3 -6
  17. package/src/call_context.ts +56 -0
  18. package/src/controllers/auth_state.ts +24 -0
  19. package/src/controllers/collection_registry.ts +5 -1
  20. package/src/controllers/data_driver.ts +2 -2
  21. package/src/controllers/index.ts +1 -10
  22. package/src/index.ts +1 -1
  23. package/src/types/admin_block.ts +75 -0
  24. package/src/types/collection_contract.ts +30 -1
  25. package/src/types/collections.ts +25 -848
  26. package/src/types/component_ref.ts +40 -6
  27. package/src/types/entity_callbacks.ts +1 -1
  28. package/src/types/index.ts +2 -15
  29. package/src/types/properties.ts +11 -169
  30. package/src/types/security_rules.ts +344 -0
  31. package/dist/controllers/analytics_controller.d.ts +0 -7
  32. package/dist/controllers/auth.d.ts +0 -110
  33. package/dist/controllers/customization_controller.d.ts +0 -61
  34. package/dist/controllers/dialogs_controller.d.ts +0 -36
  35. package/dist/controllers/local_config_persistence.d.ts +0 -20
  36. package/dist/controllers/navigation.d.ts +0 -225
  37. package/dist/controllers/registry.d.ts +0 -80
  38. package/dist/controllers/side_dialogs_controller.d.ts +0 -67
  39. package/dist/controllers/side_panel_controller.d.ts +0 -97
  40. package/dist/controllers/snackbar.d.ts +0 -24
  41. package/dist/rebase_context.d.ts +0 -110
  42. package/dist/types/breadcrumbs.d.ts +0 -26
  43. package/dist/types/builders.d.ts +0 -15
  44. package/dist/types/component_overrides.d.ts +0 -196
  45. package/dist/types/entity_actions.d.ts +0 -104
  46. package/dist/types/entity_link_builder.d.ts +0 -7
  47. package/dist/types/entity_views.d.ts +0 -95
  48. package/dist/types/export_import.d.ts +0 -21
  49. package/dist/types/formex.d.ts +0 -40
  50. package/dist/types/locales.d.ts +0 -4
  51. package/dist/types/modify_collections.d.ts +0 -5
  52. package/dist/types/plugins.d.ts +0 -277
  53. package/dist/types/property_config.d.ts +0 -74
  54. package/dist/types/slots.d.ts +0 -262
  55. package/dist/types/translations.d.ts +0 -915
  56. package/dist/types/user_management_delegate.d.ts +0 -22
  57. package/src/controllers/analytics_controller.tsx +0 -57
  58. package/src/controllers/auth.tsx +0 -121
  59. package/src/controllers/customization_controller.tsx +0 -72
  60. package/src/controllers/dialogs_controller.tsx +0 -37
  61. package/src/controllers/local_config_persistence.tsx +0 -22
  62. package/src/controllers/navigation.ts +0 -267
  63. package/src/controllers/registry.ts +0 -95
  64. package/src/controllers/side_dialogs_controller.tsx +0 -82
  65. package/src/controllers/side_panel_controller.tsx +0 -112
  66. package/src/controllers/snackbar.ts +0 -29
  67. package/src/rebase_context.tsx +0 -130
  68. package/src/types/breadcrumbs.ts +0 -27
  69. package/src/types/builders.ts +0 -17
  70. package/src/types/component_overrides.ts +0 -244
  71. package/src/types/entity_actions.tsx +0 -125
  72. package/src/types/entity_link_builder.ts +0 -8
  73. package/src/types/entity_views.tsx +0 -114
  74. package/src/types/export_import.ts +0 -26
  75. package/src/types/formex.ts +0 -45
  76. package/src/types/locales.ts +0 -81
  77. package/src/types/modify_collections.tsx +0 -6
  78. package/src/types/plugins.tsx +0 -346
  79. package/src/types/property_config.tsx +0 -95
  80. package/src/types/slots.tsx +0 -307
  81. package/src/types/translations.ts +0 -1026
  82. 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,90 @@ function toCanonicalOp(op) {
264
264
  return REST_TO_CANONICAL[op];
265
265
  }
266
266
  //#endregion
267
+ //#region src/types/admin_block.ts
268
+ /**
269
+ * The keys of a collection's admin block, as data.
270
+ *
271
+ * There is no *type* for the block in this package any more, and that is the point:
272
+ * `admin` is not declared on `BaseCollectionConfig` or on any property here, so a
273
+ * BaaS install cannot even write one. `@rebasepro/admin-types` adds the field back by
274
+ * declaration merging, which is why installing it is what makes the admin surface
275
+ * appear.
276
+ *
277
+ * The *list* still has to live here, because three runtime consumers need it and two
278
+ * of them are core — see below.
279
+ */
280
+ /**
281
+ * Every key that belongs inside a collection's `admin` block, as data.
282
+ *
283
+ * The type that describes these fields is `AdminCollectionOptions` in
284
+ * `@rebasepro/admin-types`, and it is erased at build time — but three runtime
285
+ * consumers need the list, and two of them are core:
286
+ *
287
+ * - `serializeCollections`, to drop the block from the contract
288
+ * - the ts-morph schema editor in `@rebasepro/server`, which rewrites collection
289
+ * files on disk from the admin panel and has to know where each key goes. A key
290
+ * missing from this list gets written to the *top level* of the file, where the
291
+ * backend ignores it and the panel never finds it again.
292
+ * - the `collections-admin-block` codemod
293
+ *
294
+ * `@rebasepro/admin-types` re-exports this and asserts it names only real option
295
+ * keys; the count is pinned by a test there.
296
+ *
297
+ * @group Models
298
+ */
299
+ var ADMIN_COLLECTION_KEYS = [
300
+ "Actions",
301
+ "additionalFields",
302
+ "alwaysApplyDefaultValues",
303
+ "components",
304
+ "defaultEntityAction",
305
+ "defaultFilter",
306
+ "defaultSelectedView",
307
+ "defaultSize",
308
+ "defaultViewMode",
309
+ "disableDefaultActions",
310
+ "enabledViews",
311
+ "entityActions",
312
+ "entityViews",
313
+ "exportable",
314
+ "filterPresets",
315
+ "fixedFilter",
316
+ "formAutoSave",
317
+ "formView",
318
+ "group",
319
+ "hideFromNavigation",
320
+ "hideIdFromCollection",
321
+ "hideIdFromForm",
322
+ "icon",
323
+ "includeJsonView",
324
+ "inlineEditing",
325
+ "kanban",
326
+ "listProperties",
327
+ "localChangesBackup",
328
+ "openEntityMode",
329
+ "orderProperty",
330
+ "pagination",
331
+ "previewProperties",
332
+ "propertiesOrder",
333
+ "selectionController",
334
+ "selectionEnabled",
335
+ "sideDialogWidth",
336
+ "sort",
337
+ "titleProperty"
338
+ ];
339
+ //#endregion
267
340
  //#region src/types/collections.ts
268
341
  /**
269
342
  * Type guard for PostgreSQL collections.
270
343
  * Returns true if the collection uses the Postgres engine (or the default engine).
344
+ *
345
+ * Generic over the *input* type, and narrows by intersection rather than
346
+ * replacement. Narrowing to a bare `PostgresCollectionConfig` discarded whatever
347
+ * the caller actually had — most visibly the admin panel's view model, whose
348
+ * flattened presentation fields vanished the moment a collection passed through
349
+ * one of these guards.
350
+ *
271
351
  * @group Models
272
352
  */
273
353
  function isPostgresCollectionConfig(collection) {
@@ -658,12 +738,36 @@ function toSerializable(value, seen, depth, state, key) {
658
738
  * — does not depend on filesystem ordering.
659
739
  */
660
740
  function serializeCollections(collections) {
661
- return [...collections].sort((a, b) => String(a.slug ?? "").localeCompare(String(b.slug ?? ""))).map((collection) => toSerializable(collection, /* @__PURE__ */ new WeakSet(), 0, {
741
+ return [...collections].sort((a, b) => String(a.slug ?? "").localeCompare(String(b.slug ?? ""))).map((collection) => toSerializable(withoutAdminBlock(collection), /* @__PURE__ */ new WeakSet(), 0, {
662
742
  memo: /* @__PURE__ */ new WeakMap(),
663
743
  truncations: 0
664
744
  })).filter((c) => c !== void 0);
665
745
  }
666
746
  /**
747
+ * Drop the admin block before the walk.
748
+ *
749
+ * Nothing downstream of serialization is an admin panel. The contract endpoint
750
+ * feeds remote SDK generation, and `rebase build` writes the result into a bundle
751
+ * manifest that only the backend runtime reads. The block would survive the walk
752
+ * as a husk anyway — its React elements and component functions are dropped
753
+ * individually — and that husk has two costs worth avoiding: it puts every custom
754
+ * component's *file path* on an endpoint whose job is to describe data shapes, and
755
+ * it grows a payload that is fetched and cached per project.
756
+ *
757
+ * Removing it here rather than at each call site means one chokepoint, so a future
758
+ * consumer of `serializeCollections` cannot forget.
759
+ *
760
+ * Child collections carry their own block, so this recurses — stripping only the
761
+ * top level was the mistake `stripNonClientFields` in the contract routes already
762
+ * had to fix once for security rules.
763
+ */
764
+ function withoutAdminBlock(collection) {
765
+ const { admin: _admin, ...rest } = collection;
766
+ const nested = rest;
767
+ if (Array.isArray(nested.subcollections)) nested.subcollections = nested.subcollections.map((child) => withoutAdminBlock(child));
768
+ return rest;
769
+ }
770
+ /**
667
771
  * Rebuild collections received from a contract endpoint.
668
772
  *
669
773
  * Relation refs become real thunks resolving through the returned set, so
@@ -837,6 +941,6 @@ function isPublicStoragePath(path) {
837
941
  return p.startsWith("public/") || p.startsWith(`default/public/`);
838
942
  }
839
943
  //#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 };
944
+ 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
945
 
842
946
  //# sourceMappingURL=index.es.js.map