@rebasepro/types 0.10.0 → 0.10.1-canary.0a881d4

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 (96) 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/client.d.ts +3 -1
  4. package/dist/controllers/collection_registry.d.ts +5 -1
  5. package/dist/controllers/data_driver.d.ts +31 -2
  6. package/dist/controllers/index.d.ts +1 -10
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.es.js +374 -1
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/types/admin_block.d.ts +34 -0
  11. package/dist/types/backend.d.ts +30 -1
  12. package/dist/types/channel_bus.d.ts +192 -0
  13. package/dist/types/collection_contract.d.ts +43 -0
  14. package/dist/types/collections.d.ts +17 -789
  15. package/dist/types/component_ref.d.ts +39 -6
  16. package/dist/types/entity_callbacks.d.ts +1 -1
  17. package/dist/types/index.d.ts +7 -15
  18. package/dist/types/project_manifest.d.ts +336 -0
  19. package/dist/types/properties.d.ts +12 -157
  20. package/dist/types/schema_version.d.ts +18 -0
  21. package/dist/types/security_rules.d.ts +320 -0
  22. package/dist/types/storage_authorize.d.ts +74 -0
  23. package/package.json +3 -6
  24. package/src/call_context.ts +56 -0
  25. package/src/controllers/auth_state.ts +24 -0
  26. package/src/controllers/client.ts +3 -2
  27. package/src/controllers/collection_registry.ts +5 -1
  28. package/src/controllers/data_driver.ts +58 -2
  29. package/src/controllers/index.ts +1 -10
  30. package/src/index.ts +1 -1
  31. package/src/types/admin_block.ts +75 -0
  32. package/src/types/backend.ts +33 -1
  33. package/src/types/channel_bus.ts +202 -0
  34. package/src/types/collection_contract.ts +278 -0
  35. package/src/types/collections.ts +25 -848
  36. package/src/types/component_ref.ts +40 -6
  37. package/src/types/entity_callbacks.ts +1 -1
  38. package/src/types/index.ts +7 -15
  39. package/src/types/policy.ts +25 -11
  40. package/src/types/project_manifest.ts +362 -0
  41. package/src/types/properties.ts +11 -169
  42. package/src/types/schema_version.ts +112 -0
  43. package/src/types/security_rules.ts +344 -0
  44. package/src/types/storage_authorize.ts +77 -0
  45. package/dist/controllers/analytics_controller.d.ts +0 -7
  46. package/dist/controllers/auth.d.ts +0 -110
  47. package/dist/controllers/customization_controller.d.ts +0 -61
  48. package/dist/controllers/dialogs_controller.d.ts +0 -36
  49. package/dist/controllers/local_config_persistence.d.ts +0 -20
  50. package/dist/controllers/navigation.d.ts +0 -225
  51. package/dist/controllers/registry.d.ts +0 -80
  52. package/dist/controllers/side_dialogs_controller.d.ts +0 -67
  53. package/dist/controllers/side_panel_controller.d.ts +0 -97
  54. package/dist/controllers/snackbar.d.ts +0 -24
  55. package/dist/rebase_context.d.ts +0 -110
  56. package/dist/types/breadcrumbs.d.ts +0 -26
  57. package/dist/types/builders.d.ts +0 -15
  58. package/dist/types/component_overrides.d.ts +0 -196
  59. package/dist/types/entity_actions.d.ts +0 -104
  60. package/dist/types/entity_link_builder.d.ts +0 -7
  61. package/dist/types/entity_views.d.ts +0 -95
  62. package/dist/types/export_import.d.ts +0 -21
  63. package/dist/types/formex.d.ts +0 -40
  64. package/dist/types/locales.d.ts +0 -4
  65. package/dist/types/modify_collections.d.ts +0 -5
  66. package/dist/types/plugins.d.ts +0 -277
  67. package/dist/types/property_config.d.ts +0 -74
  68. package/dist/types/slots.d.ts +0 -262
  69. package/dist/types/translations.d.ts +0 -915
  70. package/dist/types/user_management_delegate.d.ts +0 -22
  71. package/src/controllers/analytics_controller.tsx +0 -57
  72. package/src/controllers/auth.tsx +0 -121
  73. package/src/controllers/customization_controller.tsx +0 -72
  74. package/src/controllers/dialogs_controller.tsx +0 -37
  75. package/src/controllers/local_config_persistence.tsx +0 -22
  76. package/src/controllers/navigation.ts +0 -267
  77. package/src/controllers/registry.ts +0 -95
  78. package/src/controllers/side_dialogs_controller.tsx +0 -82
  79. package/src/controllers/side_panel_controller.tsx +0 -112
  80. package/src/controllers/snackbar.ts +0 -29
  81. package/src/rebase_context.tsx +0 -130
  82. package/src/types/breadcrumbs.ts +0 -27
  83. package/src/types/builders.ts +0 -17
  84. package/src/types/component_overrides.ts +0 -244
  85. package/src/types/entity_actions.tsx +0 -125
  86. package/src/types/entity_link_builder.ts +0 -8
  87. package/src/types/entity_views.tsx +0 -114
  88. package/src/types/export_import.ts +0 -26
  89. package/src/types/formex.ts +0 -45
  90. package/src/types/locales.ts +0 -81
  91. package/src/types/modify_collections.tsx +0 -6
  92. package/src/types/plugins.tsx +0 -346
  93. package/src/types/property_config.tsx +0 -95
  94. package/src/types/slots.tsx +0 -307
  95. package/src/types/translations.ts +0 -1026
  96. package/src/types/user_management_delegate.ts +0 -23
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The keys of a collection's admin block, as data.
3
+ *
4
+ * There is no *type* for the block in this package any more, and that is the point:
5
+ * `admin` is not declared on `BaseCollectionConfig` or on any property here, so a
6
+ * BaaS install cannot even write one. `@rebasepro/admin-types` adds the field back by
7
+ * declaration merging, which is why installing it is what makes the admin surface
8
+ * appear.
9
+ *
10
+ * The *list* still has to live here, because three runtime consumers need it and two
11
+ * of them are core — see below.
12
+ */
13
+ /**
14
+ * Every key that belongs inside a collection's `admin` block, as data.
15
+ *
16
+ * The type that describes these fields is `AdminCollectionOptions` in
17
+ * `@rebasepro/admin-types`, and it is erased at build time — but three runtime
18
+ * consumers need the list, and two of them are core:
19
+ *
20
+ * - `serializeCollections`, to drop the block from the contract
21
+ * - the ts-morph schema editor in `@rebasepro/server`, which rewrites collection
22
+ * files on disk from the admin panel and has to know where each key goes. A key
23
+ * missing from this list gets written to the *top level* of the file, where the
24
+ * backend ignores it and the panel never finds it again.
25
+ * - the `collections-admin-block` codemod
26
+ *
27
+ * `@rebasepro/admin-types` re-exports this and asserts it names only real option
28
+ * keys; the count is pinned by a test there.
29
+ *
30
+ * @group Models
31
+ */
32
+ export declare const ADMIN_COLLECTION_KEYS: readonly ["Actions", "additionalFields", "alwaysApplyDefaultValues", "components", "defaultEntityAction", "defaultFilter", "defaultSelectedView", "defaultSize", "defaultViewMode", "disableDefaultActions", "enabledViews", "entityActions", "entityViews", "exportable", "filterPresets", "fixedFilter", "formAutoSave", "formView", "group", "hideFromNavigation", "hideIdFromCollection", "hideIdFromForm", "icon", "includeJsonView", "inlineEditing", "kanban", "listProperties", "localChangesBackup", "openEntityMode", "orderProperty", "pagination", "previewProperties", "propertiesOrder", "selectionController", "selectionEnabled", "sideDialogWidth", "sort", "titleProperty"];
33
+ /** A key of a collection's `admin` block. @group Models */
34
+ export type AdminCollectionKey = typeof ADMIN_COLLECTION_KEYS[number];
@@ -1,6 +1,7 @@
1
1
  import type { CollectionConfig, FilterValues, WhereFilterOp } from "./collections";
2
2
  import type { AuthAdapter } from "./auth_adapter";
3
3
  import type { HistoryConfig } from "../controllers/client";
4
+ import type { ChannelBusSetting } from "./channel_bus";
4
5
  /**
5
6
  * Abstract database connection interface.
6
7
  * Represents a connection to any database system.
@@ -188,13 +189,23 @@ export interface ChannelRetentionRule {
188
189
  */
189
190
  ttl?: number | string;
190
191
  }
191
- /** Server-side realtime options. */
192
+ /**
193
+ * Server-side realtime options.
194
+ *
195
+ * The channel bus contract and its config live in `./channel_bus` so that a
196
+ * transport shipped as its own package depends on the contract alone.
197
+ */
192
198
  export interface RealtimeChannelsConfig {
193
199
  /**
194
200
  * Retention rules, most specific first — the first match wins. Omitted or
195
201
  * empty means no channel retains anything.
196
202
  */
197
203
  channels?: ChannelRetentionRule[];
204
+ /**
205
+ * How channel broadcast and presence reach other backend instances.
206
+ * Defaults to `{ type: "memory" }` — i.e. they don't.
207
+ */
208
+ bus?: ChannelBusSetting;
198
209
  }
199
210
  /**
200
211
  * Abstract realtime provider interface.
@@ -582,6 +593,24 @@ export interface BackendBootstrapper {
582
593
  * Return admin capabilities for this driver.
583
594
  */
