@rebasepro/server-postgresql 0.0.1-canary.000dc36
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 +11289 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +11297 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +106 -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 +46 -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 +195 -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/backend_hooks.d.ts +187 -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 +857 -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 +59 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/formex.d.ts +40 -0
- package/dist/types/src/types/index.d.ts +25 -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 +282 -0
- package/dist/types/src/types/properties.d.ts +1148 -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 +262 -0
- package/dist/types/src/types/translations.d.ts +874 -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 +93 -0
- package/scratch.ts +41 -0
- package/src/PostgresBackendDriver.ts +1017 -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 +747 -0
- package/src/schema/generate-drizzle-schema.ts +151 -0
- package/src/schema/introspect-db-logic.ts +592 -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 +355 -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 +1035 -0
- package/test/historyService.test.ts +141 -0
- package/test/introspect-db-generation.test.ts +436 -0
- package/test/introspect-db-utils.test.ts +392 -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,151 @@
|
|
|
1
|
+
import { promises as fsPromises } from "fs";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { pathToFileURL } from "url";
|
|
5
|
+
import chokidar from "chokidar";
|
|
6
|
+
import { generateSchema } from "./generate-drizzle-schema-logic";
|
|
7
|
+
import { EntityCollection } from "@rebasepro/types";
|
|
8
|
+
|
|
9
|
+
// --- Helper Functions ---
|
|
10
|
+
|
|
11
|
+
const formatTerminalText = (text: string, options: {
|
|
12
|
+
bold?: boolean;
|
|
13
|
+
backgroundColor?: "blue" | "green" | "red" | "yellow" | "cyan" | "magenta";
|
|
14
|
+
textColor?: "white" | "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan";
|
|
15
|
+
} = {}): string => {
|
|
16
|
+
let codes = "";
|
|
17
|
+
if (options.bold) codes += "\x1b[1m";
|
|
18
|
+
if (options.backgroundColor) {
|
|
19
|
+
const bgColors = {
|
|
20
|
+
blue: "\x1b[44m",
|
|
21
|
+
green: "\x1b[42m",
|
|
22
|
+
red: "\x1b[41m",
|
|
23
|
+
yellow: "\x1b[43m",
|
|
24
|
+
cyan: "\x1b[46m",
|
|
25
|
+
magenta: "\x1b[45m"
|
|
26
|
+
} as const;
|
|
27
|
+
codes += bgColors[options.backgroundColor];
|
|
28
|
+
}
|
|
29
|
+
if (options.textColor) {
|
|
30
|
+
const textColors = {
|
|
31
|
+
white: "\x1b[37m",
|
|
32
|
+
black: "\x1b[30m",
|
|
33
|
+
red: "\x1b[31m",
|
|
34
|
+
green: "\x1b[32m",
|
|
35
|
+
yellow: "\x1b[33m",
|
|
36
|
+
blue: "\x1b[34m",
|
|
37
|
+
magenta: "\x1b[35m",
|
|
38
|
+
cyan: "\x1b[36m"
|
|
39
|
+
} as const;
|
|
40
|
+
codes += textColors[options.textColor];
|
|
41
|
+
}
|
|
42
|
+
return `${codes}${text}\x1b[0m`;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// --- Execution and Watch Logic ---
|
|
46
|
+
|
|
47
|
+
const runGeneration = async (collectionsFilePath?: string, outputPath?: string) => {
|
|
48
|
+
try {
|
|
49
|
+
if (!collectionsFilePath) {
|
|
50
|
+
console.error("Error: No collections file path provided. Skipping schema generation.");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const resolvedPath = path.resolve(collectionsFilePath);
|
|
55
|
+
let collections: EntityCollection[] = [];
|
|
56
|
+
const stats = fs.statSync(resolvedPath);
|
|
57
|
+
|
|
58
|
+
if (stats.isDirectory()) {
|
|
59
|
+
const files = fs.readdirSync(resolvedPath);
|
|
60
|
+
for (const file of files) {
|
|
61
|
+
if ((file.endsWith(".ts") || file.endsWith(".js")) &&
|
|
62
|
+
!file.includes(".test.") &&
|
|
63
|
+
!file.endsWith(".d.ts") &&
|
|
64
|
+
file !== "index.ts" && file !== "index.js") {
|
|
65
|
+
|
|
66
|
+
const filePath = path.join(resolvedPath, file);
|
|
67
|
+
try {
|
|
68
|
+
const fileUrl = pathToFileURL(filePath).href;
|
|
69
|
+
const dynamicImport = new Function("url", "return import(url)");
|
|
70
|
+
const module = await dynamicImport(fileUrl);
|
|
71
|
+
if (module && module.default) {
|
|
72
|
+
collections.push(module.default);
|
|
73
|
+
}
|
|
74
|
+
} catch (err: unknown) {
|
|
75
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
76
|
+
console.error(`Error loading ${file}:`, message);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
const fileUrl = pathToFileURL(resolvedPath).href + `?t=${Date.now()}`;
|
|
82
|
+
const dynamicImport = new Function("url", "return import(url)");
|
|
83
|
+
const imported = await dynamicImport(fileUrl);
|
|
84
|
+
collections = imported.backendCollections || imported.collections;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!collections || !Array.isArray(collections) || collections.length === 0) {
|
|
88
|
+
console.error("Error: Could not find collections array or failed to load directory.");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const schemaContent = await generateSchema(collections);
|
|
93
|
+
|
|
94
|
+
if (outputPath) {
|
|
95
|
+
const outputDir = path.dirname(outputPath);
|
|
96
|
+
await fsPromises.mkdir(outputDir, { recursive: true });
|
|
97
|
+
await fsPromises.writeFile(outputPath, schemaContent);
|
|
98
|
+
console.log("✅ Drizzle schema generated successfully at", outputPath);
|
|
99
|
+
} else {
|
|
100
|
+
console.log("✅ Drizzle schema generated successfully.");
|
|
101
|
+
console.log(schemaContent);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(`You can now run ${formatTerminalText("rebase db generate", {
|
|
105
|
+
bold: true,
|
|
106
|
+
backgroundColor: "blue",
|
|
107
|
+
textColor: "black"
|
|
108
|
+
})} to generate the SQL migration files.`);
|
|
109
|
+
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error("Error generating schema:", error);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const main = () => {
|
|
116
|
+
const collectionsFilePathArg = process.argv.find(arg => arg.startsWith("--collections="));
|
|
117
|
+
const collectionsFilePath = collectionsFilePathArg ? collectionsFilePathArg.split("=")[1] : process.argv[2];
|
|
118
|
+
|
|
119
|
+
const outputPathArg = process.argv.find(arg => arg.startsWith("--output="));
|
|
120
|
+
const outputPath = outputPathArg ? outputPathArg.split("=")[1] : undefined;
|
|
121
|
+
|
|
122
|
+
const watch = process.argv.includes("--watch");
|
|
123
|
+
|
|
124
|
+
if (!collectionsFilePath) {
|
|
125
|
+
console.log("Usage: ts-node generate-drizzle-schema.ts <path-to-collections-file> [--output <path-to-output-file>] [--watch]");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const resolvedPath = path.resolve(process.cwd(), collectionsFilePath);
|
|
130
|
+
const resolvedOutputPath = outputPath ? path.resolve(process.cwd(), outputPath) : undefined;
|
|
131
|
+
|
|
132
|
+
if (watch) {
|
|
133
|
+
console.log(`Watching for changes in ${resolvedPath}...`);
|
|
134
|
+
const watcher = chokidar.watch(resolvedPath, {
|
|
135
|
+
persistent: true,
|
|
136
|
+
ignoreInitial: false
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
watcher.on("all", (event, filePath) => {
|
|
140
|
+
console.log(`[${event}] ${filePath}. Regenerating schema...`);
|
|
141
|
+
runGeneration(resolvedPath, resolvedOutputPath);
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
runGeneration(resolvedPath, resolvedOutputPath);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// This check ensures the script only runs when executed directly
|
|
149
|
+
if (import.meta.url.endsWith(process.argv[1])) {
|
|
150
|
+
main();
|
|
151
|
+
}
|