@rebasepro/server-postgresql 0.0.1-canary.eae7889 → 0.1.0
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 +458 -201
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +458 -201
- package/dist/index.umd.js.map +1 -1
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +8 -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 +117 -0
- package/dist/server-postgresql/src/schema/introspect-db.d.ts +1 -0
- 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/collection_registry.d.ts +2 -1
- package/dist/types/src/controllers/data_driver.d.ts +36 -1
- 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/backend_hooks.d.ts +187 -0
- package/dist/types/src/types/collections.d.ts +31 -11
- 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 +6 -7
- package/dist/types/src/types/formex.d.ts +40 -0
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/src/types/plugins.d.ts +6 -3
- package/dist/types/src/types/properties.d.ts +72 -88
- package/dist/types/src/types/slots.d.ts +20 -10
- package/dist/types/src/types/translations.d.ts +6 -0
- package/examples/sdk-demo/node_modules/esbuild/LICENSE.md +21 -0
- package/examples/sdk-demo/node_modules/esbuild/README.md +3 -0
- package/examples/sdk-demo/node_modules/esbuild/bin/esbuild +223 -0
- package/examples/sdk-demo/node_modules/esbuild/install.js +289 -0
- package/examples/sdk-demo/node_modules/esbuild/lib/main.d.ts +716 -0
- package/examples/sdk-demo/node_modules/esbuild/lib/main.js +2242 -0
- package/examples/sdk-demo/node_modules/esbuild/package.json +49 -0
- package/package.json +6 -5
- package/src/PostgresBackendDriver.ts +32 -6
- package/src/cli.ts +68 -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 +896 -0
- package/src/schema/introspect-db.ts +254 -0
- package/src/services/EntityFetchService.ts +16 -0
- package/src/services/EntityPersistService.ts +95 -13
- package/test/generate-drizzle-schema.test.ts +342 -0
- package/test/introspect-db-generation.test.ts +458 -0
- package/test/introspect-db-utils.test.ts +392 -0
- package/test/property-ordering.test.ts +395 -0
- package/test/relations.test.ts +4 -4
- package/test/unmapped-tables-safety.test.ts +345 -0
- 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
|
@@ -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
|
|
@@ -986,3 +1033,298 @@ isId: true }
|
|
|
986
1033
|
expect(cleanResult).toContain("user_name: varchar(\"user_name\").primaryKey()");
|
|
987
1034
|
});
|
|
988
1035
|
});
|
|
1036
|
+
|
|
1037
|
+
// ── columnName tests ────────────────────────────────────────────────────
|
|
1038
|
+
describe("generateDrizzleSchema columnName support", () => {
|
|
1039
|
+
const cleanSchema = (schema: string) => {
|
|
1040
|
+
return schema
|
|
1041
|
+
.replace(/\/\/.*$/gm, "")
|
|
1042
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
1043
|
+
.replace(/\n{2,}/g, "\n")
|
|
1044
|
+
.replace(/\s+/g, " ")
|
|
1045
|
+
.trim();
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
it("should use explicit columnName as the SQL column name instead of deriving from the property key", async () => {
|
|
1049
|
+
const collections: EntityCollection[] = [{
|
|
1050
|
+
slug: "billing",
|
|
1051
|
+
table: "company_billing_config",
|
|
1052
|
+
name: "Billing",
|
|
1053
|
+
properties: {
|
|
1054
|
+
employee_number_140a: {
|
|
1055
|
+
type: "string",
|
|
1056
|
+
name: "Employee Number 140a",
|
|
1057
|
+
columnName: "employee_number_140a",
|
|
1058
|
+
},
|
|
1059
|
+
contract_number_140a: {
|
|
1060
|
+
type: "string",
|
|
1061
|
+
name: "Contract Number 140a",
|
|
1062
|
+
columnName: "contract_number_140a",
|
|
1063
|
+
},
|
|
1064
|
+
},
|
|
1065
|
+
}];
|
|
1066
|
+
|
|
1067
|
+
const result = await generateSchema(collections);
|
|
1068
|
+
const cleanResult = cleanSchema(result);
|
|
1069
|
+
|
|
1070
|
+
// Must use the exact columnName, NOT toSnakeCase(propKey) which would produce "employee_number_140_a"
|
|
1071
|
+
expect(cleanResult).toContain('employee_number_140a: varchar("employee_number_140a")');
|
|
1072
|
+
expect(cleanResult).toContain('contract_number_140a: varchar("contract_number_140a")');
|
|
1073
|
+
|
|
1074
|
+
// Must NOT contain the broken snake_case version
|
|
1075
|
+
expect(cleanResult).not.toContain("employee_number_140_a");
|
|
1076
|
+
expect(cleanResult).not.toContain("contract_number_140_a");
|
|
1077
|
+
});
|
|
1078
|
+
|
|
1079
|
+
it("should fall back to toSnakeCase when columnName is not set (manually-authored collections)", async () => {
|
|
1080
|
+
const collections: EntityCollection[] = [{
|
|
1081
|
+
slug: "products",
|
|
1082
|
+
table: "products",
|
|
1083
|
+
name: "Products",
|
|
1084
|
+
properties: {
|
|
1085
|
+
productName: {
|
|
1086
|
+
type: "string",
|
|
1087
|
+
name: "Product Name",
|
|
1088
|
+
// No columnName — should derive from key
|
|
1089
|
+
},
|
|
1090
|
+
},
|
|
1091
|
+
}];
|
|
1092
|
+
|
|
1093
|
+
const result = await generateSchema(collections);
|
|
1094
|
+
const cleanResult = cleanSchema(result);
|
|
1095
|
+
|
|
1096
|
+
// JS key stays camelCase, SQL column name gets snake_cased
|
|
1097
|
+
expect(cleanResult).toContain('productName: varchar("product_name")');
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
it("should handle mixed properties — some with columnName, some without", async () => {
|
|
1101
|
+
const collections: EntityCollection[] = [{
|
|
1102
|
+
slug: "config",
|
|
1103
|
+
table: "app_config",
|
|
1104
|
+
name: "Config",
|
|
1105
|
+
properties: {
|
|
1106
|
+
// Introspected: has explicit columnName
|
|
1107
|
+
fee_number_140a: {
|
|
1108
|
+
type: "string",
|
|
1109
|
+
name: "Fee Number",
|
|
1110
|
+
columnName: "fee_number_140a",
|
|
1111
|
+
},
|
|
1112
|
+
// Manually added: no columnName
|
|
1113
|
+
displayName: {
|
|
1114
|
+
type: "string",
|
|
1115
|
+
name: "Display Name",
|
|
1116
|
+
},
|
|
1117
|
+
},
|
|
1118
|
+
}];
|
|
1119
|
+
|
|
1120
|
+
const result = await generateSchema(collections);
|
|
1121
|
+
const cleanResult = cleanSchema(result);
|
|
1122
|
+
|
|
1123
|
+
// Introspected prop uses exact columnName
|
|
1124
|
+
expect(cleanResult).toContain('fee_number_140a: varchar("fee_number_140a")');
|
|
1125
|
+
// Manual prop: JS key stays camelCase, SQL column gets snake_cased
|
|
1126
|
+
expect(cleanResult).toContain('displayName: varchar("display_name")');
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
it("should use columnName for all property types, not just strings", async () => {
|
|
1130
|
+
const collections: EntityCollection[] = [{
|
|
1131
|
+
slug: "metrics",
|
|
1132
|
+
table: "metrics",
|
|
1133
|
+
name: "Metrics",
|
|
1134
|
+
properties: {
|
|
1135
|
+
count_v2: {
|
|
1136
|
+
type: "number",
|
|
1137
|
+
name: "Count V2",
|
|
1138
|
+
columnName: "count_v2",
|
|
1139
|
+
},
|
|
1140
|
+
is_active_v2: {
|
|
1141
|
+
type: "boolean",
|
|
1142
|
+
name: "Is Active V2",
|
|
1143
|
+
columnName: "is_active_v2",
|
|
1144
|
+
},
|
|
1145
|
+
created_at_v2: {
|
|
1146
|
+
type: "date",
|
|
1147
|
+
name: "Created At V2",
|
|
1148
|
+
columnName: "created_at_v2",
|
|
1149
|
+
},
|
|
1150
|
+
metadata_v2: {
|
|
1151
|
+
type: "map",
|
|
1152
|
+
name: "Metadata V2",
|
|
1153
|
+
columnName: "metadata_v2",
|
|
1154
|
+
},
|
|
1155
|
+
},
|
|
1156
|
+
}];
|
|
1157
|
+
|
|
1158
|
+
const result = await generateSchema(collections);
|
|
1159
|
+
const cleanResult = cleanSchema(result);
|
|
1160
|
+
|
|
1161
|
+
expect(cleanResult).toContain('count_v2: numeric("count_v2")');
|
|
1162
|
+
expect(cleanResult).toContain('is_active_v2: boolean("is_active_v2")');
|
|
1163
|
+
expect(cleanResult).toContain('created_at_v2: timestamp("created_at_v2"');
|
|
1164
|
+
expect(cleanResult).toContain('metadata_v2: jsonb("metadata_v2")');
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
it("should reproduce and prevent the medmot bug: digit+letter column names", async () => {
|
|
1168
|
+
// This is the exact scenario from the medmot project that caused the production failure
|
|
1169
|
+
const collections: EntityCollection[] = [{
|
|
1170
|
+
slug: "company_billing_config",
|
|
1171
|
+
table: "company_billing_config",
|
|
1172
|
+
name: "Company Billing Config",
|
|
1173
|
+
properties: {
|
|
1174
|
+
employee_number_140a: { type: "string", name: "Employee Number", columnName: "employee_number_140a" },
|
|
1175
|
+
contract_number_140a: { type: "string", name: "Contract Number", columnName: "contract_number_140a" },
|
|
1176
|
+
amount: { type: "number", name: "Amount" },
|
|
1177
|
+
id: { type: "number", name: "ID", isId: "increment" },
|
|
1178
|
+
service_provider_140a: { type: "string", name: "Service Provider", columnName: "service_provider_140a" },
|
|
1179
|
+
internal_area_code_140a: { type: "string", name: "Internal Area Code", columnName: "internal_area_code_140a" },
|
|
1180
|
+
fee_number_140a: { type: "string", name: "Fee Number", columnName: "fee_number_140a" },
|
|
1181
|
+
receiver_market_participant_140a: { type: "string", name: "Receiver Market Participant", columnName: "receiver_market_participant_140a" },
|
|
1182
|
+
employee_value_number_140a: { type: "string", name: "Employee Value Number", columnName: "employee_value_number_140a" },
|
|
1183
|
+
sender_market_participant_140a: { type: "string", name: "Sender Market Participant", columnName: "sender_market_participant_140a" },
|
|
1184
|
+
processing_indicator_140a: { type: "string", name: "Processing Indicator", columnName: "processing_indicator_140a" },
|
|
1185
|
+
insurance_id_140a: { type: "string", name: "Insurance ID", columnName: "insurance_id_140a" },
|
|
1186
|
+
company_id: { type: "number", name: "Company ID" },
|
|
1187
|
+
},
|
|
1188
|
+
}];
|
|
1189
|
+
|
|
1190
|
+
const result = await generateSchema(collections);
|
|
1191
|
+
|
|
1192
|
+
// Every _140a column must stay _140a, not become _140_a
|
|
1193
|
+
const brokenPattern = /_140_a/;
|
|
1194
|
+
expect(result).not.toMatch(brokenPattern);
|
|
1195
|
+
|
|
1196
|
+
// Spot-check a few exact columns
|
|
1197
|
+
expect(result).toContain('"employee_number_140a"');
|
|
1198
|
+
expect(result).toContain('"contract_number_140a"');
|
|
1199
|
+
expect(result).toContain('"service_provider_140a"');
|
|
1200
|
+
expect(result).toContain('"insurance_id_140a"');
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
describe("generateDrizzleSchema autoValue date properties", () => {
|
|
1204
|
+
|
|
1205
|
+
it("should add .default(sql`now()`) for on_create autoValue", async () => {
|
|
1206
|
+
const collections: EntityCollection[] = [
|
|
1207
|
+
{
|
|
1208
|
+
slug: "articles",
|
|
1209
|
+
table: "articles",
|
|
1210
|
+
name: "Articles",
|
|
1211
|
+
properties: {
|
|
1212
|
+
title: { type: "string" },
|
|
1213
|
+
created_at: {
|
|
1214
|
+
type: "date",
|
|
1215
|
+
autoValue: "on_create"
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
];
|
|
1220
|
+
|
|
1221
|
+
const result = await generateSchema(collections, true);
|
|
1222
|
+
|
|
1223
|
+
// on_create should produce .default(sql`now()`)
|
|
1224
|
+
expect(result).toContain(".default(sql`now()`)");
|
|
1225
|
+
// No $onUpdate or triggers — on_update logic lives in the backend driver
|
|
1226
|
+
expect(result).not.toContain(".$onUpdate");
|
|
1227
|
+
expect(result).not.toContain("CREATE OR REPLACE TRIGGER");
|
|
1228
|
+
expect(result).not.toContain("CREATE OR REPLACE FUNCTION");
|
|
1229
|
+
});
|
|
1230
|
+
|
|
1231
|
+
it("should add .default(sql`now()`) for on_update autoValue (INSERT default only)", async () => {
|
|
1232
|
+
const collections: EntityCollection[] = [
|
|
1233
|
+
{
|
|
1234
|
+
slug: "articles",
|
|
1235
|
+
table: "articles",
|
|
1236
|
+
name: "Articles",
|
|
1237
|
+
properties: {
|
|
1238
|
+
title: { type: "string" },
|
|
1239
|
+
updated_at: {
|
|
1240
|
+
type: "date",
|
|
1241
|
+
autoValue: "on_update"
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
];
|
|
1246
|
+
|
|
1247
|
+
const result = await generateSchema(collections, true);
|
|
1248
|
+
|
|
1249
|
+
// on_update should produce .default(sql`now()`) for initial INSERT value
|
|
1250
|
+
expect(result).toContain(".default(sql`now()`)");
|
|
1251
|
+
// No $onUpdate or triggers — update logic is handled by the backend driver
|
|
1252
|
+
expect(result).not.toContain(".$onUpdate");
|
|
1253
|
+
expect(result).not.toContain("CREATE OR REPLACE TRIGGER");
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
it("should not modify date columns without autoValue", async () => {
|
|
1257
|
+
const collections: EntityCollection[] = [
|
|
1258
|
+
{
|
|
1259
|
+
slug: "events",
|
|
1260
|
+
table: "events",
|
|
1261
|
+
name: "Events",
|
|
1262
|
+
properties: {
|
|
1263
|
+
name: { type: "string" },
|
|
1264
|
+
event_date: { type: "date" }
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
];
|
|
1268
|
+
|
|
1269
|
+
const result = await generateSchema(collections, true);
|
|
1270
|
+
|
|
1271
|
+
// A plain date should NOT have any autoValue-related modifiers
|
|
1272
|
+
expect(result).not.toContain(".default(sql`now()`)");
|
|
1273
|
+
expect(result).not.toContain(".$onUpdate");
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
it("should handle both on_create and on_update in the same collection", async () => {
|
|
1277
|
+
const collections: EntityCollection[] = [
|
|
1278
|
+
{
|
|
1279
|
+
slug: "posts",
|
|
1280
|
+
table: "posts",
|
|
1281
|
+
name: "Posts",
|
|
1282
|
+
properties: {
|
|
1283
|
+
title: { type: "string" },
|
|
1284
|
+
created_at: {
|
|
1285
|
+
type: "date",
|
|
1286
|
+
autoValue: "on_create"
|
|
1287
|
+
},
|
|
1288
|
+
updated_at: {
|
|
1289
|
+
type: "date",
|
|
1290
|
+
autoValue: "on_update"
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
];
|
|
1295
|
+
|
|
1296
|
+
const result = await generateSchema(collections, true);
|
|
1297
|
+
|
|
1298
|
+
// Both should get .default(sql`now()`) for INSERT defaults
|
|
1299
|
+
expect(result).toMatch(/created_at:.*\.default\(sql`now\(\)`\)/);
|
|
1300
|
+
expect(result).toMatch(/updated_at:.*\.default\(sql`now\(\)`\)/);
|
|
1301
|
+
// No $onUpdate or triggers
|
|
1302
|
+
expect(result).not.toContain(".$onUpdate");
|
|
1303
|
+
expect(result).not.toContain("CREATE OR REPLACE TRIGGER");
|
|
1304
|
+
});
|
|
1305
|
+
|
|
1306
|
+
it("should handle on_create with date columnType", async () => {
|
|
1307
|
+
const collections: EntityCollection[] = [
|
|
1308
|
+
{
|
|
1309
|
+
slug: "logs",
|
|
1310
|
+
table: "logs",
|
|
1311
|
+
name: "Logs",
|
|
1312
|
+
properties: {
|
|
1313
|
+
message: { type: "string" },
|
|
1314
|
+
log_date: {
|
|
1315
|
+
type: "date",
|
|
1316
|
+
columnType: "date",
|
|
1317
|
+
autoValue: "on_create"
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
];
|
|
1322
|
+
|
|
1323
|
+
const result = await generateSchema(collections, true);
|
|
1324
|
+
|
|
1325
|
+
// Should use date() column with the default
|
|
1326
|
+
expect(result).toContain("date(\"log_date\"");
|
|
1327
|
+
expect(result).toContain(".default(sql`now()`)");
|
|
1328
|
+
});
|
|
1329
|
+
});
|
|
1330
|
+
});
|