584
595
  getAdmin?(driverResult: InitializedDriver): DatabaseAdmin | undefined;
596
+ /**
597
+ * Bring the database's collection tables up to date, additively.
598
+ *
599
+ * Optional because it is only meaningful for schema-ful drivers. A managed
600
+ * runtime boots a compiled project against a database it has never seen; auth
601
+ * tables are ensured on boot but collection tables were created by nothing,
602
+ * so every data request answered 500 on a missing relation. The CLI's `db
603
+ * push` cannot fill the gap — it needs Atlas, and the runtime image ships no
604
+ * CLI.
605
+ *
606
+ * Implementations MUST be additive-only: create missing tables, columns and
607
+ * enum types, and never drop, narrow or rewrite anything. This runs
608
+ * unattended against live customer data with nobody reading a diff, so the
609
+ * destructive half stays a deliberate migration.
610
+ */
611
+ ensureCollectionSchema?(collections: unknown[], driverResult: InitializedDriver, log?: (message: string) => void): Promise<{
612
+ applied: number;
613
+ }>;
585
614
  /**
586
615
  * Initialize WebSocket server for realtime operations.
587
616
  */
@@ -0,0 +1,192 @@
1
+ /**
2
+ * The cross-instance transport for channel broadcast and presence, and the
3
+ * contract anyone implementing one has to meet.
4
+ *
5
+ * These types live in `@rebasepro/types` rather than in the Postgres adapter on
6
+ * purpose: a transport package should depend on the contract, not on the
7
+ * database driver that happens to ship the default implementation. A
8
+ * `@rebasepro/channel-bus-<something>` package needs this file and nothing else.
9
+ *
10
+ * Why a transport exists at all: entity/collection realtime already spans
11
+ * instances (CDC, or per-mutation LISTEN/NOTIFY). Channel broadcast and presence
12
+ * did not — they fanned out from per-process maps, so two clients served by
13
+ * different replicas could not see each other, and nothing errored. The bus is
14
+ * the missing hop, and deliberately *only* that hop: which local clients receive
15
+ * a frame stays in the realtime service, so a transport never has to know what a
16
+ * subscription, a WebSocket or a presence roster is.
17
+ */
18
+ /**
19
+ * A frame in flight between instances.
20
+ *
21
+ * `sid` identifies the publishing instance. The realtime service drops frames
22
+ * carrying its own `sid` on arrival — local fan-out already happened before the
23
+ * publish — so a transport that echoes a publisher's own messages back to it is
24
+ * still correct, merely wasteful.
25
+ *
26
+ * Keys are spelled out rather than abbreviated. The one shipped transport with a
27
+ * size limit has a pointer path for anything that would approach it, so shaving
28
+ * bytes off key names buys nothing worth the opacity.
29
+ */
30
+ export type ChannelBusFrame =
31
+ /** A broadcast carrying its payload. */
32
+ {
33
+ kind: "broadcast";
34
+ sid: string;
35
+ channel: string;
36
+ event: string;
37
+ /** Originating client, echoed so receivers can skip it if it is theirs. */
38
+ from?: string;
39
+ /** Sequence number, present only on retained channels. */
40
+ seq?: number;
41
+ payload: unknown;
42
+ }
43
+ /**
44
+ * A broadcast too large for the transport to carry inline: the body is
45
+ * already durable in `rebase.channel_messages`, so the frame carries only
46
+ * its address and each receiver reads it back. Only ever emitted for
47
+ * retained channels, and only by a transport with a finite
48
+ * {@link ChannelBus.maxFrameBytes}.
49
+ */
50
+ | {
51
+ kind: "broadcast_ref";
52
+ sid: string;
53
+ channel: string;
54
+ from?: string;
55
+ seq: number;
56
+ }
57
+ /** A presence join/leave/update, small by construction. */
58
+ | {
59
+ kind: "presence_diff";
60
+ sid: string;
61
+ channel: string;
62
+ joins: Record<string, Record<string, unknown>>;
63
+ leaves: Record<string, Record<string, unknown>>;
64
+ };
65
+ /** Receives frames published by *other* instances. */
66
+ export type ChannelBusHandler = (frame: ChannelBusFrame) => void | Promise<void>;
67
+ /**
68
+ * A cross-instance transport.
69
+ *
70
+ * ## What an implementation must guarantee
71
+ *
72
+ * - **`start()` rejects if the transport is unusable.** The caller falls back to
73
+ * in-process delivery when it does. Resolving while disconnected produces a
74
+ * cluster that believes it is connected and silently is not, which is the
75
+ * exact failure this whole mechanism exists to remove.
76
+ * - **`publish()` reaches every *other* instance, or rejects.** Delivery back to
77
+ * the publisher is permitted but pointless (see {@link ChannelBusFrame.sid}).
78
+ * - **`stop()` is idempotent** and releases everything, including anything
79
+ * holding the event loop open.
80
+ * - **A malformed message never throws out of the transport.** Parsing happens
81
+ * inside the implementation; drop and log what you cannot understand, so one
82
+ * bad frame cannot take the listener down.
83
+ *
84
+ * ## What it does *not* have to guarantee
85
+ *
86
+ * - **Ordering.** Retained channels carry `seq`, and the client SDK orders by
87
+ * it. Unsequenced broadcasts are cursor-grade traffic where order is not
88
+ * meaningful.
89
+ * - **Durability.** A frame lost in transit is a missed live update; retained
90
+ * channels repair themselves through the client's `channel_history` replay.
91
+ * - **Exactly-once.** Duplicates are tolerated — retained frames are deduped by
92
+ * `seq`, and presence diffs are idempotent by construction.
93
+ */
94
+ export interface ChannelBus {
95
+ /**
96
+ * Identifies the transport in logs and in `getChannelBusKind()`. Use your
97
+ * own name; the framework only compares against `"memory"` to decide
98
+ * whether publishing is worth attempting at all.
99
+ */
100
+ readonly kind: string;
101
+ /**
102
+ * Largest frame this transport will carry, in bytes of encoded JSON, or
103
+ * `Infinity` when there is no meaningful ceiling.
104
+ *
105
+ * A broadcast that exceeds it is published as a `broadcast_ref` pointer when
106
+ * the channel is retained, and refused with an error to the sender when it
107
+ * is not. Implementations with no limit should return `Infinity` rather than
108
+ * a large number, so the pointer path is never taken needlessly.
109
+ */
110
+ readonly maxFrameBytes: number;
111
+ /** Connect and begin delivering remote frames to `handler`. */
112
+ start(handler: ChannelBusHandler): Promise<void>;
113
+ /** Publish a frame to the other instances. */
114
+ publish(frame: ChannelBusFrame): Promise<void>;
115
+ /** Disconnect and release resources. Idempotent. */
116
+ stop(): Promise<void>;
117
+ }
118
+ /**
119
+ * Which transport to use, for the two that ship with the Postgres adapter.
120
+ *
121
+ * To use one that does not ship here — a Redis package, or your own class —
122
+ * pass the {@link ChannelBus} instance itself instead of a config object.
123
+ *
124
+ * There are deliberately only two built in, and neither adds a service to a
125
+ * deployment. Rebase deploys as Postgres + backend + frontend; a bus that
126
+ * required a message broker would put a second stateful service into every
127
+ * `docker-compose.yml` the CLI scaffolds, for a feature most applications never
128
+ * use. Measured across two backend instances against one Postgres container,
129
+ * the Postgres bus carried ~10k cross-instance messages/second with no losses,
130
+ * and stayed flat out to eight instances — comfortably past what live-cursor
131
+ * collaboration generates. The extension point below is the answer for anyone
132
+ * who does outgrow it.
133
+ */
134
+ export type ChannelBusConfig =
135
+ /**
136
+ * In-process only — the historical behaviour. Broadcast and presence reach
137
+ * the clients connected to *this* instance and no further.
138
+ */
139
+ {
140
+ type: "memory";
141
+ }
142
+ /**
143
+ * Postgres LISTEN/NOTIFY, reusing infrastructure the deployment already has.
144
+ *
145
+ * `pg_notify` caps a payload at 8000 bytes, so a broadcast larger than that
146
+ * is delivered cross-instance only on a *retained* channel, where the
147
+ * notification carries a pointer (`seq`) instead of the message and each
148
+ * receiver reads the body back from `rebase.channel_messages`. An oversized
149
+ * broadcast on an ephemeral channel is refused rather than silently
150
+ * delivered to half the cluster.
151
+ *
152
+ * NOTE: `LISTEN` needs a session-mode connection. Behind PgBouncer in
153
+ * transaction mode this must point at the database directly
154
+ * (`DATABASE_DIRECT_URL`), not at the pooler.
155
+ */
156
+ | {
157
+ type: "postgres";
158
+ /** Direct connection for the LISTEN client. Defaults to `DATABASE_DIRECT_URL`. */
159
+ connectionString?: string;
160
+ /**
161
+ * How long to coalesce outgoing frames into a single notification, in
162
+ * milliseconds. Defaults to 10.
163
+ *
164
+ * A notify is a query on your primary database, so under load this is
165
+ * the difference between one query per message and one per window. The
166
+ * window is leading-edge: a frame arriving when none is open goes out
167
+ * immediately, so an idle channel pays no added latency and only a
168
+ * sustained stream is batched.
169
+ *
170
+ * Set to 0 to disable coalescing and send every frame on its own.
171
+ */
172
+ batchWindowMs?: number;
173
+ };
174
+ /**
175
+ * What `realtime.bus` accepts: a built-in transport by name, or any
176
+ * {@link ChannelBus} instance.
177
+ *
178
+ * ```typescript
179
+ * realtime: { bus: { type: "postgres" } } // shipped
180
+ * realtime: { bus: new MyRedisChannelBus(url) } // a separate package, or your own
181
+ * ```
182
+ */
183
+ export type ChannelBusSetting = ChannelBusConfig | ChannelBus;
184
+ /**
185
+ * Whether `setting` is an already-constructed transport rather than a request
186
+ * for a built-in one.
187
+ *
188
+ * Structural rather than nominal so that an instance from a *different copy* of
189
+ * `@rebasepro/types` — an entirely normal outcome of a separately versioned
190
+ * transport package — is still recognised.
191
+ */
192
+ export declare function isChannelBusInstance(setting: ChannelBusSetting | undefined): setting is ChannelBus;
@@ -0,0 +1,43 @@
1
+ import type { CollectionConfig } from "./collections";
2
+ /**
3
+ * Serializing collections so they survive a network hop.
4
+ *
5
+ * A collection definition is not plain data. Relations point at their target
6
+ * with a *function* (`target: () => usersCollection`) so two collections can
7
+ * reference each other without an import cycle, and collections also carry
8
+ * callbacks, custom views and component references. `JSON.stringify` silently
9
+ * drops every one of those, which matters because the SDK generator *calls*
10
+ * `relation.target()` to decide whether a foreign key is a string or a number.
11
+ * Serialize naively and remote SDK generation produces subtly wrong types
12
+ * instead of failing — the worst possible outcome.
13
+ *
14
+ * So relation targets are resolved to a slug reference on the way out and
15
+ * rebuilt into functions on the way in. Everything else that cannot cross a wire
16
+ * is dropped deliberately: an SDK is generated from the *shape* of the data, and
17
+ * server-side behaviour is neither useful to a client nor safe to publish.
18
+ */
19
+ /** Marker replacing a relation's `target` function in serialized form. */
20
+ export interface SerializedCollectionRef {
21
+ __collectionRef: string;
22
+ }
23
+ export declare function isSerializedCollectionRef(value: unknown): value is SerializedCollectionRef;
24
+ /**
25
+ * Serialize collections for transport over the contract endpoint.
26
+ *
27
+ * Sorted by slug so the output — and therefore the schema hash computed from it
28
+ * — does not depend on filesystem ordering.
29
+ */
30
+ export declare function serializeCollections(collections: CollectionConfig[]): unknown[];
31
+ /**
32
+ * Rebuild collections received from a contract endpoint.
33
+ *
34
+ * Relation refs become real thunks resolving through the returned set, so
35
+ * downstream consumers — the SDK generator above all — see exactly the shape
36
+ * they would have seen had the collections been imported from source.
37
+ *
38
+ * A ref naming a collection that is not in the payload resolves to `undefined`
39
+ * rather than throwing: the generator already tolerates an unresolvable target
40
+ * by falling back to a permissive key type, and a partial contract should still
41
+ * produce a usable SDK.
42
+ */
43
+ export declare function deserializeCollections(payload: unknown[]): CollectionConfig[];