@rebasepro/server-postgresql 0.0.1-canary.e259309 → 0.0.1-canary.f81da60
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 +5 -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/services/EntityPersistService.ts +7 -1
- package/test/generate-drizzle-schema.test.ts +47 -0
- 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.f81da60",
|
|
5
5
|
"description": "PostgreSQL data source backend implementation for Rebase with Drizzle ORM",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"drizzle-orm": "^0.44.4",
|
|
65
65
|
"execa": "^4.1.0",
|
|
66
66
|
"pg": "^8.11.3",
|
|
67
|
-
"@rebasepro/common": "0.0.1-canary.
|
|
68
|
-
"@rebasepro/server-core": "0.0.1-canary.
|
|
69
|
-
"@rebasepro/types": "0.0.1-canary.
|
|
70
|
-
"@rebasepro/utils": "0.0.1-canary.
|
|
67
|
+
"@rebasepro/common": "0.0.1-canary.f81da60",
|
|
68
|
+
"@rebasepro/server-core": "0.0.1-canary.f81da60",
|
|
69
|
+
"@rebasepro/types": "0.0.1-canary.f81da60",
|
|
70
|
+
"@rebasepro/utils": "0.0.1-canary.f81da60"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
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) {
|
|
@@ -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
|
}
|
|
@@ -666,6 +666,53 @@ using: "{is_locked} = false" }
|
|
|
666
666
|
expect(result).toContain('as: "restrictive"');
|
|
667
667
|
});
|
|
668
668
|
|
|
669
|
+
it("should enable RLS on every table even without any security rules", async () => {
|
|
670
|
+
const collections: EntityCollection[] = [{
|
|
671
|
+
slug: "public_data",
|
|
672
|
+
table: "public_data",
|
|
673
|
+
name: "Public Data",
|
|
674
|
+
properties: { title: { type: "string" } }
|
|
675
|
+
// No securityRules defined — table should still have .enableRLS()
|
|
676
|
+
}];
|
|
677
|
+
|
|
678
|
+
const result = await generateSchema(collections);
|
|
679
|
+
expect(result).toContain(".enableRLS()");
|
|
680
|
+
// No policies should be generated
|
|
681
|
+
expect(result).not.toContain("pgPolicy(");
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
it("should enable RLS on tables that do have security rules", async () => {
|
|
685
|
+
const collections: EntityCollection[] = [{
|
|
686
|
+
slug: "secure_data",
|
|
687
|
+
table: "secure_data",
|
|
688
|
+
name: "Secure Data",
|
|
689
|
+
properties: { title: { type: "string" } },
|
|
690
|
+
securityRules: [
|
|
691
|
+
{ operation: "select", access: "public" }
|
|
692
|
+
]
|
|
693
|
+
}];
|
|
694
|
+
|
|
695
|
+
const result = await generateSchema(collections);
|
|
696
|
+
expect(result).toContain(".enableRLS()");
|
|
697
|
+
expect(result).toContain("pgPolicy(");
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
it("should fall back to deny-all (sql`false`) when no USING clause can be generated", async () => {
|
|
701
|
+
const collections: EntityCollection[] = [{
|
|
702
|
+
slug: "deny_test",
|
|
703
|
+
table: "deny_test",
|
|
704
|
+
name: "Deny Test",
|
|
705
|
+
properties: { title: { type: "string" } },
|
|
706
|
+
securityRules: [
|
|
707
|
+
{ operation: "select" }
|
|
708
|
+
// No access, ownerField, or using — should produce sql`false`
|
|
709
|
+
]
|
|
710
|
+
}];
|
|
711
|
+
|
|
712
|
+
const result = await generateSchema(collections);
|
|
713
|
+
expect(result).toContain("sql`false`");
|
|
714
|
+
});
|
|
715
|
+
|
|
669
716
|
});
|
|
670
717
|
});
|
|
671
718
|
// V2 improvements tests
|
package/test/relations.test.ts
CHANGED
|
@@ -382,8 +382,8 @@ relationName: "author" }
|
|
|
382
382
|
// Should create owning relation on profiles
|
|
383
383
|
expect(cleanResult).toContain("export const profilesRelations = drizzleRelations(profiles, ({ one, many }) => ({ \"author\": one(authors, { fields: [profiles.author_id], references: [authors.id], relationName: \"profiles_author_id\" }) }));");
|
|
384
384
|
|
|
385
|
-
// Should create inverse relation on authors
|
|
386
|
-
expect(cleanResult).toContain("export const authorsRelations = drizzleRelations(authors, ({ one, many }) => ({ \"profile\": one(profiles, {
|
|
385
|
+
// Should create inverse relation on authors — inverse side has NO fields/references
|
|
386
|
+
expect(cleanResult).toContain("export const authorsRelations = drizzleRelations(authors, ({ one, many }) => ({ \"profile\": one(profiles, { relationName: \"profiles_author_id\" }) }));");
|
|
387
387
|
});
|
|
388
388
|
|
|
389
389
|
it("should generate owning one-to-many relations", async () => {
|
|
@@ -818,9 +818,9 @@ relationName: "user" }
|
|
|
818
818
|
`"user": one(users, { fields: [profiles.user_id], references: [users.id], relationName: \"${expectedSharedName}\" })`
|
|
819
819
|
);
|
|
820
820
|
|
|
821
|
-
// Inverse side (users → profiles)
|
|
821
|
+
// Inverse side (users → profiles) — no fields/references, paired by relationName only
|
|
822
822
|
expect(cleanResult).toContain(
|
|
823
|
-
`"profile": one(profiles, {
|
|
823
|
+
`"profile": one(profiles, { relationName: \"${expectedSharedName}\" })`
|
|
824
824
|
);
|
|
825
825
|
|
|
826
826
|
// Both must match
|