@rebasepro/server-postgresql 0.0.1-canary.c53f5db → 0.0.1-canary.cbdd980
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 +384 -1100
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +315 -1031
- package/dist/index.umd.js.map +1 -1
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +2 -1
- package/dist/server-postgresql/src/schema/introspect-db-inference.d.ts +5 -0
- package/dist/server-postgresql/src/schema/introspect-db-logic.d.ts +44 -9
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +9 -0
- package/dist/types/src/controllers/auth.d.ts +8 -2
- package/dist/types/src/controllers/client.d.ts +13 -0
- package/dist/types/src/controllers/navigation.d.ts +18 -6
- package/dist/types/src/controllers/registry.d.ts +9 -1
- package/dist/types/src/controllers/side_entity_controller.d.ts +7 -0
- package/dist/types/src/rebase_context.d.ts +17 -0
- package/dist/types/src/types/collections.d.ts +21 -1
- package/dist/types/src/types/component_ref.d.ts +47 -0
- package/dist/types/src/types/cron.d.ts +1 -1
- package/dist/types/src/types/entity_views.d.ts +2 -1
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/properties.d.ts +68 -84
- package/dist/types/src/types/translations.d.ts +2 -0
- package/package.json +5 -5
- package/src/PostgresBackendDriver.ts +23 -6
- package/src/cli.ts +10 -2
- package/src/data-transformer.ts +84 -1
- package/src/schema/doctor.ts +14 -2
- package/src/schema/generate-drizzle-schema-logic.ts +59 -30
- package/src/schema/introspect-db-inference.ts +238 -0
- package/src/schema/introspect-db-logic.ts +365 -61
- package/src/schema/introspect-db.ts +66 -23
- package/src/services/EntityFetchService.ts +16 -0
- package/src/services/EntityPersistService.ts +88 -12
- package/test/generate-drizzle-schema.test.ts +295 -0
- package/test/introspect-db-generation.test.ts +32 -10
- package/test/property-ordering.test.ts +395 -0
- package/test/relations.test.ts +4 -4
- package/jest-all.log +0 -3128
- package/jest.log +0 -49
- package/scratch.ts +0 -41
- package/test-drizzle-bug.ts +0 -18
- package/test-drizzle-out/0000_cultured_freak.sql +0 -7
- package/test-drizzle-out/0001_tiresome_professor_monster.sql +0 -1
- package/test-drizzle-out/meta/0000_snapshot.json +0 -55
- package/test-drizzle-out/meta/0001_snapshot.json +0 -63
- package/test-drizzle-out/meta/_journal.json +0 -20
- package/test-drizzle-prompt.sh +0 -2
- package/test-policy-prompt.sh +0 -3
- package/test-programmatic.ts +0 -30
- package/test-programmatic2.ts +0 -59
- package/test-schema-no-policies.ts +0 -12
- package/test_drizzle_mock.js +0 -3
- package/test_find_changed.mjs +0 -32
- package/test_hash.js +0 -14
- package/test_output.txt +0 -3145
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ComponentRef } from "./component_ref";
|
|
2
2
|
import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity } from "./entities";
|
|
3
3
|
import type { Relation, JoinStep, OnAction } from "./relations";
|
|
4
4
|
import type { EntityCollection, FilterValues } from "./collections";
|
|
@@ -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?: ComponentRef<any>;
|
|
108
|
+
Preview?: ComponentRef<any>;
|
|
109
|
+
}
|
|
92
110
|
export interface BaseProperty<CustomProps = unknown> {
|
|
111
|
+
ui?: BaseUIConfig<CustomProps>;
|
|
93
112
|
/**
|
|
94
113
|
* Property name (e.g. Product)
|
|
95
114
|
*/
|
|
@@ -106,27 +125,17 @@ export interface BaseProperty<CustomProps = unknown> {
|
|
|
106
125
|
*/
|
|
107
126
|
propertyConfig?: string;
|
|
108
127
|
/**
|
|
109
|
-
*
|
|
110
|
-
* the
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
* Explicit database column name. When set, this value is used as-is
|
|
129
|
+
* for the SQL column name, bypassing any snake_case conversion of
|
|
130
|
+
* the property key.
|
|
131
|
+
*
|
|
132
|
+
* This is automatically populated by `rebase schema introspect`
|
|
133
|
+
* to guarantee an exact match with the live database schema.
|
|
134
|
+
*
|
|
135
|
+
* For manually-authored collections you can omit this — the framework
|
|
136
|
+
* will derive the column name from the property key via `toSnakeCase()`.
|
|
128
137
|
*/
|
|
129
|
-
|
|
138
|
+
columnName?: string;
|
|
130
139
|
/**
|
|
131
140
|
* Rules for validating this property
|
|
132
141
|
*/
|
|
@@ -135,16 +144,6 @@ export interface BaseProperty<CustomProps = unknown> {
|
|
|
135
144
|
* This value will be set by default for new entities.
|
|
136
145
|
*/
|
|
137
146
|
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
147
|
/**
|
|
149
148
|
* Use this to define dynamic properties that change based on certain conditions
|
|
150
149
|
* or on the entity's values. For example, you can make a field read-only if
|
|
@@ -168,21 +167,19 @@ export interface BaseProperty<CustomProps = unknown> {
|
|
|
168
167
|
* Callbacks/Hooks for this property field to transform and sanitize data during its lifecycle.
|
|
169
168
|
*/
|
|
170
169
|
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
170
|
}
|
|
182
171
|
/**
|
|
183
172
|
* @group Entity properties
|
|
184
173
|
*/
|
|
174
|
+
export interface StringUIConfig extends BaseUIConfig {
|
|
175
|
+
multiline?: boolean;
|
|
176
|
+
markdown?: boolean;
|
|
177
|
+
previewAsTag?: boolean;
|
|
178
|
+
clearable?: boolean;
|
|
179
|
+
url?: boolean | PreviewType;
|
|
180
|
+
}
|
|
185
181
|
export interface StringProperty extends BaseProperty {
|
|
182
|
+
ui?: StringUIConfig;
|
|
186
183
|
type: "string";
|
|
187
184
|
/**
|
|
188
185
|
* Optional database column type. If not set, it defaults to `varchar` or `uuid` depending on `isId` configuration.
|
|
@@ -257,10 +254,6 @@ export interface StringProperty extends BaseProperty {
|
|
|
257
254
|
* Should this string be rendered as a tag instead of just text.
|
|
258
255
|
*/
|
|
259
256
|
previewAsTag?: boolean;
|
|
260
|
-
/**
|
|
261
|
-
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
|
262
|
-
*/
|
|
263
|
-
clearable?: boolean;
|
|
264
257
|
/**
|
|
265
258
|
* You can use this property (a string) to behave as a reference to another
|
|
266
259
|
* collection. The stored value is the ID of the entity in the
|
|
@@ -272,7 +265,11 @@ export interface StringProperty extends BaseProperty {
|
|
|
272
265
|
/**
|
|
273
266
|
* @group Entity properties
|
|
274
267
|
*/
|
|
268
|
+
export interface NumberUIConfig extends BaseUIConfig {
|
|
269
|
+
clearable?: boolean;
|
|
270
|
+
}
|
|
275
271
|
export interface NumberProperty extends BaseProperty {
|
|
272
|
+
ui?: NumberUIConfig;
|
|
276
273
|
type: "number";
|
|
277
274
|
/**
|
|
278
275
|
* Optional database column type. Allows specifying exact database numeric types.
|
|
@@ -300,15 +297,12 @@ export interface NumberProperty extends BaseProperty {
|
|
|
300
297
|
* displayed in the dropdown.
|
|
301
298
|
*/
|
|
302
299
|
enum?: EnumValues;
|
|
303
|
-
/**
|
|
304
|
-
* Add an icon to clear the value and set it to `null`. Defaults to `false`
|
|
305
|
-
*/
|
|
306
|
-
clearable?: boolean;
|
|
307
300
|
}
|
|
308
301
|
/**
|
|
309
302
|
* @group Entity properties
|
|
310
303
|
*/
|
|
311
304
|
export interface BooleanProperty extends BaseProperty {
|
|
305
|
+
ui?: BaseUIConfig;
|
|
312
306
|
type: "boolean";
|
|
313
307
|
/**
|
|
314
308
|
* Rules for validating this property
|
|
@@ -318,7 +312,11 @@ export interface BooleanProperty extends BaseProperty {
|
|
|
318
312
|
/**
|
|
319
313
|
* @group Entity properties
|
|
320
314
|
*/
|
|
315
|
+
export interface DateUIConfig extends BaseUIConfig {
|
|
316
|
+
clearable?: boolean;
|
|
317
|
+
}
|
|
321
318
|
export interface DateProperty extends BaseProperty {
|
|
319
|
+
ui?: DateUIConfig;
|
|
322
320
|
type: "date";
|
|
323
321
|
/**
|
|
324
322
|
* Optional database column type. If not set, defaults to `timestamp` with timezone.
|
|
@@ -354,6 +352,7 @@ export interface DateProperty extends BaseProperty {
|
|
|
354
352
|
* @group Entity properties
|
|
355
353
|
*/
|
|
356
354
|
export interface GeopointProperty extends BaseProperty {
|
|
355
|
+
ui?: BaseUIConfig;
|
|
357
356
|
type: "geopoint";
|
|
358
357
|
/**
|
|
359
358
|
* Rules for validating this property
|
|
@@ -363,7 +362,11 @@ export interface GeopointProperty extends BaseProperty {
|
|
|
363
362
|
/**
|
|
364
363
|
* @group Entity properties
|
|
365
364
|
*/
|
|
365
|
+
export interface ReferenceUIConfig extends BaseUIConfig {
|
|
366
|
+
previewProperties?: string[];
|
|
367
|
+
}
|
|
366
368
|
export interface ReferenceProperty extends BaseProperty {
|
|
369
|
+
ui?: ReferenceUIConfig;
|
|
367
370
|
type: "reference";
|
|
368
371
|
/**
|
|
369
372
|
* Marks this field as a Primary Key / Unique Identifier.
|
|
@@ -387,12 +390,6 @@ export interface ReferenceProperty extends BaseProperty {
|
|
|
387
390
|
* e.g. `fixedFilter: { age: [">=", 18] }`
|
|
388
391
|
*/
|
|
389
392
|
fixedFilter?: 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.
|
|
394
|
-
*/
|
|
395
|
-
previewProperties?: string[];
|
|
396
393
|
/**
|
|
397
394
|
* Should the reference include the ID of the entity. Defaults to `true`
|
|
398
395
|
*/
|
|
@@ -405,7 +402,12 @@ export interface ReferenceProperty extends BaseProperty {
|
|
|
405
402
|
/**
|
|
406
403
|
* @group Entity properties
|
|
407
404
|
*/
|
|
405
|
+
export interface RelationUIConfig extends BaseUIConfig {
|
|
406
|
+
previewProperties?: string[];
|
|
407
|
+
widget?: "select" | "dialog";
|
|
408
|
+
}
|
|
408
409
|
export interface RelationProperty extends BaseProperty {
|
|
410
|
+
ui?: RelationUIConfig;
|
|
409
411
|
type: "relation";
|
|
410
412
|
/**
|
|
411
413
|
* Marks this field as a Primary Key / Unique Identifier.
|
|
@@ -495,12 +497,6 @@ export interface RelationProperty extends BaseProperty {
|
|
|
495
497
|
* e.g. `fixedFilter: { age: [">=", 18] }`
|
|
496
498
|
*/
|
|
497
499
|
fixedFilter?: FilterValues<string>;
|
|
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[];
|
|
504
500
|
/**
|
|
505
501
|
* Should the reference include the ID of the entity. Defaults to `true`
|
|
506
502
|
*/
|
|
@@ -518,7 +514,12 @@ export interface RelationProperty extends BaseProperty {
|
|
|
518
514
|
/**
|
|
519
515
|
* @group Entity properties
|
|
520
516
|
*/
|
|
517
|
+
export interface ArrayUIConfig extends BaseUIConfig {
|
|
518
|
+
expanded?: boolean;
|
|
519
|
+
minimalistView?: boolean;
|
|
520
|
+
}
|
|
521
521
|
export interface ArrayProperty extends BaseProperty {
|
|
522
|
+
ui?: ArrayUIConfig;
|
|
522
523
|
type: "array";
|
|
523
524
|
/**
|
|
524
525
|
* Optional database column type. Defaults to `jsonb`.
|
|
@@ -573,15 +574,6 @@ export interface ArrayProperty extends BaseProperty {
|
|
|
573
574
|
* Rules for validating this property
|
|
574
575
|
*/
|
|
575
576
|
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
577
|
/**
|
|
586
578
|
* Can the elements in this array be reordered. Defaults to `true`.
|
|
587
579
|
* This prop has no effect if `disabled` is set to true.
|
|
@@ -596,7 +588,13 @@ export interface ArrayProperty extends BaseProperty {
|
|
|
596
588
|
/**
|
|
597
589
|
* @group Entity properties
|
|
598
590
|
*/
|
|
591
|
+
export interface MapUIConfig extends BaseUIConfig {
|
|
592
|
+
expanded?: boolean;
|
|
593
|
+
minimalistView?: boolean;
|
|
594
|
+
spreadChildren?: boolean;
|
|
595
|
+
}
|
|
599
596
|
export interface MapProperty extends BaseProperty {
|
|
597
|
+
ui?: MapUIConfig;
|
|
600
598
|
type: "map";
|
|
601
599
|
/**
|
|
602
600
|
* Optional database column type. Defaults to `jsonb`.
|
|
@@ -630,20 +628,6 @@ export interface MapProperty extends BaseProperty {
|
|
|
630
628
|
* needed
|
|
631
629
|
*/
|
|
632
630
|
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
631
|
/**
|
|
648
632
|
* Render this map as a key-value table that allows to use
|
|
649
633
|
* arbitrary keys. You don't need to define the properties in this case.
|
|
@@ -51,6 +51,8 @@ export interface RebaseTranslations {
|
|
|
51
51
|
all_entries_loaded: string;
|
|
52
52
|
create_your_first_entry: string;
|
|
53
53
|
no_results_filter_sort: string;
|
|
54
|
+
/** Shown when a text search yields no results. Supports `{{search}}` interpolation. */
|
|
55
|
+
no_results_search?: string;
|
|
54
56
|
add: string;
|
|
55
57
|
remove: string;
|
|
56
58
|
copy_id: 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.cbdd980",
|
|
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/
|
|
68
|
-
"@rebasepro/
|
|
69
|
-
"@rebasepro/
|
|
70
|
-
"@rebasepro/
|
|
67
|
+
"@rebasepro/common": "0.0.1-canary.cbdd980",
|
|
68
|
+
"@rebasepro/server-core": "0.0.1-canary.cbdd980",
|
|
69
|
+
"@rebasepro/utils": "0.0.1-canary.cbdd980",
|
|
70
|
+
"@rebasepro/types": "0.0.1-canary.cbdd980"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/jest": "^29.5.14",
|
|
@@ -4,9 +4,9 @@ import { BranchService } from "./services/BranchService";
|
|
|
4
4
|
import { RealtimeService } from "./services/realtimeService";
|
|
5
5
|
import { DatabasePoolManager } from "./databasePoolManager";
|
|
6
6
|
import { DrizzleClient } from "./interfaces";
|
|
7
|
-
import { User } from "@rebasepro/types";
|
|
7
|
+
import { User, RebaseClient } from "@rebasepro/types";
|
|
8
8
|
import { sql as drizzleSql } from "drizzle-orm";
|
|
9
|
-
import { buildPropertyCallbacks } from "@rebasepro/common";
|
|
9
|
+
import { buildPropertyCallbacks, updateDateAutoValues } from "@rebasepro/common";
|
|
10
10
|
import { PostgresCollectionRegistry } from "./collections/PostgresCollectionRegistry";
|
|
11
11
|
import {
|
|
12
12
|
DataDriver,
|
|
@@ -44,6 +44,7 @@ export class PostgresBackendDriver implements DataDriver {
|
|
|
44
44
|
public branchService?: BranchService;
|
|
45
45
|
public user?: User;
|
|
46
46
|
public data: RebaseData;
|
|
47
|
+
public client?: RebaseClient;
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* When true, realtime notifications are deferred until after the
|
|
@@ -163,7 +164,8 @@ propertyCallbacks: undefined };
|
|
|
163
164
|
const contextForCallback = {
|
|
164
165
|
user: this.user,
|
|
165
166
|
driver: this,
|
|
166
|
-
data: this.data
|
|
167
|
+
data: this.data,
|
|
168
|
+
client: this.client
|
|
167
169
|
} as unknown as RebaseCallContext; // Backend context
|
|
168
170
|
return Promise.all(entities.map(async (entity) => {
|
|
169
171
|
let fetched = entity;
|
|
@@ -272,7 +274,8 @@ propertyCallbacks: undefined };
|
|
|
272
274
|
const contextForCallback = {
|
|
273
275
|
user: this.user,
|
|
274
276
|
driver: this,
|
|
275
|
-
data: this.data
|
|
277
|
+
data: this.data,
|
|
278
|
+
client: this.client
|
|
276
279
|
} as unknown as RebaseCallContext; // Backend context
|
|
277
280
|
if (callbacks?.afterRead) {
|
|
278
281
|
entity = await callbacks.afterRead({
|
|
@@ -354,7 +357,8 @@ propertyCallbacks: undefined };
|
|
|
354
357
|
const contextForCallback = {
|
|
355
358
|
user: this.user,
|
|
356
359
|
driver: this,
|
|
357
|
-
data: this.data
|
|
360
|
+
data: this.data,
|
|
361
|
+
client: this.client
|
|
358
362
|
} as unknown as RebaseCallContext;
|
|
359
363
|
|
|
360
364
|
// Fetch previous values for callbacks AND history recording
|
|
@@ -395,6 +399,17 @@ propertyCallbacks: undefined };
|
|
|
395
399
|
|
|
396
400
|
}
|
|
397
401
|
|
|
402
|
+
// Apply autoValue timestamps (on_create / on_update) at the application layer.
|
|
403
|
+
// This handles updated_at fields for all writes that flow through the Rebase backend.
|
|
404
|
+
if (resolvedCollection?.properties) {
|
|
405
|
+
updatedValues = updateDateAutoValues({
|
|
406
|
+
inputValues: updatedValues,
|
|
407
|
+
properties: resolvedCollection.properties,
|
|
408
|
+
status: status ?? "new",
|
|
409
|
+
timestampNowValue: new Date()
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
398
413
|
try {
|
|
399
414
|
let savedEntity = await this.entityService.saveEntity<M>(
|
|
400
415
|
path,
|
|
@@ -517,7 +532,8 @@ propertyCallbacks: undefined };
|
|
|
517
532
|
const contextForCallback = {
|
|
518
533
|
user: this.user,
|
|
519
534
|
driver: this,
|
|
520
|
-
data: this.data
|
|
535
|
+
data: this.data,
|
|
536
|
+
client: this.client
|
|
521
537
|
} as unknown as RebaseCallContext;
|
|
522
538
|
|
|
523
539
|
if (callbacks?.beforeDelete || propertyCallbacks?.beforeDelete) {
|
|
@@ -940,6 +956,7 @@ roles: userRoles })}, true)
|
|
|
940
956
|
txDelegate.entityService = txEntityService;
|
|
941
957
|
txDelegate._deferNotifications = true;
|
|
942
958
|
txDelegate._pendingNotifications = pendingNotifications;
|
|
959
|
+
txDelegate.client = this.delegate.client;
|
|
943
960
|
|
|
944
961
|
return await operation(txDelegate);
|
|
945
962
|
});
|
package/src/cli.ts
CHANGED
|
@@ -43,7 +43,7 @@ export async function runPluginCommand(args: string[]) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
46
|
-
const VALID_ACTIONS = ["push", "
|
|
46
|
+
const VALID_ACTIONS = ["push", "generate", "migrate", "studio", "branch"];
|
|
47
47
|
if (!subcommand || !VALID_ACTIONS.includes(subcommand)) {
|
|
48
48
|
console.error(chalk.red(`Unknown db command. Valid: ${VALID_ACTIONS.join(", ")}`));
|
|
49
49
|
process.exit(1);
|
|
@@ -68,6 +68,12 @@ async function dbCommand(subcommand: string, rawArgs: string[]): Promise<void> {
|
|
|
68
68
|
console.log("");
|
|
69
69
|
console.log(` You can now run ${chalk.bold.green("rebase db migrate")} to apply the migrations to your database.`);
|
|
70
70
|
console.log("");
|
|
71
|
+
} else if (subcommand === "pull") {
|
|
72
|
+
console.log("");
|
|
73
|
+
console.log(chalk.yellow(" ⚠ \"rebase db pull\" has been removed."));
|
|
74
|
+
console.log(chalk.gray(" Use \"rebase schema introspect\" instead."));
|
|
75
|
+
console.log("");
|
|
76
|
+
process.exit(1);
|
|
71
77
|
} else {
|
|
72
78
|
console.log("");
|
|
73
79
|
console.log(chalk.bold(` 🗄️ Rebase DB ${subcommand.charAt(0).toUpperCase() + subcommand.slice(1)}`));
|
|
@@ -538,9 +544,11 @@ async function schemaCommand(subcommand: string, rawArgs: string[]): Promise<voi
|
|
|
538
544
|
const argsList = arg(
|
|
539
545
|
{
|
|
540
546
|
"--output": String,
|
|
547
|
+
"--collections": String,
|
|
541
548
|
"--force": Boolean,
|
|
542
549
|
"--schema": String,
|
|
543
550
|
"-o": "--output",
|
|
551
|
+
"-c": "--collections",
|
|
544
552
|
"-f": "--force"
|
|
545
553
|
},
|
|
546
554
|
{
|
|
@@ -561,7 +569,7 @@ async function schemaCommand(subcommand: string, rawArgs: string[]): Promise<voi
|
|
|
561
569
|
process.exit(1);
|
|
562
570
|
}
|
|
563
571
|
|
|
564
|
-
const outputPath = argsList["--output"] || path.join("config", "collections");
|
|
572
|
+
const outputPath = argsList["--output"] || argsList["--collections"] || path.join("..", "config", "collections");
|
|
565
573
|
|
|
566
574
|
console.log("");
|
|
567
575
|
console.log(chalk.bold(" 🔍 Rebase Schema Introspector"));
|
package/src/data-transformer.ts
CHANGED
|
@@ -258,7 +258,26 @@ export function serializePropertyToServer(value: unknown, property: Property): u
|
|
|
258
258
|
}
|
|
259
259
|
return value;
|
|
260
260
|
|
|
261
|
+
case "string":
|
|
262
|
+
if (typeof value === "string") {
|
|
263
|
+
if (value.startsWith("data:application/octet-stream;base64,")) {
|
|
264
|
+
const base64Data = value.split(",")[1];
|
|
265
|
+
if (base64Data) {
|
|
266
|
+
return Buffer.from(base64Data, "base64");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return value;
|
|
271
|
+
|
|
261
272
|
default:
|
|
273
|
+
if (typeof value === "string") {
|
|
274
|
+
if (value.startsWith("data:application/octet-stream;base64,")) {
|
|
275
|
+
const base64Data = value.split(",")[1];
|
|
276
|
+
if (base64Data) {
|
|
277
|
+
return Buffer.from(base64Data, "base64");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
262
281
|
return value;
|
|
263
282
|
}
|
|
264
283
|
}
|
|
@@ -447,6 +466,45 @@ export function parsePropertyFromServer(value: unknown, property: Property, coll
|
|
|
447
466
|
}
|
|
448
467
|
|
|
449
468
|
switch (property.type) {
|
|
469
|
+
case "string": {
|
|
470
|
+
if (typeof value === "string") return value;
|
|
471
|
+
|
|
472
|
+
// Handle Buffer objects (e.g. from PostgreSQL bytea columns)
|
|
473
|
+
let isBuffer = false;
|
|
474
|
+
let buf: Buffer | null = null;
|
|
475
|
+
|
|
476
|
+
if (Buffer.isBuffer(value)) {
|
|
477
|
+
isBuffer = true;
|
|
478
|
+
buf = value;
|
|
479
|
+
} else if (typeof value === "object" && value !== null && (value as any).type === "Buffer" && Array.isArray((value as any).data)) {
|
|
480
|
+
isBuffer = true;
|
|
481
|
+
buf = Buffer.from((value as any).data);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (isBuffer && buf) {
|
|
485
|
+
// Heuristic: if all bytes are printable ASCII, return utf8, else base64
|
|
486
|
+
let isPrintable = true;
|
|
487
|
+
for (let i = 0; i < buf.length; i++) {
|
|
488
|
+
const b = buf[i];
|
|
489
|
+
// Allow standard printable ASCII + common whitespace (\r, \n, \t)
|
|
490
|
+
if ((b < 32 || b > 126) && b !== 9 && b !== 10 && b !== 13) {
|
|
491
|
+
isPrintable = false;
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return isPrintable ? buf.toString("utf8") : `data:application/octet-stream;base64,${buf.toString("base64")}`;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (typeof value === "object" && value !== null) {
|
|
499
|
+
try {
|
|
500
|
+
return JSON.stringify(value);
|
|
501
|
+
} catch {
|
|
502
|
+
return String(value);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return String(value);
|
|
506
|
+
}
|
|
507
|
+
|
|
450
508
|
case "relation":
|
|
451
509
|
// Transform ID back to relation object with type information
|
|
452
510
|
if (typeof value === "string" || typeof value === "number") {
|
|
@@ -538,8 +596,33 @@ export function parsePropertyFromServer(value: unknown, property: Property, coll
|
|
|
538
596
|
return null;
|
|
539
597
|
}
|
|
540
598
|
|
|
541
|
-
default:
|
|
599
|
+
default: {
|
|
600
|
+
// Fallback for buffers in case they are mapped to something other than string
|
|
601
|
+
let isBuffer = false;
|
|
602
|
+
let buf: Buffer | null = null;
|
|
603
|
+
|
|
604
|
+
if (Buffer.isBuffer(value)) {
|
|
605
|
+
isBuffer = true;
|
|
606
|
+
buf = value;
|
|
607
|
+
} else if (typeof value === "object" && value !== null && (value as any).type === "Buffer" && Array.isArray((value as any).data)) {
|
|
608
|
+
isBuffer = true;
|
|
609
|
+
buf = Buffer.from((value as any).data);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (isBuffer && buf) {
|
|
613
|
+
let isPrintable = true;
|
|
614
|
+
for (let i = 0; i < buf.length; i++) {
|
|
615
|
+
const b = buf[i];
|
|
616
|
+
if ((b < 32 || b > 126) && b !== 9 && b !== 10 && b !== 13) {
|
|
617
|
+
isPrintable = false;
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return isPrintable ? buf.toString("utf8") : `data:application/octet-stream;base64,${buf.toString("base64")}`;
|
|
622
|
+
}
|
|
623
|
+
|
|
542
624
|
return value;
|
|
625
|
+
}
|
|
543
626
|
}
|
|
544
627
|
}
|
|
545
628
|
|
package/src/schema/doctor.ts
CHANGED
|
@@ -17,6 +17,18 @@ import { generateSchema } from "./generate-drizzle-schema-logic";
|
|
|
17
17
|
import { getTableName, resolveCollectionRelations, findRelation } from "@rebasepro/common";
|
|
18
18
|
import { toSnakeCase } from "@rebasepro/utils";
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the SQL column name for a property.
|
|
22
|
+
* Uses the explicit `columnName` when set (e.g. from introspection),
|
|
23
|
+
* falling back to `toSnakeCase(propName)` for manually-authored collections.
|
|
24
|
+
*/
|
|
25
|
+
const resolveColumnName = (propName: string, prop?: Property | null): string => {
|
|
26
|
+
if (prop && "columnName" in prop && typeof prop.columnName === "string") {
|
|
27
|
+
return prop.columnName;
|
|
28
|
+
}
|
|
29
|
+
return toSnakeCase(propName);
|
|
30
|
+
};
|
|
31
|
+
|
|
20
32
|
// ── Types ────────────────────────────────────────────────────────────────
|
|
21
33
|
|
|
22
34
|
export type IssueSeverity = "error" | "warning" | "info";
|
|
@@ -316,7 +328,7 @@ export async function checkCollectionsVsDatabase(
|
|
|
316
328
|
const resolvedRelations = resolveCollectionRelations(collection);
|
|
317
329
|
const relation = findRelation(resolvedRelations, (prop as RelationProperty).relationName ?? propName);
|
|
318
330
|
if (relation?.direction === "owning" && relation.cardinality === "one" && relation.localKey) {
|
|
319
|
-
const fkColName =
|
|
331
|
+
const fkColName = relation.localKey;
|
|
320
332
|
if (!dbColumnMap.has(fkColName)) {
|
|
321
333
|
issues.push({
|
|
322
334
|
severity: "error",
|
|
@@ -349,7 +361,7 @@ export async function checkCollectionsVsDatabase(
|
|
|
349
361
|
continue;
|
|
350
362
|
}
|
|
351
363
|
|
|
352
|
-
const colName =
|
|
364
|
+
const colName = resolveColumnName(propName, prop);
|
|
353
365
|
|
|
354
366
|
// Skip system columns — they're handled automatically
|
|
355
367
|
if (systemColumns.has(colName)) continue;
|