@rebasepro/server-postgresql 0.0.1-canary.4d4fb3e

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 (147) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +106 -0
  3. package/build-errors.txt +37 -0
  4. package/dist/common/src/collections/CollectionRegistry.d.ts +48 -0
  5. package/dist/common/src/collections/index.d.ts +1 -0
  6. package/dist/common/src/data/buildRebaseData.d.ts +14 -0
  7. package/dist/common/src/index.d.ts +3 -0
  8. package/dist/common/src/util/builders.d.ts +57 -0
  9. package/dist/common/src/util/callbacks.d.ts +6 -0
  10. package/dist/common/src/util/collections.d.ts +11 -0
  11. package/dist/common/src/util/common.d.ts +2 -0
  12. package/dist/common/src/util/conditions.d.ts +26 -0
  13. package/dist/common/src/util/entities.d.ts +36 -0
  14. package/dist/common/src/util/enums.d.ts +3 -0
  15. package/dist/common/src/util/index.d.ts +16 -0
  16. package/dist/common/src/util/navigation_from_path.d.ts +34 -0
  17. package/dist/common/src/util/navigation_utils.d.ts +20 -0
  18. package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
  19. package/dist/common/src/util/paths.d.ts +14 -0
  20. package/dist/common/src/util/permissions.d.ts +5 -0
  21. package/dist/common/src/util/references.d.ts +2 -0
  22. package/dist/common/src/util/relations.d.ts +12 -0
  23. package/dist/common/src/util/resolutions.d.ts +72 -0
  24. package/dist/common/src/util/storage.d.ts +24 -0
  25. package/dist/index.es.js +10635 -0
  26. package/dist/index.es.js.map +1 -0
  27. package/dist/index.umd.js +10643 -0
  28. package/dist/index.umd.js.map +1 -0
  29. package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +112 -0
  30. package/dist/server-postgresql/src/PostgresBootstrapper.d.ts +40 -0
  31. package/dist/server-postgresql/src/auth/ensure-tables.d.ts +6 -0
  32. package/dist/server-postgresql/src/auth/services.d.ts +188 -0
  33. package/dist/server-postgresql/src/cli.d.ts +1 -0
  34. package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +43 -0
  35. package/dist/server-postgresql/src/connection.d.ts +7 -0
  36. package/dist/server-postgresql/src/data-transformer.d.ts +36 -0
  37. package/dist/server-postgresql/src/databasePoolManager.d.ts +20 -0
  38. package/dist/server-postgresql/src/history/HistoryService.d.ts +71 -0
  39. package/dist/server-postgresql/src/history/ensure-history-table.d.ts +7 -0
  40. package/dist/server-postgresql/src/index.d.ts +13 -0
  41. package/dist/server-postgresql/src/interfaces.d.ts +18 -0
  42. package/dist/server-postgresql/src/schema/auth-schema.d.ts +767 -0
  43. package/dist/server-postgresql/src/schema/generate-drizzle-schema-logic.d.ts +2 -0
  44. package/dist/server-postgresql/src/schema/generate-drizzle-schema.d.ts +1 -0
  45. package/dist/server-postgresql/src/services/BranchService.d.ts +47 -0
  46. package/dist/server-postgresql/src/services/EntityFetchService.d.ts +195 -0
  47. package/dist/server-postgresql/src/services/EntityPersistService.d.ts +41 -0
  48. package/dist/server-postgresql/src/services/RelationService.d.ts +92 -0
  49. package/dist/server-postgresql/src/services/entity-helpers.d.ts +24 -0
  50. package/dist/server-postgresql/src/services/entityService.d.ts +102 -0
  51. package/dist/server-postgresql/src/services/index.d.ts +4 -0
  52. package/dist/server-postgresql/src/services/realtimeService.d.ts +186 -0
  53. package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +116 -0
  54. package/dist/server-postgresql/src/websocket.d.ts +5 -0
  55. package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
  56. package/dist/types/src/controllers/auth.d.ts +117 -0
  57. package/dist/types/src/controllers/client.d.ts +58 -0
  58. package/dist/types/src/controllers/collection_registry.d.ts +44 -0
  59. package/dist/types/src/controllers/customization_controller.d.ts +54 -0
  60. package/dist/types/src/controllers/data.d.ts +141 -0
  61. package/dist/types/src/controllers/data_driver.d.ts +168 -0
  62. package/dist/types/src/controllers/database_admin.d.ts +11 -0
  63. package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
  64. package/dist/types/src/controllers/effective_role.d.ts +4 -0
  65. package/dist/types/src/controllers/index.d.ts +17 -0
  66. package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
  67. package/dist/types/src/controllers/navigation.d.ts +213 -0
  68. package/dist/types/src/controllers/registry.d.ts +51 -0
  69. package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
  70. package/dist/types/src/controllers/side_entity_controller.d.ts +89 -0
  71. package/dist/types/src/controllers/snackbar.d.ts +24 -0
  72. package/dist/types/src/controllers/storage.d.ts +173 -0
  73. package/dist/types/src/index.d.ts +4 -0
  74. package/dist/types/src/rebase_context.d.ts +101 -0
  75. package/dist/types/src/types/backend.d.ts +533 -0
  76. package/dist/types/src/types/builders.d.ts +14 -0
  77. package/dist/types/src/types/chips.d.ts +5 -0
  78. package/dist/types/src/types/collections.d.ts +812 -0
  79. package/dist/types/src/types/data_source.d.ts +64 -0
  80. package/dist/types/src/types/entities.d.ts +145 -0
  81. package/dist/types/src/types/entity_actions.d.ts +98 -0
  82. package/dist/types/src/types/entity_callbacks.d.ts +173 -0
  83. package/dist/types/src/types/entity_link_builder.d.ts +7 -0
  84. package/dist/types/src/types/entity_overrides.d.ts +9 -0
  85. package/dist/types/src/types/entity_views.d.ts +61 -0
  86. package/dist/types/src/types/export_import.d.ts +21 -0
  87. package/dist/types/src/types/index.d.ts +22 -0
  88. package/dist/types/src/types/locales.d.ts +4 -0
  89. package/dist/types/src/types/modify_collections.d.ts +5 -0
  90. package/dist/types/src/types/plugins.d.ts +225 -0
  91. package/dist/types/src/types/properties.d.ts +1091 -0
  92. package/dist/types/src/types/property_config.d.ts +70 -0
  93. package/dist/types/src/types/relations.d.ts +336 -0
  94. package/dist/types/src/types/slots.d.ts +228 -0
  95. package/dist/types/src/types/translations.d.ts +826 -0
  96. package/dist/types/src/types/user_management_delegate.d.ts +120 -0
  97. package/dist/types/src/types/websockets.d.ts +78 -0
  98. package/dist/types/src/users/index.d.ts +2 -0
  99. package/dist/types/src/users/roles.d.ts +22 -0
  100. package/dist/types/src/users/user.d.ts +46 -0
  101. package/jest-all.log +3128 -0
  102. package/jest.log +49 -0
  103. package/package.json +93 -0
  104. package/src/PostgresBackendDriver.ts +1024 -0
  105. package/src/PostgresBootstrapper.ts +232 -0
  106. package/src/auth/ensure-tables.ts +309 -0
  107. package/src/auth/services.ts +740 -0
  108. package/src/cli.ts +347 -0
  109. package/src/collections/PostgresCollectionRegistry.ts +96 -0
  110. package/src/connection.ts +62 -0
  111. package/src/data-transformer.ts +569 -0
  112. package/src/databasePoolManager.ts +84 -0
  113. package/src/history/HistoryService.ts +257 -0
  114. package/src/history/ensure-history-table.ts +45 -0
  115. package/src/index.ts +13 -0
  116. package/src/interfaces.ts +60 -0
  117. package/src/schema/auth-schema.ts +146 -0
  118. package/src/schema/generate-drizzle-schema-logic.ts +618 -0
  119. package/src/schema/generate-drizzle-schema.ts +151 -0
  120. package/src/services/BranchService.ts +237 -0
  121. package/src/services/EntityFetchService.ts +1447 -0
  122. package/src/services/EntityPersistService.ts +351 -0
  123. package/src/services/RelationService.ts +1012 -0
  124. package/src/services/entity-helpers.ts +121 -0
  125. package/src/services/entityService.ts +209 -0
  126. package/src/services/index.ts +13 -0
  127. package/src/services/realtimeService.ts +1005 -0
  128. package/src/utils/drizzle-conditions.ts +999 -0
  129. package/src/websocket.ts +487 -0
  130. package/test/auth-services.test.ts +569 -0
  131. package/test/branchService.test.ts +357 -0
  132. package/test/drizzle-conditions.test.ts +895 -0
  133. package/test/entityService.errors.test.ts +352 -0
  134. package/test/entityService.relations.test.ts +912 -0
  135. package/test/entityService.subcollection-search.test.ts +516 -0
  136. package/test/entityService.test.ts +977 -0
  137. package/test/generate-drizzle-schema.test.ts +795 -0
  138. package/test/historyService.test.ts +126 -0
  139. package/test/postgresDataDriver.test.ts +556 -0
  140. package/test/realtimeService.test.ts +276 -0
  141. package/test/relations.test.ts +662 -0
  142. package/test_drizzle_mock.js +3 -0
  143. package/test_find_changed.mjs +30 -0
  144. package/test_output.txt +3145 -0
  145. package/tsconfig.json +49 -0
  146. package/tsconfig.prod.json +20 -0
  147. package/vite.config.ts +82 -0
