@otwdesign/plugin-db 1.0.2 → 1.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.
Files changed (2) hide show
  1. package/package.json +5 -3
  2. package/src/index.ts +14 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otwdesign/plugin-db",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "OTW DB in the OTW CMS admin: browse, query and edit the site's database, and any other, the way TablePlus does.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "OTW SRL",
@@ -35,10 +35,12 @@
35
35
  "node": ">=22.18"
36
36
  },
37
37
  "dependencies": {
38
+ "@types/pg": "^8.23.1",
39
+ "@types/pg-cursor": "^2.7.2",
38
40
  "pg": "^8.23.1",
39
41
  "pg-cursor": "^2.22.1",
40
- "@otwdesign/db-core": "1.0.2",
41
- "@otwdesign/db-ui": "1.0.2"
42
+ "@otwdesign/db-core": "1.1.0",
43
+ "@otwdesign/db-ui": "1.1.0"
42
44
  },
43
45
  "peerDependencies": {
44
46
  "@otwdesign/sdk": "^1.1.0",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { definePlugin, type ApiContext, type PluginContext } from '@otwdesign/sdk'
2
- import type { ConnectionConfig, DbAdmin, PGliteLike } from '@otwdesign/db-core'
2
+ import type { ConnectionConfig, DbAdmin, PGliteLike, PostgresOptions } from '@otwdesign/db-core'
3
3
  import { ROUTES } from '@otwdesign/db-core/routes'
4
4
 
5
5
  declare module '@otwdesign/sdk' {
@@ -36,6 +36,16 @@ export function siteConnection(env: NodeJS.ProcessEnv = process.env): Connection
36
36
  }
37
37
  }
38
38
 
39
+ /**
40
+ * pg and pg-cursor from the plugin's own dependencies, imported on the first PostgreSQL
41
+ * connection. The site's bundler resolves these imports from the plugin. db-core's own imports are
42
+ * resolved from where the site's bundle runs, which under pnpm has neither: pnpm keeps them beside
43
+ * the plugin, not in the site's root.
44
+ */
45
+ const postgres: PostgresOptions = {
46
+ modules: () => Promise.all([import('pg'), import('pg-cursor')]),
47
+ }
48
+
39
49
  /**
40
50
  * Registers the tool's API under /api/p/db from its static route table. The tool itself (its
41
51
  * engine, drivers and browser app) loads on the first request to it, so a site that never opens
@@ -57,10 +67,10 @@ export function setup(cms: PluginContext): void {
57
67
  return user && cms.auth.can(user, 'db.manage') ? { id: user.email } : null
58
68
  },
59
69
  driver(connection) {
60
- if (connection.name !== SITE) return core.openDriver(connection)
70
+ if (connection.name !== SITE) return core.openDriver(connection, { postgres })
61
71
  return site.warning
62
72
  ? core.pgliteDriver((cms.db as unknown as { $client: PGliteLike }).$client)
63
- : core.postgresDriver(connection.url)
73
+ : core.postgresDriver(connection.url, postgres)
64
74
  },
65
75
  signInUrl: '/admin',
66
76
  })
@@ -79,7 +89,7 @@ export function setup(cms: PluginContext): void {
79
89
 
80
90
  export default definePlugin({
81
91
  id: 'db',
82
- version: '1.0.2',
92
+ version: '1.1.0',
83
93
  name: 'Database',
84
94
  icon: ICON,
85
95
  description: