@rebasepro/server-postgresql 0.0.1-canary.0e2f892 → 0.0.1-canary.3263433
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.
- package/dist/index.es.js +171 -180
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +171 -180
- package/dist/index.umd.js.map +1 -1
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +6 -0
- package/dist/types/src/controllers/auth.d.ts +2 -2
- package/dist/types/src/controllers/collection_registry.d.ts +2 -1
- package/dist/types/src/controllers/data_driver.d.ts +36 -1
- package/dist/types/src/types/backend_hooks.d.ts +187 -0
- package/dist/types/src/types/collections.d.ts +11 -10
- package/dist/types/src/types/cron.d.ts +1 -1
- package/dist/types/src/types/entity_views.d.ts +4 -6
- package/dist/types/src/types/formex.d.ts +40 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/plugins.d.ts +6 -3
- package/dist/types/src/types/properties.d.ts +61 -89
- package/dist/types/src/types/slots.d.ts +20 -10
- package/dist/types/src/types/translations.d.ts +4 -0
- package/package.json +6 -5
- package/src/PostgresBackendDriver.ts +9 -0
- package/src/cli.ts +1 -1
- package/src/schema/generate-drizzle-schema-logic.ts +7 -25
- package/src/schema/introspect-db-logic.ts +61 -11
- package/src/services/EntityPersistService.ts +7 -1
- package/test/generate-drizzle-schema.test.ts +47 -0
- package/test/introspect-db-generation.test.ts +1 -1
- package/test/introspect-db-utils.test.ts +18 -15
- package/test/relations.test.ts +4 -4
|
@@ -36,6 +36,14 @@ export type Property = StringProperty | NumberProperty | BooleanProperty | DateP
|
|
|
36
36
|
export type Properties = {
|
|
37
37
|
[key: string]: Property;
|
|
38
38
|
};
|
|
39
|
+
export type PostgresProperty = Exclude<Property, ReferenceProperty>;
|
|
40
|
+
export type PostgresProperties = {
|
|
41
|
+
[key: string]: PostgresProperty;
|
|
42
|
+
};
|
|
43
|
+
export type FirebaseProperty = Exclude<Property, RelationProperty>;
|
|
44
|
+
export type FirebaseProperties = {
|
|
45
|
+
[key: string]: FirebaseProperty;
|
|
46
|
+
};
|
|
39
47
|
/**
|
|
40
48
|
* A helper type to infer the underlying data type from a Property definition.
|
|
41
49
|
* This is the core of the type inference system.
|
|
@@ -89,7 +97,18 @@ export type InferEntityType<P extends Properties> = {
|
|
|
89
97
|
* Interface including all common properties of a CMS property.
|
|
90
98
|
* @group Entity properties
|
|
91
99
|
*/
|
|
100
|
+
export interface BaseUIConfig<CustomProps = unknown> {
|
|
101
|
+
columnWidth?: number;
|
|
102
|
+
hideFromCollection?: boolean;
|
|
103
|
+
readOnly?: boolean;
|
|
104
|
+
disabled?: boolean | PropertyDisabledConfig;
|
|
105
|
+
widthPercentage?: number;
|
|
106
|
+
customProps?: CustomProps;
|
|
107
|
+
Field?: React.ComponentType<any>;
|
|
108
|
+
Preview?: React.ComponentType<any>;
|
|
109
|
+
}
|
|
92
110
|
export interface BaseProperty<CustomProps = unknown> {
|
|
111
|
+
ui?: BaseUIConfig<CustomProps>;
|
|
93
112
|
/**
|
|
94
113
|
* Property name (e.g. Product)
|
|
95
114
|
*/
|
|
@@ -105,28 +124,6 @@ export interface BaseProperty<CustomProps = unknown> {
|
|
|
105
124
|
* overwritten by the current property config.
|
|
106
125
|
*/
|
|
107
126
|
propertyConfig?: string;
|
|
108
|
-
/**
|
|
109
|
-
* Width in pixels of this column in the collection view. If not set
|
|
110
|
-
* the width is inferred based on the other configurations
|
|
111
|
-
*/
|
|
112
|
-
columnWidth?: number;
|
|
113
|
-
/**
|
|
114
|
-
* Do not show this property in the collection view
|
|
115
|
-
*/
|
|
116
|
-
hideFromCollection?: boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Is this a read only property. When set to true, it gets rendered as a
|
|
119
|
-
* preview.
|
|
120
|
-
*/
|
|
121
|
-
readOnly?: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Is this field disabled.
|
|
124
|
-
* When set to true, it gets rendered as a
|
|
125
|
-
* disabled field. You can also specify a configuration for defining the
|
|
126
|
-
* behaviour of disabled properties (including custom messages, clear value on
|
|
127
|
-
* disabled or hide the field completely)
|
|
128
|
-
*/
|
|
129
|
-
disabled?: boolean | PropertyDisabledConfig;
|
|
130
127
|
/**
|
|
131
128
|
* Rules for validating this property
|
|
132
129
|
*/
|
|
@@ -135,16 +132,6 @@ export interface BaseProperty<CustomProps = unknown> {
|
|
|
135
132
|
* This value will be set by default for new entities.
|
|
136
133
|
*/
|
|
137
134
|
defaultValue?: unknown;
|
|
138
|
-
/**
|
|
139
|
-
* A number between 0 and 100 that indicates the width of the field in the form view.
|
|
140
|
-
* It defaults to 100, but you can set it to 50 to have two fields in the same row.
|
|
141
|
-
*/
|
|
142
|
-
widthPercentage?: number;
|
|
143
|
-
/**
|
|
144
|
-
* Additional props that are passed to the components defined in `field`
|
|
145
|
-
* or in `preview`.
|
|
146
|
-
*/
|
|
147
|
-
customProps?: CustomProps;
|
|
148
135
|
/**
|
|
149
136
|
* Use this to define dynamic properties that change based on certain conditions
|
|
150
137
|
* or on the entity's values. For example, you can make a field read-only if
|
|
@@ -168,21 +155,19 @@ export interface BaseProperty<CustomProps = unknown> {
|
|
|
168
155
|
* Callbacks/Hooks for this property field to transform and sanitize data during its lifecycle.
|
|
169
156
|
*/
|
|
170
157
|
callbacks?: PropertyCallbacks;
|
|
171
|
-
/**
|
|
172
|
-
* Custom field component to render this property in forms.
|
|
173
|
-
* Used by the CMS layer.
|
|
174
|
-
*/
|
|
175
|
-
Field?: React.ComponentType<any>;
|
|
176
|
-
/**
|
|
177
|
-
* Custom preview component to render this property in previews/tables.
|
|
178
|
-
* Used by the CMS layer.
|
|
179
|
-
*/
|
|
180
|
-
Preview?: React.ComponentType<any>;
|
|
181
158
|
}
|
|
182
159
|
/**
|
|
183
160
|
* @group Entity properties
|
|
184
161
|
*/
|
|
162
|
+
export interface StringUIConfig extends BaseUIConfig {
|
|
163
|
+
multiline?: boolean;
|
|
164
|
+
markdown?: boolean;
|
|
165
|
+
previewAsTag?: boolean;
|
|
166
|
+
clearable?: boolean;
|
|
167
|
+
url?: boolean | PreviewType;
|
|
168
|
+
}
|
|
185
169
|
export interface StringProperty extends BaseProperty {
|
|
170
|
+
ui?: StringUIConfig;
|
|
186
171
|
type: "string";
|
|
187
172
|
/**
|
|
188
173
|
* Optional database column type. If not set, it defaults to `varchar` or `uuid` depending on `isId` configuration.
|
|
@@ -257,10 +242,6 @@ export interface StringProperty extends BaseProperty {
|
|
|
257
242
|
* Should this string be rendered as a tag instead of just text.
|
|
258
243
|
*/
|
|
259
244
|
previewAsTag?: boolean;
|
|
260
|
-
/**
|
|
261
|
-
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
|
262
|
-
*/
|
|
263
|
-
clearable?: boolean;
|
|
264
245
|
/**
|
|
265
246
|
* You can use this property (a string) to behave as a reference to another
|
|
266
247
|
* collection. The stored value is the ID of the entity in the
|
|
@@ -272,7 +253,11 @@ export interface StringProperty extends BaseProperty {
|
|
|
272
253
|
/**
|
|
273
254
|
* @group Entity properties
|
|
274
255
|
*/
|
|
256
|
+
export interface NumberUIConfig extends BaseUIConfig {
|
|
257
|
+
clearable?: boolean;
|
|
258
|
+
}
|
|
275
259
|
export interface NumberProperty extends BaseProperty {
|
|
260
|
+
ui?: NumberUIConfig;
|
|
276
261
|
type: "number";
|
|
277
262
|
/**
|
|
278
263
|
* Optional database column type. Allows specifying exact database numeric types.
|
|
@@ -300,15 +285,12 @@ export interface NumberProperty extends BaseProperty {
|
|
|
300
285
|
* displayed in the dropdown.
|
|
301
286
|
*/
|
|
302
287
|
enum?: EnumValues;
|
|
303
|
-
/**
|
|
304
|
-
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
|
305
|
-
*/
|
|
306
|
-
clearable?: boolean;
|
|
307
288
|
}
|
|
308
289
|
/**
|
|
309
290
|
* @group Entity properties
|
|
310
291
|
*/
|
|
311
292
|
export interface BooleanProperty extends BaseProperty {
|
|
293
|
+
ui?: BaseUIConfig;
|
|
312
294
|
type: "boolean";
|
|
313
295
|
/**
|
|
314
296
|
* Rules for validating this property
|
|
@@ -318,7 +300,11 @@ export interface BooleanProperty extends BaseProperty {
|
|
|
318
300
|
/**
|
|
319
301
|
* @group Entity properties
|
|
320
302
|
*/
|
|
303
|
+
export interface DateUIConfig extends BaseUIConfig {
|
|
304
|
+
clearable?: boolean;
|
|
305
|
+
}
|
|
321
306
|
export interface DateProperty extends BaseProperty {
|
|
307
|
+
ui?: DateUIConfig;
|
|
322
308
|
type: "date";
|
|
323
309
|
/**
|
|
324
310
|
* Optional database column type. If not set, defaults to `timestamp` with timezone.
|
|
@@ -354,6 +340,7 @@ export interface DateProperty extends BaseProperty {
|
|
|
354
340
|
* @group Entity properties
|
|
355
341
|
*/
|
|
356
342
|
export interface GeopointProperty extends BaseProperty {
|
|
343
|
+
ui?: BaseUIConfig;
|
|
357
344
|
type: "geopoint";
|
|
358
345
|
/**
|
|
359
346
|
* Rules for validating this property
|
|
@@ -363,7 +350,11 @@ export interface GeopointProperty extends BaseProperty {
|
|
|
363
350
|
/**
|
|
364
351
|
* @group Entity properties
|
|
365
352
|
*/
|
|
353
|
+
export interface ReferenceUIConfig extends BaseUIConfig {
|
|
354
|
+
previewProperties?: string[];
|
|
355
|
+
}
|
|
366
356
|
export interface ReferenceProperty extends BaseProperty {
|
|
357
|
+
ui?: ReferenceUIConfig;
|
|
367
358
|
type: "reference";
|
|
368
359
|
/**
|
|
369
360
|
* Marks this field as a Primary Key / Unique Identifier.
|
|
@@ -384,15 +375,9 @@ export interface ReferenceProperty extends BaseProperty {
|
|
|
384
375
|
path?: string;
|
|
385
376
|
/**
|
|
386
377
|
* Allow selection of entities that pass the given filter only.
|
|
387
|
-
* e.g. `
|
|
388
|
-
*/
|
|
389
|
-
forceFilter?: FilterValues<string>;
|
|
390
|
-
/**
|
|
391
|
-
* Properties that need to be rendered when displaying a preview of this
|
|
392
|
-
* reference. If not specified the first 3 are used. Only the first 3
|
|
393
|
-
* specified values are considered.
|
|
378
|
+
* e.g. `fixedFilter: { age: [">=", 18] }`
|
|
394
379
|
*/
|
|
395
|
-
|
|
380
|
+
fixedFilter?: FilterValues<string>;
|
|
396
381
|
/**
|
|
397
382
|
* Should the reference include the ID of the entity. Defaults to `true`
|
|
398
383
|
*/
|
|
@@ -405,7 +390,12 @@ export interface ReferenceProperty extends BaseProperty {
|
|
|
405
390
|
/**
|
|
406
391
|
* @group Entity properties
|
|
407
392
|
*/
|
|
393
|
+
export interface RelationUIConfig extends BaseUIConfig {
|
|
394
|
+
previewProperties?: string[];
|
|
395
|
+
widget?: "select" | "dialog";
|
|
396
|
+
}
|
|
408
397
|
export interface RelationProperty extends BaseProperty {
|
|
398
|
+
ui?: RelationUIConfig;
|
|
409
399
|
type: "relation";
|
|
410
400
|
/**
|
|
411
401
|
* Marks this field as a Primary Key / Unique Identifier.
|
|
@@ -492,15 +482,9 @@ export interface RelationProperty extends BaseProperty {
|
|
|
492
482
|
relation?: Relation;
|
|
493
483
|
/**
|
|
494
484
|
* Allow selection of entities that pass the given filter only.
|
|
495
|
-
* e.g. `
|
|
485
|
+
* e.g. `fixedFilter: { age: [">=", 18] }`
|
|
496
486
|
*/
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Properties that need to be rendered when displaying a preview of this
|
|
500
|
-
* reference. If not specified the first 3 are used. Only the first 3
|
|
501
|
-
* specified values are considered.
|
|
502
|
-
*/
|
|
503
|
-
previewProperties?: string[];
|
|
487
|
+
fixedFilter?: FilterValues<string>;
|
|
504
488
|
/**
|
|
505
489
|
* Should the reference include the ID of the entity. Defaults to `true`
|
|
506
490
|
*/
|
|
@@ -518,7 +502,12 @@ export interface RelationProperty extends BaseProperty {
|
|
|
518
502
|
/**
|
|
519
503
|
* @group Entity properties
|
|
520
504
|
*/
|
|
505
|
+
export interface ArrayUIConfig extends BaseUIConfig {
|
|
506
|
+
expanded?: boolean;
|
|
507
|
+
minimalistView?: boolean;
|
|
508
|
+
}
|
|
521
509
|
export interface ArrayProperty extends BaseProperty {
|
|
510
|
+
ui?: ArrayUIConfig;
|
|
522
511
|
type: "array";
|
|
523
512
|
/**
|
|
524
513
|
* Optional database column type. Defaults to `jsonb`.
|
|
@@ -573,15 +562,6 @@ export interface ArrayProperty extends BaseProperty {
|
|
|
573
562
|
* Rules for validating this property
|
|
574
563
|
*/
|
|
575
564
|
validation?: ArrayPropertyValidationSchema;
|
|
576
|
-
/**
|
|
577
|
-
* Should the field be initially expanded. Defaults to `true`
|
|
578
|
-
*/
|
|
579
|
-
expanded?: boolean;
|
|
580
|
-
/**
|
|
581
|
-
* Display the child properties directly, without being wrapped in an
|
|
582
|
-
* extendable panel.
|
|
583
|
-
*/
|
|
584
|
-
minimalistView?: boolean;
|
|
585
565
|
/**
|
|
586
566
|
* Can the elements in this array be reordered. Defaults to `true`.
|
|
587
567
|
* This prop has no effect if `disabled` is set to true.
|
|
@@ -596,7 +576,13 @@ export interface ArrayProperty extends BaseProperty {
|
|
|
596
576
|
/**
|
|
597
577
|
* @group Entity properties
|
|
598
578
|
*/
|
|
579
|
+
export interface MapUIConfig extends BaseUIConfig {
|
|
580
|
+
expanded?: boolean;
|
|
581
|
+
minimalistView?: boolean;
|
|
582
|
+
spreadChildren?: boolean;
|
|
583
|
+
}
|
|
599
584
|
export interface MapProperty extends BaseProperty {
|
|
585
|
+
ui?: MapUIConfig;
|
|
600
586
|
type: "map";
|
|
601
587
|
/**
|
|
602
588
|
* Optional database column type. Defaults to `jsonb`.
|
|
@@ -630,20 +616,6 @@ export interface MapProperty extends BaseProperty {
|
|
|
630
616
|
* needed
|
|
631
617
|
*/
|
|
632
618
|
pickOnlySomeKeys?: boolean;
|
|
633
|
-
/**
|
|
634
|
-
* Display the child properties as independent columns in the collection
|
|
635
|
-
* view
|
|
636
|
-
*/
|
|
637
|
-
spreadChildren?: boolean;
|
|
638
|
-
/**
|
|
639
|
-
* Display the child properties directly, without being wrapped in an
|
|
640
|
-
* extendable panel. Note that this will also hide the title of this property.
|
|
641
|
-
*/
|
|
642
|
-
minimalistView?: boolean;
|
|
643
|
-
/**
|
|
644
|
-
* Should the field be initially expanded. Defaults to `true`
|
|
645
|
-
*/
|
|
646
|
-
expanded?: boolean;
|
|
647
619
|
/**
|
|
648
620
|
* Render this map as a key-value table that allows to use
|
|
649
621
|
* arbitrary keys. You don't need to define the properties in this case.
|
|
@@ -100,7 +100,8 @@ export interface NavigationSlotProps {
|
|
|
100
100
|
export interface CollectionToolbarProps {
|
|
101
101
|
path: string;
|
|
102
102
|
collection: EntityCollection;
|
|
103
|
-
|
|
103
|
+
parentCollectionSlugs: string[];
|
|
104
|
+
parentEntityIds: string[];
|
|
104
105
|
tableController: EntityTableController;
|
|
105
106
|
selectionController: SelectionController;
|
|
106
107
|
}
|
|
@@ -111,7 +112,8 @@ export interface CollectionToolbarProps {
|
|
|
111
112
|
export interface CollectionEmptyStateProps {
|
|
112
113
|
path: string;
|
|
113
114
|
collection: EntityCollection;
|
|
114
|
-
|
|
115
|
+
parentCollectionSlugs: string[];
|
|
116
|
+
parentEntityIds: string[];
|
|
115
117
|
canCreate: boolean;
|
|
116
118
|
onNewClick?: () => void;
|
|
117
119
|
}
|
|
@@ -123,7 +125,8 @@ export interface CollectionHeaderActionProps {
|
|
|
123
125
|
property: Property;
|
|
124
126
|
propertyKey: string;
|
|
125
127
|
path: string;
|
|
126
|
-
|
|
128
|
+
parentCollectionSlugs: string[];
|
|
129
|
+
parentEntityIds: string[];
|
|
127
130
|
onHover: boolean;
|
|
128
131
|
collection: EntityCollection;
|
|
129
132
|
tableController: EntityTableController;
|
|
@@ -134,7 +137,8 @@ export interface CollectionHeaderActionProps {
|
|
|
134
137
|
*/
|
|
135
138
|
export interface CollectionAddColumnProps {
|
|
136
139
|
path: string;
|
|
137
|
-
|
|
140
|
+
parentCollectionSlugs: string[];
|
|
141
|
+
parentEntityIds: string[];
|
|
138
142
|
collection: EntityCollection;
|
|
139
143
|
tableController: EntityTableController;
|
|
140
144
|
}
|
|
@@ -145,7 +149,8 @@ export interface CollectionAddColumnProps {
|
|
|
145
149
|
export interface CollectionErrorProps {
|
|
146
150
|
path: string;
|
|
147
151
|
collection: EntityCollection;
|
|
148
|
-
|
|
152
|
+
parentCollectionSlugs?: string[];
|
|
153
|
+
parentEntityIds?: string[];
|
|
149
154
|
error: Error;
|
|
150
155
|
}
|
|
151
156
|
/**
|
|
@@ -155,7 +160,8 @@ export interface CollectionErrorProps {
|
|
|
155
160
|
export interface KanbanSetupProps {
|
|
156
161
|
collection: EntityCollection;
|
|
157
162
|
fullPath: string;
|
|
158
|
-
|
|
163
|
+
parentCollectionSlugs: string[];
|
|
164
|
+
parentEntityIds: string[];
|
|
159
165
|
}
|
|
160
166
|
/**
|
|
161
167
|
* Props for the `kanban.add-column` slot.
|
|
@@ -164,7 +170,8 @@ export interface KanbanSetupProps {
|
|
|
164
170
|
export interface KanbanAddColumnProps {
|
|
165
171
|
collection: EntityCollection;
|
|
166
172
|
fullPath: string;
|
|
167
|
-
|
|
173
|
+
parentCollectionSlugs: string[];
|
|
174
|
+
parentEntityIds: string[];
|
|
168
175
|
columnProperty: string;
|
|
169
176
|
}
|
|
170
177
|
/**
|
|
@@ -177,7 +184,8 @@ export interface EntityRowActionsProps {
|
|
|
177
184
|
entityId: string;
|
|
178
185
|
path: string;
|
|
179
186
|
collection: EntityCollection;
|
|
180
|
-
|
|
187
|
+
parentCollectionSlugs: string[];
|
|
188
|
+
parentEntityIds: string[];
|
|
181
189
|
selectionController: SelectionController;
|
|
182
190
|
context: RebaseContext;
|
|
183
191
|
}
|
|
@@ -202,7 +210,8 @@ export interface EntityFieldSlotProps {
|
|
|
202
210
|
export interface CollectionFilterPanelProps {
|
|
203
211
|
path: string;
|
|
204
212
|
collection: EntityCollection;
|
|
205
|
-
|
|
213
|
+
parentCollectionSlugs: string[];
|
|
214
|
+
parentEntityIds: string[];
|
|
206
215
|
tableController: EntityTableController;
|
|
207
216
|
context: RebaseContext;
|
|
208
217
|
}
|
|
@@ -238,7 +247,8 @@ export interface ShellToolbarProps {
|
|
|
238
247
|
export interface CollectionInsightsSlotProps {
|
|
239
248
|
path: string;
|
|
240
249
|
collection: EntityCollection;
|
|
241
|
-
|
|
250
|
+
parentCollectionSlugs: string[];
|
|
251
|
+
parentEntityIds: string[];
|
|
242
252
|
}
|
|
243
253
|
/**
|
|
244
254
|
* Props for `home.card.insight` slot.
|
|
@@ -461,6 +461,10 @@ export interface RebaseTranslations {
|
|
|
461
461
|
reset_password_success?: string;
|
|
462
462
|
reset_password_confirmation?: string;
|
|
463
463
|
error_resetting_password?: string;
|
|
464
|
+
/** Permission-denied empty states */
|
|
465
|
+
no_permission_to_view_users?: string;
|
|
466
|
+
no_permission_to_view_roles?: string;
|
|
467
|
+
no_permission_description?: string;
|
|
464
468
|
/** Editor table-bubble */
|
|
465
469
|
add_row_before: string;
|
|
466
470
|
add_row_after: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/server-postgresql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.1-canary.
|
|
4
|
+
"version": "0.0.1-canary.3263433",
|
|
5
5
|
"description": "PostgreSQL data source backend implementation for Rebase with Drizzle ORM",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -60,13 +60,14 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"arg": "^5.0.2",
|
|
62
62
|
"chalk": "^4.1.2",
|
|
63
|
+
"chokidar": "5.0.0",
|
|
63
64
|
"drizzle-orm": "^0.44.4",
|
|
64
65
|
"execa": "^4.1.0",
|
|
65
66
|
"pg": "^8.11.3",
|
|
66
|
-
"@rebasepro/common": "0.0.1-canary.
|
|
67
|
-
"@rebasepro/server-core": "0.0.1-canary.
|
|
68
|
-
"@rebasepro/types": "0.0.1-canary.
|
|
69
|
-
"@rebasepro/utils": "0.0.1-canary.
|
|
67
|
+
"@rebasepro/common": "0.0.1-canary.3263433",
|
|
68
|
+
"@rebasepro/server-core": "0.0.1-canary.3263433",
|
|
69
|
+
"@rebasepro/types": "0.0.1-canary.3263433",
|
|
70
|
+
"@rebasepro/utils": "0.0.1-canary.3263433"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
73
|
"@types/jest": "^29.5.14",
|
|
@@ -101,6 +101,15 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* REST-optimised fetch service (include-aware eager-loading).
|
|
106
|
+
* Delegates to the underlying EntityFetchService which already
|
|
107
|
+
* implements the matching method signatures.
|
|
108
|
+
*/
|
|
109
|
+
get restFetchService() {
|
|
110
|
+
return this.entityService.getFetchService();
|
|
111
|
+
}
|
|
112
|
+
|
|
104
113
|
|
|
105
114
|
private resolveCollectionCallbacks<M extends Record<string, unknown>>(collection: EntityCollection<M> | undefined, path: string) {
|
|
106
115
|
if (!collection && !path) return { collection: undefined,
|
package/src/cli.ts
CHANGED
|
@@ -561,7 +561,7 @@ async function schemaCommand(subcommand: string, rawArgs: string[]): Promise<voi
|
|
|
561
561
|
process.exit(1);
|
|
562
562
|
}
|
|
563
563
|
|
|
564
|
-
const outputPath = argsList["--output"] || path.join("config", "collections");
|
|
564
|
+
const outputPath = argsList["--output"] || path.join("..", "config", "collections");
|
|
565
565
|
|
|
566
566
|
console.log("");
|
|
567
567
|
console.log(chalk.bold(" 🔍 Rebase Schema Introspector"));
|
|
@@ -682,31 +682,13 @@ export const generateSchema = async (collections: EntityCollection[], stripPolic
|
|
|
682
682
|
if (rel.cardinality === "one") {
|
|
683
683
|
if (rel.direction === "owning" && rel.localKey) {
|
|
684
684
|
tableRelations.push(` "${relationKey}": one(${targetTableVar}, {\n fields: [${tableVarName}.${rel.localKey}],\n references: [${targetTableVar}.${getPrimaryKeyName(target)}],\n relationName: \"${drizzleRelationName}\"\n })`);
|
|
685
|
-
} else if (rel.direction === "inverse"
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
//
|
|
690
|
-
//
|
|
691
|
-
|
|
692
|
-
try {
|
|
693
|
-
const targetCollection = rel.target();
|
|
694
|
-
const targetResolvedRelations = resolveCollectionRelations(targetCollection);
|
|
695
|
-
|
|
696
|
-
// Find the owning relation on the target that points back to this collection
|
|
697
|
-
const correspondingRelation = Object.values(targetResolvedRelations).find(targetRel =>
|
|
698
|
-
targetRel.direction === "owning" &&
|
|
699
|
-
targetRel.cardinality === "one" &&
|
|
700
|
-
targetRel.target().slug === collection.slug
|
|
701
|
-
);
|
|
702
|
-
|
|
703
|
-
if (correspondingRelation && correspondingRelation.localKey) {
|
|
704
|
-
const sourceIdField = getPrimaryKeyName(collection);
|
|
705
|
-
tableRelations.push(` "${relationKey}": one(${targetTableVar}, {\n fields: [${tableVarName}.${sourceIdField}],\n references: [${targetTableVar}.${correspondingRelation.localKey}],\n relationName: \"${drizzleRelationName}\"\n })`);
|
|
706
|
-
}
|
|
707
|
-
} catch (e) {
|
|
708
|
-
console.warn(`Could not resolve inverse one-to-one relation '${relationKey}':`, e);
|
|
709
|
-
}
|
|
685
|
+
} else if (rel.direction === "inverse") {
|
|
686
|
+
// Inverse one-to-one: the FK lives on the TARGET table, not here.
|
|
687
|
+
// Drizzle pairs inverse relations via `relationName` alone — specifying
|
|
688
|
+
// `fields`/`references` on the inverse side is invalid and causes
|
|
689
|
+
// `normalizeRelation` to crash with "Cannot read properties of
|
|
690
|
+
// undefined (reading 'referencedTable')".
|
|
691
|
+
tableRelations.push(` "${relationKey}": one(${targetTableVar}, {\n relationName: \"${drizzleRelationName}\"\n })`);
|
|
710
692
|
}
|
|
711
693
|
} else if (rel.cardinality === "many") {
|
|
712
694
|
if (rel.direction === "inverse" && rel.foreignKeyOnTarget) {
|
|
@@ -159,7 +159,7 @@ export function mapPgType(dataType: string): string {
|
|
|
159
159
|
if (dt === "interval") return "string";
|
|
160
160
|
|
|
161
161
|
// Array types MUST be checked before numeric ("_int4" contains "int")
|
|
162
|
-
if (dt === "array" || dt.startsWith("_")) return "
|
|
162
|
+
if (dt === "array" || dt.startsWith("_")) return "array";
|
|
163
163
|
|
|
164
164
|
// Numeric types
|
|
165
165
|
if (
|
|
@@ -183,7 +183,7 @@ export function mapPgType(dataType: string): string {
|
|
|
183
183
|
if (dt.includes("time") || dt.includes("date")) return "date";
|
|
184
184
|
|
|
185
185
|
// JSON
|
|
186
|
-
if (dt === "json" || dt === "jsonb") return "
|
|
186
|
+
if (dt === "json" || dt === "jsonb") return "map";
|
|
187
187
|
|
|
188
188
|
// Binary
|
|
189
189
|
if (dt === "bytea") return "string";
|
|
@@ -321,6 +321,20 @@ export function generateCollectionFile(
|
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
// Array/Map heuristics
|
|
325
|
+
if (propType === "array") {
|
|
326
|
+
let innerType = "string";
|
|
327
|
+
if (col.udt_name.startsWith("_")) {
|
|
328
|
+
const baseType = col.udt_name.substring(1);
|
|
329
|
+
// Simple recursive check or hardcoded for inner type:
|
|
330
|
+
// We'll just call mapPgType on the baseType
|
|
331
|
+
innerType = mapPgType(baseType);
|
|
332
|
+
}
|
|
333
|
+
extra = `\n of: { type: "${innerType}" },`;
|
|
334
|
+
} else if (propType === "map") {
|
|
335
|
+
extra = `\n keyValue: true,`;
|
|
336
|
+
}
|
|
337
|
+
|
|
324
338
|
// String sub-type heuristics (skip if already handled as enum)
|
|
325
339
|
if (propType === "string" && !isEnumColumn) {
|
|
326
340
|
if (colNameLower.includes("image") || colNameLower.includes("avatar") || colNameLower.includes("photo") || colNameLower.includes("logo") || colNameLower.includes("cover")) {
|
|
@@ -509,11 +523,14 @@ export default ${tableName}Collection;
|
|
|
509
523
|
*/
|
|
510
524
|
export function generateIndexContent(fileNames: string[]): string {
|
|
511
525
|
const sorted = [...fileNames].sort();
|
|
512
|
-
let
|
|
526
|
+
let imports = "";
|
|
527
|
+
let arrayElements = "";
|
|
513
528
|
for (const f of sorted) {
|
|
514
|
-
|
|
529
|
+
const varName = toCollectionVarName(f);
|
|
530
|
+
imports += `import ${varName} from "./${f}";\n`;
|
|
531
|
+
arrayElements += ` ${varName},\n`;
|
|
515
532
|
}
|
|
516
|
-
return
|
|
533
|
+
return `${imports}\nexport const collections = [\n${arrayElements}];\n`;
|
|
517
534
|
}
|
|
518
535
|
|
|
519
536
|
/**
|
|
@@ -521,17 +538,50 @@ export function generateIndexContent(fileNames: string[]): string {
|
|
|
521
538
|
* Returns the merged content string.
|
|
522
539
|
*/
|
|
523
540
|
export function mergeIndexContent(existingContent: string, newFileNames: string[]): string {
|
|
524
|
-
const
|
|
525
|
-
[...existingContent.matchAll(/
|
|
541
|
+
const existingImports = new Set(
|
|
542
|
+
[...existingContent.matchAll(/import\s+([a-zA-Z0-9_]+)\s+from\s+"\.\/([^"]+)"/g)].map((m) => m[2])
|
|
526
543
|
);
|
|
527
544
|
const sorted = [...newFileNames].sort();
|
|
528
|
-
|
|
545
|
+
|
|
546
|
+
let newImports = "";
|
|
547
|
+
let newElements = "";
|
|
548
|
+
|
|
529
549
|
for (const f of sorted) {
|
|
530
|
-
if (!
|
|
531
|
-
|
|
550
|
+
if (!existingImports.has(f)) {
|
|
551
|
+
const varName = toCollectionVarName(f);
|
|
552
|
+
newImports += `import ${varName} from "./${f}";\n`;
|
|
553
|
+
newElements += ` ${varName},\n`;
|
|
532
554
|
}
|
|
533
555
|
}
|
|
534
|
-
|
|
556
|
+
|
|
557
|
+
if (!newImports) return existingContent;
|
|
558
|
+
|
|
559
|
+
// Simple injection logic:
|
|
560
|
+
// Add new imports below the last import or at the top
|
|
561
|
+
const importRegex = /import\s+.*?;/g;
|
|
562
|
+
let lastImportMatch;
|
|
563
|
+
let match;
|
|
564
|
+
while ((match = importRegex.exec(existingContent)) !== null) {
|
|
565
|
+
lastImportMatch = match;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
let contentWithImports = existingContent;
|
|
569
|
+
if (lastImportMatch) {
|
|
570
|
+
const pos = lastImportMatch.index + lastImportMatch[0].length;
|
|
571
|
+
contentWithImports = existingContent.slice(0, pos) + "\n" + newImports.trimEnd() + existingContent.slice(pos);
|
|
572
|
+
} else {
|
|
573
|
+
contentWithImports = newImports + "\n" + existingContent;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// Inject into the `collections = [...]` array
|
|
577
|
+
const arrayRegex = /export\s+const\s+collections\s*=\s*\[([\s\S]*?)\];/;
|
|
578
|
+
return contentWithImports.replace(arrayRegex, (fullMatch, arrayContent) => {
|
|
579
|
+
let mergedArray = arrayContent.trimEnd();
|
|
580
|
+
if (mergedArray && !mergedArray.endsWith(",")) mergedArray += ",";
|
|
581
|
+
if (mergedArray) mergedArray += "\n";
|
|
582
|
+
mergedArray += newElements.trimEnd();
|
|
583
|
+
return `export const collections = [\n ${mergedArray.trim()}\n];`;
|
|
584
|
+
});
|
|
535
585
|
}
|
|
536
586
|
|
|
537
587
|
/**
|
|
@@ -111,7 +111,7 @@ export class EntityPersistService {
|
|
|
111
111
|
targetColumnName = relation.localKey;
|
|
112
112
|
} else if (relation.foreignKeyOnTarget) {
|
|
113
113
|
targetColumnName = relation.foreignKeyOnTarget;
|
|
114
|
-
} else if (relation.joinPath && relation.joinPath.length
|
|
114
|
+
} else if (relation.joinPath && relation.joinPath.length === 1) {
|
|
115
115
|
const targetTableName = getTableName(targetCollection);
|
|
116
116
|
const relevantJoinStep = relation.joinPath.find(joinStep => joinStep.table === targetTableName);
|
|
117
117
|
|
|
@@ -123,6 +123,12 @@ export class EntityPersistService {
|
|
|
123
123
|
const targetColumnNames = DrizzleConditionBuilder.getColumnNamesFromColumns(relation.joinPath[0].on.to);
|
|
124
124
|
targetColumnName = targetColumnNames[0];
|
|
125
125
|
}
|
|
126
|
+
} else if (relation.joinPath && relation.joinPath.length > 1) {
|
|
127
|
+
// For multi-hop relations (like many-to-many through a junction table),
|
|
128
|
+
// there is no direct foreign key on the target table pointing to the parent.
|
|
129
|
+
// The relationship is managed via the junction table.
|
|
130
|
+
// We shouldn't inject the parent ID directly into the target entity payload.
|
|
131
|
+
break;
|
|
126
132
|
} else {
|
|
127
133
|
throw new Error(`Relation '${relationKey}' lacks configuration for path-based saving.`);
|
|
128
134
|
}
|