@rebasepro/server-postgresql 0.0.1-canary.09e5ec5
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/LICENSE +6 -0
- package/README.md +106 -0
- package/build-errors.txt +37 -0
- package/dist/common/src/collections/CollectionRegistry.d.ts +56 -0
- package/dist/common/src/collections/index.d.ts +1 -0
- package/dist/common/src/data/buildRebaseData.d.ts +14 -0
- package/dist/common/src/index.d.ts +3 -0
- package/dist/common/src/util/builders.d.ts +57 -0
- package/dist/common/src/util/callbacks.d.ts +6 -0
- package/dist/common/src/util/collections.d.ts +11 -0
- package/dist/common/src/util/common.d.ts +2 -0
- package/dist/common/src/util/conditions.d.ts +26 -0
- package/dist/common/src/util/entities.d.ts +58 -0
- package/dist/common/src/util/enums.d.ts +3 -0
- package/dist/common/src/util/index.d.ts +16 -0
- package/dist/common/src/util/navigation_from_path.d.ts +34 -0
- package/dist/common/src/util/navigation_utils.d.ts +20 -0
- package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
- package/dist/common/src/util/paths.d.ts +14 -0
- package/dist/common/src/util/permissions.d.ts +5 -0
- package/dist/common/src/util/references.d.ts +2 -0
- package/dist/common/src/util/relations.d.ts +22 -0
- package/dist/common/src/util/resolutions.d.ts +72 -0
- package/dist/common/src/util/storage.d.ts +24 -0
- package/dist/index.es.js +11298 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +11306 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +100 -0
- package/dist/server-postgresql/src/PostgresBootstrapper.d.ts +40 -0
- package/dist/server-postgresql/src/auth/ensure-tables.d.ts +6 -0
- package/dist/server-postgresql/src/auth/services.d.ts +192 -0
- package/dist/server-postgresql/src/cli.d.ts +1 -0
- package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +43 -0
- package/dist/server-postgresql/src/connection.d.ts +40 -0
- package/dist/server-postgresql/src/data-transformer.d.ts +58 -0
- package/dist/server-postgresql/src/databasePoolManager.d.ts +20 -0
- package/dist/server-postgresql/src/history/HistoryService.d.ts +71 -0
- package/dist/server-postgresql/src/history/ensure-history-table.d.ts +7 -0
- package/dist/server-postgresql/src/index.d.ts +13 -0
- package/dist/server-postgresql/src/interfaces.d.ts +18 -0
- package/dist/server-postgresql/src/schema/auth-schema.d.ts +868 -0
- package/dist/server-postgresql/src/schema/doctor-cli.d.ts +2 -0
- package/dist/server-postgresql/src/schema/doctor.d.ts +43 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema-logic.d.ts +2 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema.d.ts +1 -0
- package/dist/server-postgresql/src/schema/introspect-db-logic.d.ts +82 -0
- package/dist/server-postgresql/src/schema/introspect-db.d.ts +1 -0
- package/dist/server-postgresql/src/schema/test-schema.d.ts +24 -0
- package/dist/server-postgresql/src/services/BranchService.d.ts +47 -0
- package/dist/server-postgresql/src/services/EntityFetchService.d.ts +209 -0
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +41 -0
- package/dist/server-postgresql/src/services/RelationService.d.ts +98 -0
- package/dist/server-postgresql/src/services/entity-helpers.d.ts +38 -0
- package/dist/server-postgresql/src/services/entityService.d.ts +104 -0
- package/dist/server-postgresql/src/services/index.d.ts +4 -0
- package/dist/server-postgresql/src/services/realtimeService.d.ts +188 -0
- package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +116 -0
- package/dist/server-postgresql/src/websocket.d.ts +5 -0
- package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
- package/dist/types/src/controllers/auth.d.ts +119 -0
- package/dist/types/src/controllers/client.d.ts +170 -0
- package/dist/types/src/controllers/collection_registry.d.ts +45 -0
- package/dist/types/src/controllers/customization_controller.d.ts +60 -0
- package/dist/types/src/controllers/data.d.ts +168 -0
- package/dist/types/src/controllers/data_driver.d.ts +160 -0
- package/dist/types/src/controllers/database_admin.d.ts +11 -0
- package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
- package/dist/types/src/controllers/effective_role.d.ts +4 -0
- package/dist/types/src/controllers/email.d.ts +34 -0
- package/dist/types/src/controllers/index.d.ts +18 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
- package/dist/types/src/controllers/navigation.d.ts +213 -0
- package/dist/types/src/controllers/registry.d.ts +54 -0
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
- package/dist/types/src/controllers/snackbar.d.ts +24 -0
- package/dist/types/src/controllers/storage.d.ts +171 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/rebase_context.d.ts +105 -0
- package/dist/types/src/types/backend.d.ts +536 -0
- package/dist/types/src/types/builders.d.ts +15 -0
- package/dist/types/src/types/chips.d.ts +5 -0
- package/dist/types/src/types/collections.d.ts +856 -0
- package/dist/types/src/types/cron.d.ts +102 -0
- package/dist/types/src/types/data_source.d.ts +64 -0
- package/dist/types/src/types/entities.d.ts +145 -0
- package/dist/types/src/types/entity_actions.d.ts +98 -0
- package/dist/types/src/types/entity_callbacks.d.ts +173 -0
- package/dist/types/src/types/entity_link_builder.d.ts +7 -0
- package/dist/types/src/types/entity_overrides.d.ts +10 -0
- package/dist/types/src/types/entity_views.d.ts +61 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/index.d.ts +23 -0
- package/dist/types/src/types/locales.d.ts +4 -0
- package/dist/types/src/types/modify_collections.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +279 -0
- package/dist/types/src/types/properties.d.ts +1176 -0
- package/dist/types/src/types/property_config.d.ts +70 -0
- package/dist/types/src/types/relations.d.ts +336 -0
- package/dist/types/src/types/slots.d.ts +252 -0
- package/dist/types/src/types/translations.d.ts +870 -0
- package/dist/types/src/types/user_management_delegate.d.ts +121 -0
- package/dist/types/src/types/websockets.d.ts +78 -0
- package/dist/types/src/users/index.d.ts +2 -0
- package/dist/types/src/users/roles.d.ts +22 -0
- package/dist/types/src/users/user.d.ts +46 -0
- package/drizzle-test/0000_woozy_junta.sql +6 -0
- package/drizzle-test/0001_youthful_arachne.sql +1 -0
- package/drizzle-test/0002_lively_dragon_lord.sql +2 -0
- package/drizzle-test/0003_mean_king_cobra.sql +2 -0
- package/drizzle-test/meta/0000_snapshot.json +47 -0
- package/drizzle-test/meta/0001_snapshot.json +48 -0
- package/drizzle-test/meta/0002_snapshot.json +38 -0
- package/drizzle-test/meta/0003_snapshot.json +48 -0
- package/drizzle-test/meta/_journal.json +34 -0
- package/drizzle-test-out/0000_tan_trauma.sql +6 -0
- package/drizzle-test-out/0001_rapid_drax.sql +1 -0
- package/drizzle-test-out/meta/0000_snapshot.json +44 -0
- package/drizzle-test-out/meta/0001_snapshot.json +54 -0
- package/drizzle-test-out/meta/_journal.json +20 -0
- package/drizzle.test.config.ts +10 -0
- package/jest-all.log +3128 -0
- package/jest.log +49 -0
- package/package.json +92 -0
- package/scratch.ts +41 -0
- package/src/PostgresBackendDriver.ts +1008 -0
- package/src/PostgresBootstrapper.ts +231 -0
- package/src/auth/ensure-tables.ts +381 -0
- package/src/auth/services.ts +799 -0
- package/src/cli.ts +648 -0
- package/src/collections/PostgresCollectionRegistry.ts +96 -0
- package/src/connection.ts +84 -0
- package/src/data-transformer.ts +608 -0
- package/src/databasePoolManager.ts +85 -0
- package/src/history/HistoryService.ts +248 -0
- package/src/history/ensure-history-table.ts +45 -0
- package/src/index.ts +13 -0
- package/src/interfaces.ts +60 -0
- package/src/schema/auth-schema.ts +169 -0
- package/src/schema/doctor-cli.ts +47 -0
- package/src/schema/doctor.ts +595 -0
- package/src/schema/generate-drizzle-schema-logic.ts +765 -0
- package/src/schema/generate-drizzle-schema.ts +151 -0
- package/src/schema/introspect-db-logic.ts +542 -0
- package/src/schema/introspect-db.ts +211 -0
- package/src/schema/test-schema.ts +11 -0
- package/src/services/BranchService.ts +237 -0
- package/src/services/EntityFetchService.ts +1576 -0
- package/src/services/EntityPersistService.ts +349 -0
- package/src/services/RelationService.ts +1274 -0
- package/src/services/entity-helpers.ts +147 -0
- package/src/services/entityService.ts +211 -0
- package/src/services/index.ts +13 -0
- package/src/services/realtimeService.ts +1034 -0
- package/src/utils/drizzle-conditions.ts +1000 -0
- package/src/websocket.ts +518 -0
- package/test/auth-services.test.ts +661 -0
- package/test/batch-many-to-many-regression.test.ts +573 -0
- package/test/branchService.test.ts +367 -0
- package/test/data-transformer-hardening.test.ts +417 -0
- package/test/data-transformer.test.ts +175 -0
- package/test/doctor.test.ts +182 -0
- package/test/drizzle-conditions.test.ts +895 -0
- package/test/entityService.errors.test.ts +367 -0
- package/test/entityService.relations.test.ts +1008 -0
- package/test/entityService.subcollection-search.test.ts +566 -0
- package/test/entityService.test.ts +1035 -0
- package/test/generate-drizzle-schema.test.ts +988 -0
- package/test/historyService.test.ts +141 -0
- package/test/introspect-db-generation.test.ts +436 -0
- package/test/introspect-db-utils.test.ts +389 -0
- package/test/n-plus-one-regression.test.ts +314 -0
- package/test/postgresDataDriver.test.ts +648 -0
- package/test/realtimeService.test.ts +307 -0
- package/test/relation-pipeline-gaps.test.ts +637 -0
- package/test/relations.test.ts +1115 -0
- package/test/unmapped-tables-safety.test.ts +345 -0
- package/test-drizzle-bug.ts +18 -0
- package/test-drizzle-out/0000_cultured_freak.sql +7 -0
- package/test-drizzle-out/0001_tiresome_professor_monster.sql +1 -0
- package/test-drizzle-out/meta/0000_snapshot.json +55 -0
- package/test-drizzle-out/meta/0001_snapshot.json +63 -0
- package/test-drizzle-out/meta/_journal.json +20 -0
- package/test-drizzle-prompt.sh +2 -0
- package/test-policy-prompt.sh +3 -0
- package/test-programmatic.ts +30 -0
- package/test-programmatic2.ts +59 -0
- package/test-schema-no-policies.ts +12 -0
- package/test_drizzle_mock.js +3 -0
- package/test_find_changed.mjs +32 -0
- package/test_hash.js +14 -0
- package/test_output.txt +3145 -0
- package/tsconfig.json +49 -0
- package/tsconfig.prod.json +20 -0
- package/vite.config.ts +82 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import {
|
|
2
|
+
singularize, humanize, toCollectionVarName, getIconForTable,
|
|
3
|
+
mapPgType, buildEnumMap, buildTablesMap, identifyJoinTables,
|
|
4
|
+
generateIndexContent, mergeIndexContent, safeHostFromUrl,
|
|
5
|
+
EnumValue, TableRow, TableColumn, PrimaryKeyRow, ForeignKeyRow,
|
|
6
|
+
} from "../src/schema/introspect-db-logic";
|
|
7
|
+
|
|
8
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
9
|
+
// singularize()
|
|
10
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
11
|
+
describe("singularize", () => {
|
|
12
|
+
it("strips trailing s from regular plurals", () => {
|
|
13
|
+
expect(singularize("users")).toBe("user");
|
|
14
|
+
expect(singularize("products")).toBe("product");
|
|
15
|
+
expect(singularize("posts")).toBe("post");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("converts -ies to -y", () => {
|
|
19
|
+
expect(singularize("categories")).toBe("category");
|
|
20
|
+
expect(singularize("companies")).toBe("company");
|
|
21
|
+
expect(singularize("stories")).toBe("story");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("converts -ves to -f", () => {
|
|
25
|
+
expect(singularize("wolves")).toBe("wolf");
|
|
26
|
+
expect(singularize("leaves")).toBe("leaf");
|
|
27
|
+
expect(singularize("knives")).toBe("knif"); // known edge-case
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("converts -ches, -shes, -sses, -xes, -zes", () => {
|
|
31
|
+
expect(singularize("batches")).toBe("batch");
|
|
32
|
+
expect(singularize("wishes")).toBe("wish");
|
|
33
|
+
expect(singularize("classes")).toBe("class");
|
|
34
|
+
expect(singularize("boxes")).toBe("box");
|
|
35
|
+
expect(singularize("buzzes")).toBe("buzz");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("converts -ses (not -sses) by removing trailing s", () => {
|
|
39
|
+
expect(singularize("responses")).toBe("response");
|
|
40
|
+
expect(singularize("databases")).toBe("database");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("converts -ices to -ex", () => {
|
|
44
|
+
expect(singularize("indices")).toBe("index");
|
|
45
|
+
expect(singularize("vertices")).toBe("vertex");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("handles irregular plurals", () => {
|
|
49
|
+
expect(singularize("people")).toBe("person");
|
|
50
|
+
expect(singularize("children")).toBe("child");
|
|
51
|
+
expect(singularize("men")).toBe("man");
|
|
52
|
+
expect(singularize("women")).toBe("woman");
|
|
53
|
+
expect(singularize("mice")).toBe("mouse");
|
|
54
|
+
expect(singularize("geese")).toBe("goose");
|
|
55
|
+
expect(singularize("teeth")).toBe("tooth");
|
|
56
|
+
expect(singularize("feet")).toBe("foot");
|
|
57
|
+
expect(singularize("data")).toBe("datum");
|
|
58
|
+
expect(singularize("media")).toBe("medium");
|
|
59
|
+
expect(singularize("criteria")).toBe("criterion");
|
|
60
|
+
expect(singularize("phenomena")).toBe("phenomenon");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("preserves casing on irregular plurals", () => {
|
|
64
|
+
expect(singularize("People")).toBe("Person");
|
|
65
|
+
expect(singularize("Children")).toBe("Child");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("leaves uncountable words unchanged", () => {
|
|
69
|
+
expect(singularize("status")).toBe("status");
|
|
70
|
+
expect(singularize("news")).toBe("news");
|
|
71
|
+
expect(singularize("series")).toBe("series");
|
|
72
|
+
expect(singularize("species")).toBe("species");
|
|
73
|
+
expect(singularize("analysis")).toBe("analysis");
|
|
74
|
+
expect(singularize("diagnosis")).toBe("diagnosis");
|
|
75
|
+
expect(singularize("crisis")).toBe("crisis");
|
|
76
|
+
expect(singularize("thesis")).toBe("thesis");
|
|
77
|
+
expect(singularize("bus")).toBe("bus");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("leaves already-singular words unchanged", () => {
|
|
81
|
+
expect(singularize("user")).toBe("user");
|
|
82
|
+
expect(singularize("address")).toBe("address");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("does not strip -ss words", () => {
|
|
86
|
+
expect(singularize("boss")).toBe("boss");
|
|
87
|
+
expect(singularize("glass")).toBe("glass");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
92
|
+
// humanize()
|
|
93
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
94
|
+
describe("humanize", () => {
|
|
95
|
+
it("converts snake_case to Title Case", () => {
|
|
96
|
+
expect(humanize("created_at")).toBe("Created At");
|
|
97
|
+
expect(humanize("customer_id")).toBe("Customer Id");
|
|
98
|
+
expect(humanize("first_name")).toBe("First Name");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("capitalizes single words", () => {
|
|
102
|
+
expect(humanize("name")).toBe("Name");
|
|
103
|
+
expect(humanize("id")).toBe("Id");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("handles multiple underscores", () => {
|
|
107
|
+
expect(humanize("user_profile_image")).toBe("User Profile Image");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("handles already capitalized input", () => {
|
|
111
|
+
expect(humanize("Name")).toBe("Name");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
116
|
+
// toCollectionVarName()
|
|
117
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
118
|
+
describe("toCollectionVarName", () => {
|
|
119
|
+
it("converts snake_case to camelCase + Collection", () => {
|
|
120
|
+
expect(toCollectionVarName("company_token")).toBe("companyTokenCollection");
|
|
121
|
+
expect(toCollectionVarName("user_profile")).toBe("userProfileCollection");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("handles single-word tables", () => {
|
|
125
|
+
expect(toCollectionVarName("users")).toBe("usersCollection");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("handles multi-segment names", () => {
|
|
129
|
+
expect(toCollectionVarName("user_account_settings")).toBe("userAccountSettingsCollection");
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
134
|
+
// getIconForTable()
|
|
135
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
136
|
+
describe("getIconForTable", () => {
|
|
137
|
+
const cases: [string, string][] = [
|
|
138
|
+
["users", "Users"], ["accounts", "Users"], ["members", "Users"],
|
|
139
|
+
["customers", "Users"], ["clients", "Users"], ["patients", "Users"],
|
|
140
|
+
["posts", "FileText"], ["articles", "FileText"], ["blog_entries", "FileText"],
|
|
141
|
+
["pages", "FileText"],
|
|
142
|
+
["products", "Package"], ["items", "Package"],
|
|
143
|
+
["orders", "ShoppingCart"], ["cart", "ShoppingCart"],
|
|
144
|
+
["purchases", "ShoppingCart"], ["invoices", "ShoppingCart"],
|
|
145
|
+
["settings", "Settings"], ["app_config", "Settings"],
|
|
146
|
+
["tags", "Tag"], ["categories", "Tag"],
|
|
147
|
+
["images", "Image"], ["photos", "Image"], ["media_assets", "Image"],
|
|
148
|
+
["notifications", "Mail"], ["messages", "Mail"], ["emails", "Mail"],
|
|
149
|
+
["audit_log", "Activity"], ["events", "Activity"],
|
|
150
|
+
["subscriptions", "CreditCard"], ["plans", "CreditCard"], ["billing", "CreditCard"],
|
|
151
|
+
["comments", "MessageCircle"], ["reviews", "MessageCircle"], ["feedback", "MessageCircle"],
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
it.each(cases)("returns %s -> %s", (table, icon) => {
|
|
155
|
+
expect(getIconForTable(table)).toBe(icon);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("falls back to Database for unknown tables", () => {
|
|
159
|
+
expect(getIconForTable("foobar")).toBe("Database");
|
|
160
|
+
expect(getIconForTable("xyz_data")).toBe("Database");
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
165
|
+
// mapPgType()
|
|
166
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
167
|
+
describe("mapPgType", () => {
|
|
168
|
+
it("maps integer types to number", () => {
|
|
169
|
+
for (const t of ["integer", "smallint", "bigint", "int4", "int8"]) {
|
|
170
|
+
expect(mapPgType(t)).toBe("number");
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
it("maps serial types to number", () => {
|
|
174
|
+
// serial/bigserial don't contain 'int' — they need explicit matching
|
|
175
|
+
for (const t of ["serial", "bigserial"]) {
|
|
176
|
+
expect(mapPgType(t)).toBe("number");
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
it("maps decimal types to number", () => {
|
|
180
|
+
for (const t of ["numeric", "decimal", "real", "float4", "float8", "double precision", "money"]) {
|
|
181
|
+
expect(mapPgType(t)).toBe("number");
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
it("maps boolean types", () => {
|
|
185
|
+
expect(mapPgType("boolean")).toBe("boolean");
|
|
186
|
+
expect(mapPgType("bool")).toBe("boolean");
|
|
187
|
+
});
|
|
188
|
+
it("maps date/time types to date", () => {
|
|
189
|
+
for (const t of ["timestamp", "timestamptz", "date", "time", "timetz", "timestamp with time zone"]) {
|
|
190
|
+
expect(mapPgType(t)).toBe("date");
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
it("maps JSON types to json", () => {
|
|
194
|
+
expect(mapPgType("json")).toBe("json");
|
|
195
|
+
expect(mapPgType("jsonb")).toBe("json");
|
|
196
|
+
});
|
|
197
|
+
it("maps ARRAY and underscore-prefixed types to json", () => {
|
|
198
|
+
expect(mapPgType("ARRAY")).toBe("json");
|
|
199
|
+
expect(mapPgType("_int4")).toBe("json");
|
|
200
|
+
expect(mapPgType("_text")).toBe("json");
|
|
201
|
+
});
|
|
202
|
+
it("maps string-like types to string", () => {
|
|
203
|
+
for (const t of ["text", "varchar", "character varying", "char", "character", "uuid", "bytea", "inet", "cidr", "macaddr", "macaddr8", "interval"]) {
|
|
204
|
+
expect(mapPgType(t)).toBe("string");
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
it("defaults unknown types to string", () => {
|
|
208
|
+
expect(mapPgType("tsvector")).toBe("string");
|
|
209
|
+
expect(mapPgType("xml")).toBe("string");
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
214
|
+
// buildEnumMap()
|
|
215
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
216
|
+
describe("buildEnumMap", () => {
|
|
217
|
+
it("groups enum values by name in order", () => {
|
|
218
|
+
const vals: EnumValue[] = [
|
|
219
|
+
{ enum_name: "status", enum_value: "active", sort_order: 1 },
|
|
220
|
+
{ enum_name: "status", enum_value: "inactive", sort_order: 2 },
|
|
221
|
+
{ enum_name: "role", enum_value: "admin", sort_order: 1 },
|
|
222
|
+
{ enum_name: "role", enum_value: "user", sort_order: 2 },
|
|
223
|
+
];
|
|
224
|
+
const map = buildEnumMap(vals);
|
|
225
|
+
expect(map.get("status")).toEqual(["active", "inactive"]);
|
|
226
|
+
expect(map.get("role")).toEqual(["admin", "user"]);
|
|
227
|
+
});
|
|
228
|
+
it("returns empty map for no enums", () => {
|
|
229
|
+
expect(buildEnumMap([]).size).toBe(0);
|
|
230
|
+
});
|
|
231
|
+
it("handles single-value enums", () => {
|
|
232
|
+
const map = buildEnumMap([{ enum_name: "flag", enum_value: "yes", sort_order: 1 }]);
|
|
233
|
+
expect(map.get("flag")).toEqual(["yes"]);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
238
|
+
// buildTablesMap()
|
|
239
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
240
|
+
describe("buildTablesMap", () => {
|
|
241
|
+
it("groups columns, pks and fks by table", () => {
|
|
242
|
+
const tables: TableRow[] = [{ table_name: "users" }, { table_name: "posts" }];
|
|
243
|
+
const cols: TableColumn[] = [
|
|
244
|
+
{ table_name: "users", column_name: "id", data_type: "uuid", udt_name: "uuid", is_nullable: "NO", column_default: null },
|
|
245
|
+
{ table_name: "posts", column_name: "id", data_type: "uuid", udt_name: "uuid", is_nullable: "NO", column_default: null },
|
|
246
|
+
{ table_name: "posts", column_name: "user_id", data_type: "uuid", udt_name: "uuid", is_nullable: "NO", column_default: null },
|
|
247
|
+
];
|
|
248
|
+
const pks: PrimaryKeyRow[] = [
|
|
249
|
+
{ table_name: "users", column_name: "id" },
|
|
250
|
+
{ table_name: "posts", column_name: "id" },
|
|
251
|
+
];
|
|
252
|
+
const fks: ForeignKeyRow[] = [
|
|
253
|
+
{ table_name: "posts", column_name: "user_id", foreign_table_name: "users", foreign_column_name: "id" },
|
|
254
|
+
];
|
|
255
|
+
const map = buildTablesMap(tables, cols, pks, fks);
|
|
256
|
+
expect(map.size).toBe(2);
|
|
257
|
+
expect(map.get("users")!.pks).toEqual(["id"]);
|
|
258
|
+
expect(map.get("posts")!.fks).toHaveLength(1);
|
|
259
|
+
expect(map.get("posts")!.columns).toHaveLength(2);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
264
|
+
// identifyJoinTables()
|
|
265
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
266
|
+
describe("identifyJoinTables", () => {
|
|
267
|
+
const mkCol = (table: string, col: string): TableColumn => ({
|
|
268
|
+
table_name: table, column_name: col, data_type: "uuid",
|
|
269
|
+
udt_name: "uuid", is_nullable: "NO", column_default: null,
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("detects a pure junction table with exactly 2 FKs", () => {
|
|
273
|
+
const tablesMap = new Map([
|
|
274
|
+
["posts_to_tags", {
|
|
275
|
+
name: "posts_to_tags",
|
|
276
|
+
columns: [mkCol("posts_to_tags", "post_id"), mkCol("posts_to_tags", "tag_id")],
|
|
277
|
+
pks: [],
|
|
278
|
+
fks: [
|
|
279
|
+
{ table_name: "posts_to_tags", column_name: "post_id", foreign_table_name: "posts", foreign_column_name: "id" },
|
|
280
|
+
{ table_name: "posts_to_tags", column_name: "tag_id", foreign_table_name: "tags", foreign_column_name: "id" },
|
|
281
|
+
],
|
|
282
|
+
}],
|
|
283
|
+
]);
|
|
284
|
+
expect(identifyJoinTables(tablesMap)).toEqual(new Set(["posts_to_tags"]));
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("allows id, created_at, updated_at metadata columns on join tables", () => {
|
|
288
|
+
const tablesMap = new Map([
|
|
289
|
+
["posts_tags", {
|
|
290
|
+
name: "posts_tags",
|
|
291
|
+
columns: [
|
|
292
|
+
mkCol("posts_tags", "id"),
|
|
293
|
+
mkCol("posts_tags", "post_id"),
|
|
294
|
+
mkCol("posts_tags", "tag_id"),
|
|
295
|
+
mkCol("posts_tags", "created_at"),
|
|
296
|
+
],
|
|
297
|
+
pks: ["id"],
|
|
298
|
+
fks: [
|
|
299
|
+
{ table_name: "posts_tags", column_name: "post_id", foreign_table_name: "posts", foreign_column_name: "id" },
|
|
300
|
+
{ table_name: "posts_tags", column_name: "tag_id", foreign_table_name: "tags", foreign_column_name: "id" },
|
|
301
|
+
],
|
|
302
|
+
}],
|
|
303
|
+
]);
|
|
304
|
+
expect(identifyJoinTables(tablesMap).has("posts_tags")).toBe(true);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("does NOT flag tables with extra non-metadata columns", () => {
|
|
308
|
+
const tablesMap = new Map([
|
|
309
|
+
["enrollments", {
|
|
310
|
+
name: "enrollments",
|
|
311
|
+
columns: [
|
|
312
|
+
mkCol("enrollments", "student_id"),
|
|
313
|
+
mkCol("enrollments", "course_id"),
|
|
314
|
+
mkCol("enrollments", "grade"), // extra column
|
|
315
|
+
],
|
|
316
|
+
pks: [],
|
|
317
|
+
fks: [
|
|
318
|
+
{ table_name: "enrollments", column_name: "student_id", foreign_table_name: "students", foreign_column_name: "id" },
|
|
319
|
+
{ table_name: "enrollments", column_name: "course_id", foreign_table_name: "courses", foreign_column_name: "id" },
|
|
320
|
+
],
|
|
321
|
+
}],
|
|
322
|
+
]);
|
|
323
|
+
expect(identifyJoinTables(tablesMap).size).toBe(0);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it("does NOT flag tables with only 1 FK", () => {
|
|
327
|
+
const tablesMap = new Map([
|
|
328
|
+
["posts", {
|
|
329
|
+
name: "posts",
|
|
330
|
+
columns: [mkCol("posts", "id"), mkCol("posts", "user_id")],
|
|
331
|
+
pks: ["id"],
|
|
332
|
+
fks: [
|
|
333
|
+
{ table_name: "posts", column_name: "user_id", foreign_table_name: "users", foreign_column_name: "id" },
|
|
334
|
+
],
|
|
335
|
+
}],
|
|
336
|
+
]);
|
|
337
|
+
expect(identifyJoinTables(tablesMap).size).toBe(0);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
342
|
+
// generateIndexContent()
|
|
343
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
344
|
+
describe("generateIndexContent", () => {
|
|
345
|
+
it("generates sorted export lines", () => {
|
|
346
|
+
const result = generateIndexContent(["zebra", "apple", "mango"]);
|
|
347
|
+
const lines = result.trim().split("\n");
|
|
348
|
+
expect(lines[0]).toContain("apple");
|
|
349
|
+
expect(lines[1]).toContain("mango");
|
|
350
|
+
expect(lines[2]).toContain("zebra");
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("each line is a default re-export", () => {
|
|
354
|
+
const result = generateIndexContent(["users"]);
|
|
355
|
+
expect(result).toBe('export { default as users } from "./users";\n');
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
360
|
+
// mergeIndexContent()
|
|
361
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
362
|
+
describe("mergeIndexContent", () => {
|
|
363
|
+
it("adds new exports without duplicating existing ones", () => {
|
|
364
|
+
const existing = 'export { default as users } from "./users";\n';
|
|
365
|
+
const result = mergeIndexContent(existing, ["users", "posts"]);
|
|
366
|
+
expect(result.match(/users/g)!.length).toBe(2); // one in existing, one mention in "users" still just 1 export line
|
|
367
|
+
expect(result).toContain('export { default as posts } from "./posts";');
|
|
368
|
+
// users should appear exactly once as an export statement
|
|
369
|
+
expect(result.match(/export.*users.*from/g)!.length).toBe(1);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("returns existing content trimmed + newline when no new files", () => {
|
|
373
|
+
const existing = 'export { default as a } from "./a";\n';
|
|
374
|
+
const result = mergeIndexContent(existing, ["a"]);
|
|
375
|
+
expect(result.trim()).toBe(existing.trim());
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
380
|
+
// safeHostFromUrl()
|
|
381
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
382
|
+
describe("safeHostFromUrl", () => {
|
|
383
|
+
it("extracts host after @", () => {
|
|
384
|
+
expect(safeHostFromUrl("postgres://user:pass@localhost:5432/db")).toBe("localhost:5432/db");
|
|
385
|
+
});
|
|
386
|
+
it("returns fallback for URLs without @", () => {
|
|
387
|
+
expect(safeHostFromUrl("localhost:5432/db")).toBe("(local connection)");
|
|
388
|
+
});
|
|
389
|
+
});
|