@rebasepro/server-postgres 0.17.3-canary.gdd23447 → 0.18.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.
Files changed (149) hide show
  1. package/LICENSE +0 -1
  2. package/README.md +31 -0
  3. package/dist/backup-argv.d.ts +19 -0
  4. package/dist/branch-argv.d.ts +28 -0
  5. package/dist/branch-prune.d.ts +77 -0
  6. package/dist/cli-collections-path.d.ts +31 -0
  7. package/dist/cli-errors.d.ts +123 -0
  8. package/dist/cli-flags.d.ts +101 -0
  9. package/dist/cli-helpers.d.ts +94 -10
  10. package/dist/collection-index-C7LopMyX.js +247 -0
  11. package/dist/collection-index-C7LopMyX.js.map +1 -0
  12. package/dist/databasePoolManager.d.ts +27 -0
  13. package/dist/{ensure-collection-policies-UCqgv_8c.js → ensure-collection-policies-CagOzEPS.js} +6 -6
  14. package/dist/{ensure-collection-policies-UCqgv_8c.js.map → ensure-collection-policies-CagOzEPS.js.map} +1 -1
  15. package/dist/{ensure-collection-tables-DgVixhX3.js → ensure-collection-tables-DbAhrjnG.js} +614 -52
  16. package/dist/ensure-collection-tables-DbAhrjnG.js.map +1 -0
  17. package/dist/index.d.ts +12 -0
  18. package/dist/index.es.js +19307 -3059
  19. package/dist/index.es.js.map +1 -1
  20. package/dist/{rls-enforcement-DvAbL9YJ.js → rls-enforcement-ClJoTboT.js} +53 -189
  21. package/dist/rls-enforcement-ClJoTboT.js.map +1 -0
  22. package/dist/schema/column-type-drift.d.ts +79 -0
  23. package/dist/schema/doctor.d.ts +42 -0
  24. package/dist/schema/ensure-collection-tables.d.ts +90 -0
  25. package/dist/schema/generate-next-step.d.ts +30 -0
  26. package/dist/schema/generate-postgres-ddl-logic.d.ts +28 -0
  27. package/dist/schema/generated-schema-staleness.d.ts +37 -0
  28. package/dist/schema/introspect-db-queries.d.ts +34 -0
  29. package/dist/security/rls-enforcement.d.ts +63 -2
  30. package/dist/services/BranchService.d.ts +86 -1
  31. package/dist/services/collection-helpers.d.ts +1 -1
  32. package/dist/services/realtimeService.d.ts +30 -2
  33. package/dist/services/row-pipeline.d.ts +12 -1
  34. package/dist/utils/pg-error-utils.d.ts +3 -1
  35. package/dist/utils/pg-numeric-number-patch.d.ts +31 -0
  36. package/package.json +32 -27
  37. package/dist/backup-service-DCk7KhhL.js +0 -9044
  38. package/dist/backup-service-DCk7KhhL.js.map +0 -1
  39. package/dist/collection-index-BRUg10H5.js +0 -5690
  40. package/dist/collection-index-BRUg10H5.js.map +0 -1
  41. package/dist/connection-GOKU3Hu5.js +0 -277
  42. package/dist/connection-GOKU3Hu5.js.map +0 -1
  43. package/dist/ensure-collection-tables-DgVixhX3.js.map +0 -1
  44. package/dist/rls-bootstrap-sql-B5C9LoJ6.js +0 -244
  45. package/dist/rls-bootstrap-sql-B5C9LoJ6.js.map +0 -1
  46. package/dist/rls-enforcement-DvAbL9YJ.js.map +0 -1
  47. package/dist/src-DiB5RP2Z.js +0 -541
  48. package/dist/src-DiB5RP2Z.js.map +0 -1
  49. package/dist/websocket-BZ4H5wUz.js +0 -8198
  50. package/dist/websocket-BZ4H5wUz.js.map +0 -1
  51. package/src/PostgresAdapter.ts +0 -91
  52. package/src/PostgresBackendDriver.ts +0 -1857
  53. package/src/PostgresBootstrapper.ts +0 -1157
  54. package/src/auth/ensure-tables.ts +0 -896
  55. package/src/auth/schema-version.ts +0 -260
  56. package/src/auth/services.ts +0 -1610
  57. package/src/backup/backup-cli.ts +0 -520
  58. package/src/backup/backup-cron.ts +0 -212
  59. package/src/backup/backup-logic.ts +0 -93
  60. package/src/backup/backup-service.ts +0 -485
  61. package/src/backup/index.ts +0 -12
  62. package/src/backup/pg-tools.ts +0 -403
  63. package/src/backup/retention.ts +0 -86
  64. package/src/cli-errors.ts +0 -265
  65. package/src/cli-helpers.ts +0 -569
  66. package/src/cli-output.ts +0 -43
  67. package/src/cli.ts +0 -1339
  68. package/src/collections/PostgresCollectionRegistry.ts +0 -108
  69. package/src/collections/buildRegistry.ts +0 -68
  70. package/src/collections/validate-relations.ts +0 -402
  71. package/src/connection.ts +0 -333
  72. package/src/data-transformer.ts +0 -845
  73. package/src/databasePoolManager.ts +0 -95
  74. package/src/history/HistoryService.ts +0 -254
  75. package/src/history/ensure-history-table.ts +0 -53
  76. package/src/index.ts +0 -19
  77. package/src/interfaces.ts +0 -60
  78. package/src/module-dir.ts +0 -7
  79. package/src/schema/atlas-argv.ts +0 -94
  80. package/src/schema/auth-schema.ts +0 -298
  81. package/src/schema/auth-users-columns.ts +0 -131
  82. package/src/schema/carved-out-migration.ts +0 -404
  83. package/src/schema/classify-change.ts +0 -436
  84. package/src/schema/collection-index.ts +0 -427
  85. package/src/schema/collections-schema-version.ts +0 -103
  86. package/src/schema/destructive-sql.ts +0 -94
  87. package/src/schema/doctor-cli.ts +0 -66
  88. package/src/schema/doctor-policy-checks.ts +0 -105
  89. package/src/schema/doctor.ts +0 -837
  90. package/src/schema/drizzle-ddl.ts +0 -33
  91. package/src/schema/dynamic-tables.test.ts +0 -302
  92. package/src/schema/dynamic-tables.ts +0 -293
  93. package/src/schema/ensure-collection-policies.ts +0 -198
  94. package/src/schema/ensure-collection-tables.test.ts +0 -518
  95. package/src/schema/ensure-collection-tables.ts +0 -1267
  96. package/src/schema/generate-drizzle-schema-logic.ts +0 -957
  97. package/src/schema/generate-drizzle-schema.ts +0 -143
  98. package/src/schema/generate-postgres-ddl-logic.ts +0 -1339
  99. package/src/schema/generate-postgres-ddl.ts +0 -180
  100. package/src/schema/generate-schema-commit.ts +0 -267
  101. package/src/schema/generated-schema-staleness.ts +0 -284
  102. package/src/schema/introspect-db-constraints.ts +0 -385
  103. package/src/schema/introspect-db-inference.ts +0 -255
  104. package/src/schema/introspect-db-logic.ts +0 -1387
  105. package/src/schema/introspect-db-naming.ts +0 -15
  106. package/src/schema/introspect-db-project.ts +0 -78
  107. package/src/schema/introspect-db-queries.ts +0 -326
  108. package/src/schema/introspect-db-structure.ts +0 -670
  109. package/src/schema/introspect-db-types.ts +0 -56
  110. package/src/schema/introspect-db.ts +0 -257
  111. package/src/schema/introspect-runtime.test.ts +0 -260
  112. package/src/schema/introspect-runtime.ts +0 -327
  113. package/src/schema/non-sql-collections.test.ts +0 -131
  114. package/src/schema/rls-bootstrap-sql.ts +0 -288
  115. package/src/schema/search-column.ts +0 -643
  116. package/src/schema/test-schema.ts +0 -11
  117. package/src/schema/vector-index.ts +0 -491
  118. package/src/security/anonymous-grants.test.ts +0 -73
  119. package/src/security/policy-drift.test.ts +0 -435
  120. package/src/security/policy-drift.ts +0 -473
  121. package/src/security/rls-enforcement.ts +0 -505
  122. package/src/services/BranchService.ts +0 -326
  123. package/src/services/FetchService.ts +0 -2115
  124. package/src/services/PersistService.ts +0 -557
  125. package/src/services/RelationService.ts +0 -978
  126. package/src/services/RelationWriteService.ts +0 -653
  127. package/src/services/cdc/CdcListener.ts +0 -103
  128. package/src/services/cdc/junction-tables.ts +0 -91
  129. package/src/services/cdc/trigger-cdc.ts +0 -173
  130. package/src/services/channel-bus/ChannelBus.ts +0 -44
  131. package/src/services/channel-bus/PostgresChannelBus.ts +0 -299
  132. package/src/services/channel-bus/index.ts +0 -114
  133. package/src/services/channel-history.ts +0 -424
  134. package/src/services/channel-presence.ts +0 -185
  135. package/src/services/collection-helpers.ts +0 -420
  136. package/src/services/dataService.ts +0 -256
  137. package/src/services/index.ts +0 -14
  138. package/src/services/junction-writes.ts +0 -295
  139. package/src/services/nested-path.ts +0 -145
  140. package/src/services/pg-notify-listener.ts +0 -151
  141. package/src/services/realtimeService.ts +0 -2545
  142. package/src/services/row-pipeline.ts +0 -240
  143. package/src/services/write-denial.ts +0 -55
  144. package/src/types.ts +0 -4
  145. package/src/utils/connection-string.ts +0 -58
  146. package/src/utils/drizzle-conditions.ts +0 -2743
  147. package/src/utils/pg-array-null-patch.ts +0 -42
  148. package/src/utils/pg-error-utils.ts +0 -391
  149. package/src/websocket.ts +0 -855
