@rebasepro/server-postgresql 0.5.0 → 0.6.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 (165) hide show
  1. package/dist/{server-postgresql/src/PostgresAdapter.d.ts → PostgresAdapter.d.ts} +1 -1
  2. package/dist/{server-postgresql/src/PostgresBackendDriver.d.ts → PostgresBackendDriver.d.ts} +2 -2
  3. package/dist/{server-postgresql/src/PostgresBootstrapper.d.ts → PostgresBootstrapper.d.ts} +11 -1
  4. package/dist/{server-postgresql/src/collections → collections}/PostgresCollectionRegistry.d.ts +4 -0
  5. package/dist/index.es.js +10168 -11145
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/index.umd.js +10735 -11429
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/{server-postgresql/src/services → services}/EntityPersistService.d.ts +0 -14
  10. package/dist/utils/pg-error-utils.d.ts +55 -0
  11. package/package.json +24 -21
  12. package/src/PostgresAdapter.ts +9 -10
  13. package/src/PostgresBackendDriver.ts +134 -121
  14. package/src/PostgresBootstrapper.ts +86 -13
  15. package/src/auth/ensure-tables.ts +28 -5
  16. package/src/auth/services.ts +28 -18
  17. package/src/cli.ts +99 -96
  18. package/src/collections/PostgresCollectionRegistry.ts +7 -0
  19. package/src/connection.ts +11 -6
  20. package/src/data-transformer.ts +16 -14
  21. package/src/databasePoolManager.ts +3 -2
  22. package/src/history/HistoryService.ts +3 -2
  23. package/src/history/ensure-history-table.ts +5 -4
  24. package/src/schema/auth-schema.ts +1 -2
  25. package/src/schema/doctor-cli.ts +2 -1
  26. package/src/schema/doctor.ts +40 -37
  27. package/src/schema/generate-drizzle-schema-logic.ts +56 -18
  28. package/src/schema/generate-drizzle-schema.ts +11 -11
  29. package/src/schema/introspect-db-inference.ts +25 -25
  30. package/src/schema/introspect-db-logic.ts +38 -38
  31. package/src/schema/introspect-db.ts +28 -27
  32. package/src/services/BranchService.ts +14 -0
  33. package/src/services/EntityFetchService.ts +28 -25
  34. package/src/services/EntityPersistService.ts +11 -141
  35. package/src/services/RelationService.ts +57 -37
  36. package/src/services/entity-helpers.ts +6 -2
  37. package/src/services/realtimeService.ts +45 -32
  38. package/src/utils/drizzle-conditions.ts +31 -15
  39. package/src/utils/pg-error-utils.ts +211 -0
  40. package/src/websocket.ts +15 -12
  41. package/test/auth-services.test.ts +36 -19
  42. package/test/batch-many-to-many-regression.test.ts +119 -39
  43. package/test/data-transformer-hardening.test.ts +67 -33
  44. package/test/data-transformer.test.ts +4 -2
  45. package/test/doctor.test.ts +10 -5
  46. package/test/drizzle-conditions.test.ts +59 -6
  47. package/test/generate-drizzle-schema.test.ts +65 -40
  48. package/test/introspect-db-generation.test.ts +179 -81
  49. package/test/introspect-db-utils.test.ts +92 -37
  50. package/test/mocks/chalk.cjs +7 -0
  51. package/test/pg-error-utils.test.ts +221 -0
  52. package/test/postgresDataDriver.test.ts +14 -5
  53. package/test/property-ordering.test.ts +126 -79
  54. package/test/realtimeService.test.ts +6 -2
  55. package/test/relation-pipeline-gaps.test.ts +84 -36
  56. package/test/relations.test.ts +247 -0
  57. package/test/unmapped-tables-safety.test.ts +14 -6
  58. package/test/websocket.test.ts +1 -1
  59. package/tsconfig.json +5 -0
  60. package/tsconfig.prod.json +3 -0
  61. package/vite.config.ts +5 -5
  62. package/dist/common/src/collections/CollectionRegistry.d.ts +0 -56
  63. package/dist/common/src/collections/default-collections.d.ts +0 -9
  64. package/dist/common/src/collections/index.d.ts +0 -2
  65. package/dist/common/src/data/buildRebaseData.d.ts +0 -14
  66. package/dist/common/src/data/query_builder.d.ts +0 -55
  67. package/dist/common/src/index.d.ts +0 -4
  68. package/dist/common/src/util/builders.d.ts +0 -57
  69. package/dist/common/src/util/callbacks.d.ts +0 -6
  70. package/dist/common/src/util/collections.d.ts +0 -11
  71. package/dist/common/src/util/common.d.ts +0 -2
  72. package/dist/common/src/util/conditions.d.ts +0 -26
  73. package/dist/common/src/util/entities.d.ts +0 -58
  74. package/dist/common/src/util/enums.d.ts +0 -3
  75. package/dist/common/src/util/index.d.ts +0 -16
  76. package/dist/common/src/util/navigation_from_path.d.ts +0 -34
  77. package/dist/common/src/util/navigation_utils.d.ts +0 -20
  78. package/dist/common/src/util/parent_references_from_path.d.ts +0 -6
  79. package/dist/common/src/util/paths.d.ts +0 -14
  80. package/dist/common/src/util/permissions.d.ts +0 -14
  81. package/dist/common/src/util/references.d.ts +0 -2
  82. package/dist/common/src/util/relations.d.ts +0 -22
  83. package/dist/common/src/util/resolutions.d.ts +0 -72
  84. package/dist/common/src/util/storage.d.ts +0 -24
  85. package/dist/types/src/controllers/analytics_controller.d.ts +0 -7
  86. package/dist/types/src/controllers/auth.d.ts +0 -104
  87. package/dist/types/src/controllers/client.d.ts +0 -168
  88. package/dist/types/src/controllers/collection_registry.d.ts +0 -46
  89. package/dist/types/src/controllers/customization_controller.d.ts +0 -60
  90. package/dist/types/src/controllers/data.d.ts +0 -207
  91. package/dist/types/src/controllers/data_driver.d.ts +0 -218
  92. package/dist/types/src/controllers/database_admin.d.ts +0 -11
  93. package/dist/types/src/controllers/dialogs_controller.d.ts +0 -36
  94. package/dist/types/src/controllers/effective_role.d.ts +0 -4
  95. package/dist/types/src/controllers/email.d.ts +0 -36
  96. package/dist/types/src/controllers/index.d.ts +0 -18
  97. package/dist/types/src/controllers/local_config_persistence.d.ts +0 -20
  98. package/dist/types/src/controllers/navigation.d.ts +0 -225
  99. package/dist/types/src/controllers/registry.d.ts +0 -63
  100. package/dist/types/src/controllers/side_dialogs_controller.d.ts +0 -67
  101. package/dist/types/src/controllers/side_entity_controller.d.ts +0 -97
  102. package/dist/types/src/controllers/snackbar.d.ts +0 -24
  103. package/dist/types/src/controllers/storage.d.ts +0 -171
  104. package/dist/types/src/index.d.ts +0 -4
  105. package/dist/types/src/rebase_context.d.ts +0 -122
  106. package/dist/types/src/types/auth_adapter.d.ts +0 -301
  107. package/dist/types/src/types/backend.d.ts +0 -571
  108. package/dist/types/src/types/backend_hooks.d.ts +0 -172
  109. package/dist/types/src/types/builders.d.ts +0 -15
  110. package/dist/types/src/types/chips.d.ts +0 -5
  111. package/dist/types/src/types/collections.d.ts +0 -961
  112. package/dist/types/src/types/component_ref.d.ts +0 -47
  113. package/dist/types/src/types/cron.d.ts +0 -102
  114. package/dist/types/src/types/data_source.d.ts +0 -64
  115. package/dist/types/src/types/database_adapter.d.ts +0 -94
  116. package/dist/types/src/types/entities.d.ts +0 -145
  117. package/dist/types/src/types/entity_actions.d.ts +0 -104
  118. package/dist/types/src/types/entity_callbacks.d.ts +0 -173
  119. package/dist/types/src/types/entity_link_builder.d.ts +0 -7
  120. package/dist/types/src/types/entity_overrides.d.ts +0 -10
  121. package/dist/types/src/types/entity_views.d.ts +0 -87
  122. package/dist/types/src/types/export_import.d.ts +0 -21
  123. package/dist/types/src/types/formex.d.ts +0 -40
  124. package/dist/types/src/types/index.d.ts +0 -28
  125. package/dist/types/src/types/locales.d.ts +0 -4
  126. package/dist/types/src/types/modify_collections.d.ts +0 -5
  127. package/dist/types/src/types/plugins.d.ts +0 -282
  128. package/dist/types/src/types/properties.d.ts +0 -1173
  129. package/dist/types/src/types/property_config.d.ts +0 -74
  130. package/dist/types/src/types/relations.d.ts +0 -336
  131. package/dist/types/src/types/slots.d.ts +0 -262
  132. package/dist/types/src/types/translations.d.ts +0 -900
  133. package/dist/types/src/types/user_management_delegate.d.ts +0 -86
  134. package/dist/types/src/types/websockets.d.ts +0 -78
  135. package/dist/types/src/users/index.d.ts +0 -1
  136. package/dist/types/src/users/user.d.ts +0 -50
  137. /package/dist/{server-postgresql/src/auth → auth}/ensure-tables.d.ts +0 -0
  138. /package/dist/{server-postgresql/src/auth → auth}/services.d.ts +0 -0
  139. /package/dist/{server-postgresql/src/cli.d.ts → cli.d.ts} +0 -0
  140. /package/dist/{server-postgresql/src/connection.d.ts → connection.d.ts} +0 -0
  141. /package/dist/{server-postgresql/src/data-transformer.d.ts → data-transformer.d.ts} +0 -0
  142. /package/dist/{server-postgresql/src/databasePoolManager.d.ts → databasePoolManager.d.ts} +0 -0
  143. /package/dist/{server-postgresql/src/history → history}/HistoryService.d.ts +0 -0
  144. /package/dist/{server-postgresql/src/history → history}/ensure-history-table.d.ts +0 -0
  145. /package/dist/{server-postgresql/src/index.d.ts → index.d.ts} +0 -0
  146. /package/dist/{server-postgresql/src/interfaces.d.ts → interfaces.d.ts} +0 -0
  147. /package/dist/{server-postgresql/src/schema → schema}/auth-schema.d.ts +0 -0
  148. /package/dist/{server-postgresql/src/schema → schema}/doctor-cli.d.ts +0 -0
  149. /package/dist/{server-postgresql/src/schema → schema}/doctor.d.ts +0 -0
  150. /package/dist/{server-postgresql/src/schema → schema}/generate-drizzle-schema-logic.d.ts +0 -0
  151. /package/dist/{server-postgresql/src/schema → schema}/generate-drizzle-schema.d.ts +0 -0
  152. /package/dist/{server-postgresql/src/schema → schema}/introspect-db-inference.d.ts +0 -0
  153. /package/dist/{server-postgresql/src/schema → schema}/introspect-db-logic.d.ts +0 -0
  154. /package/dist/{server-postgresql/src/schema → schema}/introspect-db.d.ts +0 -0
  155. /package/dist/{server-postgresql/src/schema → schema}/test-schema.d.ts +0 -0
  156. /package/dist/{server-postgresql/src/services → services}/BranchService.d.ts +0 -0
  157. /package/dist/{server-postgresql/src/services → services}/EntityFetchService.d.ts +0 -0
  158. /package/dist/{server-postgresql/src/services → services}/RelationService.d.ts +0 -0
  159. /package/dist/{server-postgresql/src/services → services}/entity-helpers.d.ts +0 -0
  160. /package/dist/{server-postgresql/src/services → services}/entityService.d.ts +0 -0
  161. /package/dist/{server-postgresql/src/services → services}/index.d.ts +0 -0
  162. /package/dist/{server-postgresql/src/services → services}/realtimeService.d.ts +0 -0
  163. /package/dist/{server-postgresql/src/types.d.ts → types.d.ts} +0 -0
  164. /package/dist/{server-postgresql/src/utils → utils}/drizzle-conditions.d.ts +0 -0
  165. /package/dist/{server-postgresql/src/websocket.d.ts → websocket.d.ts} +0 -0