@@ -0,0 +1,141 @@
1
+ import { Entity, EntityValues } from "../types/entities";
2
+ /**
3
+ * Parameters for querying a collection.
4
+ * Uses PostgREST-style filter syntax for consistency between
5
+ * the SDK (HTTP) and framework (in-process) contexts.
6
+ *
7
+ * @group Data
8
+ */
9
+ export interface FindParams {
10
+ /** Maximum number of items to return (default: 20) */
11
+ limit?: number;
12
+ /** Number of items to skip */
13
+ offset?: number;
14
+ /** Page number (1-indexed), alternative to offset */
15
+ page?: number;
16
+ /**
17
+ * PostgREST-style filter object.
18
+ * Keys are field names, values use "operator.value" format.
19
+ * Operators: eq, neq, gt, gte, lt, lte, in, nin, cs (array-contains), csa (array-contains-any)
20
+ *
21
+ * @example
22
+ * { status: "eq.published" }
23
+ * { age: "gte.18" }
24
+ * { role: "in.(admin,editor)" }
25
+ */
26
+ where?: Record<string, string>;
27
+ /**
28
+ * Sort order. Format: "field:direction".
29
+ * @example "created_at:desc", "name:asc"
30
+ */
31
+ orderBy?: string;
32
+ /** Relations to include in the response */
33
+ include?: string[];
34
+ /** Full-text search string */
35
+ searchString?: string;
36
+ }
37
+ /**
38
+ * Paginated response from a collection query.
39
+ * @group Data
40
+ */
41
+ export interface FindResponse<M extends Record<string, any> = any> {
42
+ /** Array of entities matching the query */
43
+ data: Entity<M>[];
44
+ /** Pagination metadata */
45
+ meta: {
46
+ total: number;
47
+ limit: number;
48
+ offset: number;
49
+ hasMore: boolean;
50
+ };
51
+ }
52
+ /**
53
+ * A single collection's CRUD accessor.
54
+ *
55
+ * This is the unified API surface used in both:
56
+ * - The generated SDK (`client.data.products.create(...)`)
57
+ * - Framework callbacks (`context.data.products.create(...)`)
58
+ *
59
+ * @group Data
60
+ */
61
+ export interface CollectionAccessor<M extends Record<string, any> = any> {
62
+ /**
63
+ * Find multiple records with optional filtering, pagination, and sorting.
64
+ */
65
+ find(params?: FindParams): Promise<FindResponse<M>>;
66
+ /**
67
+ * Find a single record by its ID.
68
+ */
69
+ findById(id: string | number): Promise<Entity<M> | undefined>;
70
+ /**
71
+ * Create a new record.
72
+ * @param data The entity data to create.
73
+ * @param id Optional specific ID to use for the new record.
74
+ * @returns The created entity
75
+ */
76
+ create(data: Partial<EntityValues<M>>, id?: string | number): Promise<Entity<M>>;
77
+ /**
78
+ * Update an existing record by ID.
79
+ * @returns The updated entity
80
+ */
81
+ update(id: string | number, data: Partial<EntityValues<M>>): Promise<Entity<M>>;
82
+ /**
83
+ * Delete a record by ID.
84
+ */
85
+ delete(id: string | number): Promise<void>;
86
+ /**
87
+ * Subscribe to a collection for real-time updates.
88
+ * Optional method, may not be supported by all implementations (like stateless HTTP clients).
89
+ */
90
+ listen?(params: FindParams | undefined, onUpdate: (response: FindResponse<M>) => void, onError?: (error: Error) => void): () => void;
91
+ /**
92
+ * Subscribe to a single record for real-time updates.
93
+ * Optional method.
94
+ */
95
+ listenById?(id: string | number, onUpdate: (entity: Entity<M> | undefined) => void, onError?: (error: Error) => void): () => void;
96
+ /**
97
+ * Count the number of records matching the given filter.
98
+ */
99
+ count?(params?: FindParams): Promise<number>;
100
+ }
101
+ /**
102
+ * The unified data access object.
103
+ *
104
+ * Access collections as dynamic properties: `data.products.find(...)`.
105
+ * In the SDK this is backed by HTTP transport (typed, generated per-project).
106
+ * In the framework this is backed by a Proxy + in-process database driver (dynamic).
107
+ *
108
+ * @example
109
+ * // SDK
110
+ * const client = createRebaseClient({ baseUrl: "..." });
111
+ * await client.data.products.create({ name: "Camera", price: 299 });
112
+ *
113
+ * // Framework callback
114
+ * callbacks: {
115
+ * afterSave({ context }) {
116
+ * await context.data.logs.create({ action: "saved", timestamp: new Date() });
117
+ * }
118
+ * }
119
+ *
120
+ * @group Data
121
+ */
122
+ export interface RebaseData {
123
+ /**
124
+ * Get a collection accessor by slug.
125
+ * Alternative to dynamic property access for cases where
126
+ * the collection name is a variable.
127
+ *
128
+ * @example
129
+ * const accessor = data.collection("products");
130
+ * await accessor.find({ limit: 10 });
131
+ */
132
+ collection(slug: string): CollectionAccessor;
133
+ /**
134
+ * Dynamic collection accessor.
135
+ * Access any collection by its slug as a property.
136
+ *
137
+ * @example
138
+ * data.products.find({ where: { status: "eq.published" } })
139
+ */
140
+ [collectionSlug: string]: CollectionAccessor | ((slug: string) => CollectionAccessor);
141
+ }
@@ -0,0 +1,168 @@
1
+ import { Entity, EntityCollection, EntityStatus, EntityValues, FilterValues } from "../types";
2
+ import { RebaseContext } from "../rebase_context";
3
+ import { TableMetadata } from "../types/websockets";
4
+ /**
5
+ * @internal
6
+ */
7
+ export interface FetchEntityProps<M extends Record<string, any> = any> {
8
+ path: string;
9
+ entityId: string | number;
10
+ databaseId?: string;
11
+ collection?: EntityCollection<M, any>;
12
+ }
13
+ /**
14
+ * @internal
15
+ */
16
+ export type ListenEntityProps<M extends Record<string, any> = any> = FetchEntityProps<M> & {
17
+ onUpdate: (entity: Entity<M> | null) => void;
18
+ onError?: (error: Error) => void;
19
+ };
20
+ /**
21
+ * @internal
22
+ */
23
+ export interface FetchCollectionProps<M extends Record<string, any> = any> {
24
+ path: string;
25
+ collection?: EntityCollection<M>;
26
+ filter?: FilterValues<Extract<keyof M, string>>;
27
+ limit?: number;
28
+ startAfter?: unknown;
29
+ orderBy?: string;
30
+ searchString?: string;
31
+ order?: "desc" | "asc";
32
+ }
33
+ /**
34
+ * @internal
35
+ */
36
+ export type ListenCollectionProps<M extends Record<string, any> = any> = FetchCollectionProps<M> & {
37
+ onUpdate: (entities: Entity<M>[]) => void;
38
+ onError?: (error: Error) => void;
39
+ };
40
+ /**
41
+ * @internal
42
+ */
43
+ export interface SaveEntityProps<M extends Record<string, any> = any> {
44
+ path: string;
45
+ values: Partial<EntityValues<M>>;
46
+ entityId?: string | number;
47
+ previousValues?: Partial<EntityValues<M>>;
48
+ collection?: EntityCollection<M>;
49
+ status: EntityStatus;
50
+ }
51
+ /**
52
+ * @internal
53
+ */
54
+ export interface DeleteEntityProps<M extends Record<string, any> = any> {
55
+ entity: Entity<M>;
56
+ collection?: EntityCollection<M>;
57
+ }
58
+ export type FilterCombinationValidProps = {
59
+ path: string;
60
+ databaseId?: string;
61
+ collection: EntityCollection<any>;
62
+ filterValues: FilterValues<any>;
63
+ sortBy?: [string, "asc" | "desc"];
64
+ };
65
+ /**
66
+ * Internal driver interface for communicating with the data layer.
67
+ * This is NOT the public API — use `RebaseData` / `context.data` instead.
68
+ * @internal
69
+ */
70
+ export interface DataDriver {
71
+ /**
72
+ * Key that identifies this driver
73
+ */
74
+ key?: string;
75
+ /**
76
+ * If the driver has been initialised
77
+ */
78
+ initialised?: boolean;
79
+ /**
80
+ * Fetch data from a collection
81
+ * @param props
82
+ * @return Promise of entities
83
+ */
84
+ fetchCollection<M extends Record<string, any> = any>(props: FetchCollectionProps<M>): Promise<Entity<M>[]>;
85
+ /**
86
+ * Listen to a collection in a given path. If you don't implement this method
87
+ * `fetchCollection` will be used instead, with no real time updates.
88
+ * @param props
89
+ * @return Function to cancel subscription
90
+ */
91
+ listenCollection?<M extends Record<string, any> = any>(props: ListenCollectionProps<M>): () => void;
92
+ /**
93
+ * Retrieve an entity given a path and a collection
94
+ * @param props
95
+ */
96
+ fetchEntity<M extends Record<string, any> = any>(props: FetchEntityProps<M>): Promise<Entity<M> | undefined>;
97
+ /**
98
+ * Get realtime updates on one entity.
99
+ * @param props
100
+ * @return Function to cancel subscription
101
+ */
102
+ listenEntity?<M extends Record<string, any> = any>(props: ListenEntityProps<M>): () => void;
103
+ /**
104
+ * Save entity to the specified path
105
+ * @param props
106
+ */
107
+ saveEntity<M extends Record<string, any> = any>(props: SaveEntityProps<M>): Promise<Entity<M>>;
108
+ /**
109
+ * Delete an entity
110
+ * @param props
111
+ * @return was the whole deletion flow successful
112
+ */
113
+ deleteEntity<M extends Record<string, any> = any>(props: DeleteEntityProps<M>): Promise<void>;
114
+ /**
115
+ * Check if the given property is unique in the given collection
116
+ * @param path Collection path
117
+ * @param name of the property
118
+ * @param value
119
+ * @param entityId
120
+ * @param collection
121
+ * @return `true` if there are no other fields besides the given entity
122
+ */
123
+ checkUniqueField(path: string, name: string, value: unknown, entityId?: string | number, collection?: EntityCollection): Promise<boolean>;
124
+ /**
125
+ * Count the number of entities in a collection
126
+ */
127
+ countEntities?<M extends Record<string, any> = any>(props: FetchCollectionProps<M>): Promise<number>;
128
+ /**
129
+ * Check if the given filter combination is valid
130
+ * @param props
131
+ */
132
+ isFilterCombinationValid?(props: Omit<FilterCombinationValidProps, "collection"> & {
133
+ databaseId?: string;
134
+ }): boolean;
135
+ /**
136
+ * Get the object to generate the current time in the driver
137
+ */
138
+ currentTime?: () => unknown;
139
+ delegateToCMSModel?: (data: unknown) => unknown;
140
+ cmsToDelegateModel?: (data: unknown) => unknown;
141
+ initTextSearch?: (props: {
142
+ context: RebaseContext;
143
+ path: string;
144
+ databaseId?: string;
145
+ collection: EntityCollection;
146
+ parentCollectionIds?: string[];
147
+ }) => Promise<boolean>;
148
+ /**
149
+ * Flag to indicate if the driver has requested the initialization of the text search index
150
+ */
151
+ needsInitTextSearch?: boolean;
152
+ /**
153
+ * Return the admin capabilities of this driver.
154
+ * @see SQLAdmin
155
+ * @see DocumentAdmin
156
+ * @see SchemaAdmin
157
+ */
158
+ admin?: import("../types/backend").DatabaseAdmin;
159
+ executeSql?(sql: string, options?: {
160
+ database?: string;
161
+ role?: string;
162
+ }): Promise<Record<string, unknown>[]>;
163
+ fetchAvailableDatabases?(): Promise<string[]>;
164
+ fetchAvailableRoles?(): Promise<string[]>;
165
+ fetchCurrentDatabase?(): Promise<string | undefined>;
166
+ fetchUnmappedTables?(mappedPaths?: string[]): Promise<string[]>;
167
+ fetchTableMetadata?(tableName: string): Promise<TableMetadata>;
168
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module database_admin
3
+ *
4
+ * Re-exports the capability-specific admin interfaces from `@rebasepro/types/backend`.
5
+ * This file is kept for backwards compatibility — new code should import from
6
+ * `@rebasepro/types` directly.
7
+ *
8
+ * @group Admin
9
+ */
10
+ export type { SQLAdmin, DocumentAdmin, SchemaAdmin, DatabaseAdmin, HealthCheckResult, } from "../types/backend";
11
+ export { isSQLAdmin, isDocumentAdmin, isSchemaAdmin, } from "../types/backend";
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ /**
3
+ * Controller to open the side dialog
4
+ * @group Hooks and utilities
5
+ */
6
+ export interface DialogsController {
7
+ /**
8
+ * Close the last dialog
9
+ */
10
+ close: () => void;
11
+ /**
12
+ * Open a dialog
13
+ * @param props
14
+ */
15
+ open: <T extends object = object>(props: DialogControllerEntryProps<T>) => {
16
+ closeDialog: () => void;
17
+ };
18
+ }
19
+ /**
20
+ * Props used to open a side dialog
21
+ * @group Hooks and utilities
22
+ */
23
+ export interface DialogControllerEntryProps<T extends object = object> {
24
+ key: string;
25
+ /**
26
+ * The component type that will be rendered
27
+ */
28
+ Component: React.ComponentType<{
29
+ open: boolean;
30
+ closeDialog: () => void;
31
+ } & T>;
32
+ /**
33
+ * Props to pass to the dialog component
34
+ */
35
+ props?: T;
36
+ }
@@ -0,0 +1,4 @@
1
+ export interface EffectiveRoleController {
2
+ effectiveRole: string | null;
3
+ setEffectiveRole: (role: string | null) => void;
4
+ }
@@ -0,0 +1,17 @@
1
+ export * from "./collection_registry";
2
+ export * from "./analytics_controller";
3
+ export * from "./auth";
4
+ export * from "./data";
5
+ export * from "./database_admin";
6
+ export * from "./data_driver";
7
+ export * from "./local_config_persistence";
8
+ export * from "./navigation";
9
+ export * from "./effective_role";
10
+ export * from "./storage";
11
+ export * from "./client";
12
+ export * from "./customization_controller";
13
+ export * from "./side_entity_controller";
14
+ export * from "./side_dialogs_controller";
15
+ export * from "./dialogs_controller";
16
+ export * from "./snackbar";
17
+ export * from "./registry";
@@ -0,0 +1,20 @@
1
+ import { EntityCollection } from "../types";
2
+ /**
3
+ * @group Models
4
+ */
5
+ export type PartialEntityCollection<M extends Record<string, any> = any> = Partial<EntityCollection<M>>;
6
+ /**
7
+ * This interface is in charge of defining the controller that persists
8
+ * modifications to a collection or collection, and retrieves them back from
9
+ * a data source, such as local storage or Firestore.
10
+ */
11
+ export interface UserConfigurationPersistence {
12
+ onCollectionModified: <M extends Record<string, any> = any>(path: string, partialCollection: PartialEntityCollection<M>) => void;
13
+ getCollectionConfig: <M extends Record<string, any> = any>(path: string) => PartialEntityCollection<M>;
14
+ recentlyVisitedPaths: string[];
15
+ setRecentlyVisitedPaths: (paths: string[]) => void;
16
+ favouritePaths: string[];
17
+ setFavouritePaths: (paths: string[]) => void;
18
+ collapsedGroups: string[];
19
+ setCollapsedGroups: (paths: string[]) => void;
20
+ }
@@ -0,0 +1,213 @@
1
+ import React from "react";
2
+ import { EntityCollection } from "../types/collections";
3
+ import { RebasePlugin } from "../types/plugins";
4
+ /**
5
+ * Controller that handles URL path building and resolution.
6
+ * @group Models
7
+ */
8
+ export type UrlController = {
9
+ /**
10
+ * Default path under the navigation routes of the CMS will be created.
11
+ * Defaults to '/'. You may want to change this `basepath` to 'admin' for example.
12
+ */
13
+ basePath: string;
14
+ /**
15
+ * Default path under the collection routes of the CMS will be created.
16
+ * It defaults to '/c'
17
+ */
18
+ baseCollectionPath: string;
19
+ /**
20
+ * Convert a URL path to a collection or entity path
21
+ * `/c/products` => `products`
22
+ * `/my_cms/c/products/B34SAP8Z` => `products/B34SAP8Z`
23
+ * `/my_cms/my_view` => `my_view`
24
+ * @param cmsPath
25
+ */
26
+ urlPathToDataPath: (cmsPath: string) => string;
27
+ /**
28
+ * Base url path for the home screen
29
+ */
30
+ homeUrl: string;
31
+ /**
32
+ * Check if a url path belongs to a collection
33
+ * @param path
34
+ */
35
+ isUrlCollectionPath: (urlPath: string) => boolean;
36
+ /**
37
+ * Build a URL collection path from a data path
38
+ * `products` => `/c/products`
39
+ * `products/B34SAP8Z` => `/c/products/B34SAP8Z`
40
+ * @param path
41
+ */
42
+ buildUrlCollectionPath: (path: string) => string;
43
+ /**
44
+ * Build a URL path for the CMS (e.g. for custom views)
45
+ * @param path
46
+ */
47
+ buildAppUrlPath: (path: string) => string;
48
+ /**
49
+ * Turn a path with collection ids into a resolved path.
50
+ * The ids (typically used in urls) will be replaced with relative paths (typically used in database paths)
51
+ * @param path
52
+ */
53
+ resolveDatabasePathsFrom: (path: string) => string;
54
+ /**
55
+ * A function to navigate to a specified route or URL.
56
+ *
57
+ * @param {string} to - The target route or URL to navigate to.
58
+ * @param {NavigateOptions} [options] - Optional configuration settings for navigation, such as replace behavior or state data.
59
+ */
60
+ navigate: (to: string, options?: NavigateOptions) => void;
61
+ };
62
+ /**
63
+ * Controller that manages the state of the navigation menu,
64
+ * including resolved views and top-level grouping.
65
+ * @group Models
66
+ */
67
+ export type NavigationStateController = {
68
+ /**
69
+ * Custom additional views created by the developer, added to the main
70
+ * navigation
71
+ */
72
+ views?: AppView[];
73
+ /**
74
+ * Custom additional views created by the developer, added to the admin
75
+ * navigation
76
+ */
77
+ adminViews?: AppView[];
78
+ /**
79
+ * Configuration for the views that should be displayed at the top
80
+ * level of the navigation (e.g. in the home page or the navigation
81
+ * drawer)
82
+ */
83
+ topLevelNavigation?: NavigationResult;
84
+ /**
85
+ * Is the navigation loading (the configuration persistence has not
86
+ * loaded yet, or a specified navigation builder has not completed)
87
+ */
88
+ loading: boolean;
89
+ /**
90
+ * Was there an error while loading the navigation data
91
+ */
92
+ navigationLoadingError?: unknown;
93
+ /**
94
+ * Call this method to recalculate the navigation
95
+ */
96
+ refreshNavigation: () => void;
97
+ /**
98
+ * Plugin system allowing to extend the CMS functionality.
99
+ */
100
+ plugins?: RebasePlugin[];
101
+ };
102
+ export interface NavigateOptions {
103
+ replace?: boolean;
104
+ state?: unknown;
105
+ preventScrollReset?: boolean;
106
+ relative?: "route" | "path";
107
+ flushSync?: boolean;
108
+ viewTransition?: boolean;
109
+ }
110
+ export type NavigationBlocker = {
111
+ updateBlockListener: (path: string, block: boolean, basePath?: string) => () => void;
112
+ isBlocked: (path: string) => boolean;
113
+ proceed?: () => void;
114
+ reset?: () => void;
115
+ };
116
+ /**
117
+ * Custom additional views created by the developer, added to the main
118
+ * navigation.
119
+ * @group Models
120
+ */
121
+ export interface AppView {
122
+ /**
123
+ * CMS Path you can reach this view from.
124
+ */
125
+ slug: string;
126
+ /**
127
+ * Name of this view
128
+ */
129
+ name: string;
130
+ /**
131
+ * Optional description of this view. You can use Markdown
132
+ */
133
+ description?: string;
134
+ /**
135
+ * Icon key to use in this view.
136
+ * You can use any of the icons in the Material specs:
137
+ * https://fonts.google.com/icons
138
+ * e.g. 'account_tree' or 'person'
139
+ * Find all the icons in https://rebase.pro/docs/icons
140
+ */
141
+ icon?: string | React.ReactNode;
142
+ /**
143
+ * Should this view be hidden from the main navigation panel.
144
+ * It will still be accessible if you reach the specified path
145
+ */
146
+ hideFromNavigation?: boolean;
147
+ /**
148
+ * Component to be rendered. This can be any React component, and can use
149
+ * any of the provided hooks
150
+ */
151
+ view: React.ReactNode;
152
+ /**
153
+ * Optional field used to group top level navigation entries under a
154
+ * navigation view.
155
+ * This prop is ignored for admin views.
156
+ */
157
+ group?: string;
158
+ /**
159
+ * If true, a wildcard route (slug/*) is automatically registered
160
+ * alongside the base route, enabling nested navigation within this view.
161
+ */
162
+ nestedRoutes?: boolean;
163
+ }
164
+ /**
165
+ * A composable section that can be rendered on the home page.
166
+ * Use this to add custom content alongside the auto-generated
167
+ * navigation groups.
168
+ * @group Models
169
+ */
170
+ export interface HomePageSection {
171
+ /**
172
+ * Unique key for this section.
173
+ */
174
+ key: string;
175
+ /**
176
+ * Title displayed as the section header.
177
+ */
178
+ title: string;
179
+ /**
180
+ * Arbitrary React content rendered inside the section.
181
+ */
182
+ children: React.ReactNode;
183
+ }
184
+ /**
185
+ * Used to group navigation entries in the main navigation.
186
+ */
187
+ export interface NavigationGroupMapping {
188
+ /**
189
+ * Name of the group, used to display the group header in the UI
190
+ */
191
+ name: string;
192
+ /**
193
+ * List of collection ids or view paths that belong to this group.
194
+ */
195
+ entries: string[];
196
+ }
197
+ export interface NavigationEntry {
198
+ id: string;
199
+ url: string;
200
+ name: string;
201
+ slug: string;
202
+ type: "collection" | "view" | "admin";
203
+ collection?: EntityCollection;
204
+ view?: AppView;
205
+ description?: string;
206
+ group: string;
207
+ }
208
+ export type NavigationResult = {
209
+ allowDragAndDrop: boolean;
210
+ navigationEntries: NavigationEntry[];
211
+ groups: string[];
212
+ onNavigationEntriesUpdate: (entries: NavigationGroupMapping[]) => void;
213
+ };
@@ -0,0 +1,51 @@
1
+ import { ReactNode } from "react";
2
+ import { EntityCollection, EntityCollectionsBuilder, EntityCustomView, EntityAction } from "../types";
3
+ import { AppView } from "./navigation";
4
+ /**
5
+ * Options to enable the built-in collection editor.
6
+ * When provided to `<RebaseCMS>`, the editor is auto-wired as a native feature.
7
+ */
8
+ export interface CollectionEditorOptions {
9
+ /**
10
+ * Function that returns an auth token for schema-editor API calls.
11
+ * Falls back to `authController.getAuthToken` when omitted.
12
+ */
13
+ getAuthToken?: () => Promise<string | null>;
14
+ /** Mark the editor as read-only (disable mutations). */
15
+ readOnly?: boolean;
16
+ /** Suggested base paths shown when creating new collections. */
17
+ pathSuggestions?: string[];
18
+ }
19
+ export interface RebaseCMSConfig<EC extends EntityCollection = any> {
20
+ collections?: EC[] | EntityCollectionsBuilder<EC>;
21
+ homePage?: ReactNode;
22
+ entityViews?: EntityCustomView<any>[];
23
+ entityActions?: EntityAction[];
24
+ plugins?: any[];
25
+ /**
26
+ * Enable the built-in visual collection/schema editor.
27
+ * Pass `true` for zero-config, or an options object for fine-grained control.
28
+ * When enabled, the editor slots, provider, and Studio schema view
29
+ * are all auto-wired — no plugin or manual view injection needed.
30
+ */
31
+ collectionEditor?: boolean | CollectionEditorOptions;
32
+ }
33
+ export interface RebaseStudioConfig {
34
+ tools?: ("sql" | "js" | "rls" | "schema" | "storage")[];
35
+ homePage?: ReactNode;
36
+ devViews?: AppView[];
37
+ }
38
+ export interface RebaseAuthConfig {
39
+ loginView?: ReactNode;
40
+ }
41
+ export interface RebaseRegistryController {
42
+ cmsConfig: RebaseCMSConfig | null;
43
+ studioConfig: RebaseStudioConfig | null;
44
+ authConfig: RebaseAuthConfig | null;
45
+ registerCMS: (config: RebaseCMSConfig) => void;
46
+ unregisterCMS: () => void;
47
+ registerStudio: (config: RebaseStudioConfig) => void;
48
+ unregisterStudio: () => void;
49
+ registerAuth: (config: RebaseAuthConfig) => void;
50
+ unregisterAuth: () => void;
51
+ }