@@ -1,143 +0,0 @@
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 { generateSchema } from "./generate-drizzle-schema-logic";
6
- import { CollectionConfig } from "@rebasepro/types";
7
- import { loadCollectionsFromDirectory } from "@rebasepro/server";
8
- import { out, outError } from "../cli-output";
9
-
10
-
11
- // --- Helper Functions ---
12
-
13
- const formatTerminalText = (text: string, options: {
14
- bold?: boolean;
15
- backgroundColor?: "blue" | "green" | "red" | "yellow" | "cyan" | "magenta";
16
- textColor?: "white" | "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan";
17
- } = {}): string => {
18
- let codes = "";
19
- if (options.bold) codes += "\x1b[1m";
20
- if (options.backgroundColor) {
21
- const bgColors = {
22
- blue: "\x1b[44m",
23
- green: "\x1b[42m",
24
- red: "\x1b[41m",
25
- yellow: "\x1b[43m",
26
- cyan: "\x1b[46m",
27
- magenta: "\x1b[45m"
28
- } as const;
29
- codes += bgColors[options.backgroundColor];
30
- }
31
- if (options.textColor) {
32
- const textColors = {
33
- white: "\x1b[37m",
34
- black: "\x1b[30m",
35
- red: "\x1b[31m",
36
- green: "\x1b[32m",
37
- yellow: "\x1b[33m",
38
- blue: "\x1b[34m",
39
- magenta: "\x1b[35m",
40
- cyan: "\x1b[36m"
41
- } as const;
42
- codes += textColors[options.textColor];
43
- }
44
- return `${codes}${text}\x1b[0m`;
45
- };
46
-
47
- // --- Execution and Watch Logic ---
48
-
49
- const runGeneration = async (collectionsFilePath?: string, outputPath?: string) => {
50
- try {
51
- if (!collectionsFilePath) {
52
- outError("Error: No collections file path provided. Skipping schema generation.");
53
- return;
54
- }
55
-
56
- const resolvedPath = path.resolve(collectionsFilePath);
57
-
58
- // Shared with the runtime and the doctor: what gets generated here must
59
- // be exactly what the server serves, including directory-level defaults.
60
- let collections: CollectionConfig[] = await loadCollectionsFromDirectory(resolvedPath);
61
-
62
-
63
- // If collections directory is empty but exists, or failed to find any, we still want to inject defaults
64
- if (!collections || !Array.isArray(collections)) {
65
- collections = [];
66
- }
67
-
68
-
69
- // Sort collections by slug alphabetically to ensure deterministic schema generation
70
- collections.sort((a, b) => a.slug.localeCompare(b.slug));
71
-
72
- const schemaContent = await generateSchema(collections);
73
-
74
- if (outputPath) {
75
- const outputDir = path.dirname(outputPath);
76
- await fsPromises.mkdir(outputDir, { recursive: true });
77
- await fsPromises.writeFile(outputPath, schemaContent);
78
- out(`✅ Drizzle schema generated successfully at ${outputPath}`);
79
- } else {
80
- out("✅ Drizzle schema generated successfully.");
81
- out(String(schemaContent));
82
- }
83
-
84
- out(`You can now run ${formatTerminalText("rebase db generate", {
85
- bold: true,
86
- backgroundColor: "blue",
87
- textColor: "black"
88
- })} to generate the SQL migration files.`);
89
-
90
- } catch (error) {
91
- outError(`Error generating schema: ${error instanceof Error ? (error.stack ?? error.message) : String(error)}`);
92
- }
93
- };
94
-
95
- const main = async () => {
96
- const collectionsFilePathArg = process.argv.find(arg => arg.startsWith("--collections="));
97
- const collectionsFilePath = collectionsFilePathArg ? collectionsFilePathArg.split("=")[1] : process.argv[2];
98
-
99
- const outputPathArg = process.argv.find(arg => arg.startsWith("--output="));
100
- const outputPath = outputPathArg ? outputPathArg.split("=")[1] : undefined;
101
-
102
- const watch = process.argv.includes("--watch");
103
-
104
- if (!collectionsFilePath) {
105
- out("Usage: ts-node generate-drizzle-schema.ts <path-to-collections-file> [--output <path-to-output-file>] [--watch]");
106
- return;
107
- }
108
-
109
- const resolvedPath = path.resolve(process.cwd(), collectionsFilePath);
110
- const resolvedOutputPath = outputPath ? path.resolve(process.cwd(), outputPath) : undefined;
111
-
112
- if (watch) {
113
- out(`Watching for changes in ${resolvedPath}...`);
114
- // Imported here rather than at module scope, and this is not a style
115
- // choice: chokidar is needed only by `--watch`, which is a
116
- // schema-authoring path that never runs inside the runtime image. A
117
- // top-level import puts it on the boot path of the published driver
118
- // bundle, and the image installs a hand-listed set of runtime
119
- // dependencies that does not include it — so the whole driver failed to
120
- // load with "Cannot find package 'chokidar'", and every self-hosted
121
- // container answered 500 with a stack trace about a file watcher.
122
- //
123
- // Same reasoning the image already applies to @ariga/atlas: an
124
- // authoring-only dependency does not belong on a boot path.
125
- const { default: chokidar } = await import("chokidar");
126
- const watcher = chokidar.watch(resolvedPath, {
127
- persistent: true,
128
- ignoreInitial: false
129
- });
130
-
131
- watcher.on("all", (event, filePath) => {
132
- out(`[${event}] ${filePath}. Regenerating schema...`);
133
- runGeneration(resolvedPath, resolvedOutputPath);
134
- });
135
- } else {
136
- runGeneration(resolvedPath, resolvedOutputPath);
137
- }
138
- };
139
-
140
- // This check ensures the script only runs when executed directly
141
- if (import.meta.url.endsWith(process.argv[1])) {
142
- main();
143
- }