@@ -37,18 +37,4 @@ export declare class EntityPersistService {
37
37
  * Translate raw PostgreSQL / Drizzle errors into user-friendly messages.
38
38
  */
39
39
  private toUserFriendlyError;
40
- /**
41
- * Walk the error cause chain and return the deepest meaningful message.
42
- */
43
- private extractCauseMessage;
44
- /**
45
- * Strip the raw SQL query from a Drizzle "Failed query: ..." message,
46
- * keeping only the error description.
47
- */
48
- private stripSqlFromMessage;
49
- /**
50
- * Extract the underlying PostgreSQL error from a Drizzle wrapper.
51
- * Drizzle wraps PG errors in a `cause` property.
52
- */
53
- private extractPgError;
54
40
  }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Shared PostgreSQL error extraction and user-friendly message formatting.
3
+ *
4
+ * Drizzle wraps native PG errors in a `.cause` chain. These utilities
5
+ * unwrap that chain to get the real PostgreSQL error (identified by a
6
+ * 5-character alphanumeric `code` such as `42P01`) and translate it into
7
+ * a message that is safe and helpful to show to end-users.
8
+ */
9
+ /** Shape of PostgreSQL errors with diagnostic metadata. */
10
+ export interface PostgresError extends Error {
11
+ code?: string;
12
+ detail?: string;
13
+ hint?: string;
14
+ constraint?: string;
15
+ column?: string;
16
+ table?: string;
17
+ dataType?: string;
18
+ cause?: unknown;
19
+ }
20
+ /**
21
+ * Extract the underlying PostgreSQL error from a Drizzle wrapper.
22
+ * Drizzle wraps PG errors in a `cause` property — this function
23
+ * recursively walks the chain until it finds an object with a PG
24
+ * error code (5-char alphanumeric, e.g. `42P01`).
25
+ */
26
+ export declare function extractPgError(error: unknown): PostgresError | null;
27
+ /**
28
+ * Walk the error cause chain and return the deepest meaningful message.
29
+ */
30
+ export declare function extractCauseMessage(error: unknown): string | null;
31
+ /**
32
+ * Translate a raw PostgreSQL error into a user-friendly message.
33
+ *
34
+ * @param pgError - The extracted PostgreSQL error (from {@link extractPgError})
35
+ * @param context - A human-readable context string (e.g. collection slug or path)
36
+ * @returns An object with a `message` safe for the client and the PG `code`.
37
+ */
38
+ export declare function pgErrorToFriendlyMessage(pgError: PostgresError, context: string): {
39
+ message: string;
40
+ code: string;
41
+ };
42
+ /**
43
+ * Sanitize any error into a message safe and helpful for the client.
44
+ *
45
+ * Extracts the PG error from the Drizzle cause chain when possible;
46
+ * falls back to a generic message that doesn't leak SQL.
47
+ *
48
+ * @param error - The raw caught error
49
+ * @param context - A human-readable context string (e.g. collection path)
50
+ * @returns An object with `message` (user-friendly) and optional `code` (PG code).
51
+ */
52
+ export declare function sanitizeErrorForClient(error: unknown, context: string): {
53
+ message: string;
54
+ code?: string;
55
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rebasepro/server-postgresql",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.6.0",
5
5
  "description": "PostgreSQL data source backend implementation for Rebase with Drizzle ORM",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/rebaseco"
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "main": "./dist/index.umd.js",
17
17
  "module": "./dist/index.es.js",
18
- "types": "./dist/server-postgresql/src/index.d.ts",
18
+ "types": "./dist/index.d.ts",
19
19
  "source": "src/index.ts",
20
20
  "engines": {
21
21
  "node": ">=20"
@@ -43,15 +43,18 @@
43
43
  "node"
44
44
  ],
45
45
  "moduleNameMapper": {
46
+ "^chalk$": "<rootDir>/test/mocks/chalk.cjs",
46
47
  "^@rebasepro/client$": "<rootDir>/../client/src/index.ts",
47
48
  "^@rebasepro/common$": "<rootDir>/../common/src/index.ts",
48
49
  "^@rebasepro/types$": "<rootDir>/../types/src/index.ts",
49
- "^@rebasepro/utils$": "<rootDir>/../utils/src/index.ts"
50
+ "^@rebasepro/utils$": "<rootDir>/../utils/src/index.ts",
51
+ "^@rebasepro/server-core$": "<rootDir>/../server-core/src/index.ts",
52
+ "^(\\.{1,2}/.*)\\.js$": "$1"
50
53
  }
51
54
  },
52
55
  "exports": {
53
56
  ".": {
54
- "types": "./dist/server-postgresql/src/index.d.ts",
57
+ "types": "./dist/index.d.ts",
55
58
  "development": "./dist/index.es.js",
56
59
  "import": "./dist/index.es.js",
57
60
  "require": "./dist/index.umd.js"
@@ -60,31 +63,31 @@
60
63
  },
61
64
  "dependencies": {
62
65
  "arg": "^5.0.2",
63
- "chalk": "^4.1.2",
66
+ "chalk": "^5.6.2",
64
67
  "chokidar": "5.0.0",
65
- "dotenv": "^16.6.1",
66
- "drizzle-orm": "^0.44.7",
68
+ "dotenv": "^17.4.2",
69
+ "drizzle-orm": "^0.45.2",
67
70
  "execa": "^9.6.1",
68
- "hono": "^4.12.21",
71
+ "hono": "^4.12.25",
69
72
  "pg": "^8.21.0",
70
- "ws": "^8.20.1",
71
- "@rebasepro/sdk-generator": "0.5.0",
72
- "@rebasepro/server-core": "0.5.0",
73
- "@rebasepro/types": "0.5.0",
74
- "@rebasepro/utils": "0.5.0",
75
- "@rebasepro/common": "0.5.0"
73
+ "ws": "^8.21.0",
74
+ "@rebasepro/common": "0.6.0",
75
+ "@rebasepro/types": "0.6.0",
76
+ "@rebasepro/server-core": "0.6.0",
77
+ "@rebasepro/sdk-generator": "0.6.0",
78
+ "@rebasepro/utils": "0.6.0"
76
79
  },
77
80
  "devDependencies": {
78
- "@types/jest": "^29.5.14",
79
- "@types/node": "^20.19.41",
81
+ "@types/jest": "^30.0.0",
82
+ "@types/node": "^25.9.3",
80
83
  "@types/pg": "^8.20.0",
81
84
  "@types/ws": "^8.18.1",
82
- "@vitejs/plugin-react": "^4.7.0",
85
+ "@vitejs/plugin-react": "^6.0.2",
83
86
  "drizzle-kit": "^0.31.10",
84
- "jest": "^29.7.0",
85
- "ts-jest": "^29.4.10",
86
- "typescript": "^5.9.3",
87
- "vite": "^5.4.21"
87
+ "jest": "^30.4.2",
88
+ "ts-jest": "^29.4.11",
89
+ "typescript": "^6.0.3",
90
+ "vite": "^8.0.16"
88
91
  },
89
92
  "gitHead": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
90
93
  "publishConfig": {
@@ -1,55 +1,54 @@
1
1
  import { DatabaseAdapter, InitializedDriver, RealtimeProvider, DataDriver, DatabaseAdmin, BootstrappedAuth } from "@rebasepro/types";
2
2
  import { createPostgresBootstrapper } from "./PostgresBootstrapper";
3
- // @ts-ignore
4
- import type { PostgresDriverConfig } from "@rebasepro/server-core";
3
+ import type { PostgresDriverConfig } from "./PostgresBootstrapper";
5
4
 
6
5
  /**
7
6
  * Creates a Postgres database adapter for Rebase.
8
7
  */
9
8
  export function createPostgresAdapter(pgConfig: PostgresDriverConfig): DatabaseAdapter {
10
9
  const bootstrapper = createPostgresBootstrapper(pgConfig);
11
-
10
+
12
11
  return {
13
12
  type: bootstrapper.type,
14
-
13
+
15
14
  async initializeDriver(config) {
16
15
  return bootstrapper.initializeDriver(config);
17
16
  },
18
-
17
+
19
18
  async initializeRealtime(driverResult) {
20
19
  if (bootstrapper.initializeRealtime) {
21
20
  return bootstrapper.initializeRealtime({}, driverResult);
22
21
  }
23
22
  return undefined;
24
23
  },
25
-
24
+
26
25
  async initializeAuth(config, driverResult) {
27
26
  if (bootstrapper.initializeAuth) {
28
27
  return bootstrapper.initializeAuth(config, driverResult);
29
28
  }
30
29
  return undefined;
31
30
  },
32
-
31
+
33
32
  async initializeHistory(config, driverResult) {
34
33
  if (bootstrapper.initializeHistory) {
35
34
  return bootstrapper.initializeHistory(config, driverResult);
36
35
  }
37
36
  return undefined;
38
37
  },
39
-
38
+
40
39
  initializeWebsockets(server, realtimeService, driver, config) {
41
40
  if (bootstrapper.initializeWebsockets) {
42
41
  return bootstrapper.initializeWebsockets(server, realtimeService, driver, config);
43
42
  }
44
43
  },
45
-
44
+
46
45
  getAdmin(driverResult) {
47
46
  if (bootstrapper.getAdmin) {
48
47
  return bootstrapper.getAdmin(driverResult);
49
48
  }
50
49
  return undefined;
51
50
  },
52
-
51
+
53
52
  mountRoutes(app, basePath, driverResult) {
54
53
  if (bootstrapper.mountRoutes) {
55
54
  bootstrapper.mountRoutes(app, basePath, driverResult);