@owlmeans/postgres 0.1.18-rc.9 → 0.1.18

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 (48) hide show
  1. package/README.md +7 -6
  2. package/agent-meta/manifest.json +3 -3
  3. package/agent-meta/skills/postgres/SKILL.md +67 -16
  4. package/build/bootstrap.d.ts.map +1 -1
  5. package/build/bootstrap.js +12 -7
  6. package/build/bootstrap.js.map +1 -1
  7. package/build/index.d.ts +2 -0
  8. package/build/index.d.ts.map +1 -1
  9. package/build/index.js.map +1 -1
  10. package/build/service.d.ts +1 -5
  11. package/build/service.d.ts.map +1 -1
  12. package/build/service.js +23 -41
  13. package/build/service.js.map +1 -1
  14. package/build/types.local.d.ts +5 -0
  15. package/build/types.local.d.ts.map +1 -0
  16. package/build/types.local.js +2 -0
  17. package/build/types.local.js.map +1 -0
  18. package/build/utils/config/types.d.ts +30 -0
  19. package/build/utils/config/types.d.ts.map +1 -0
  20. package/build/utils/config/types.js +2 -0
  21. package/build/utils/config/types.js.map +1 -0
  22. package/build/utils/config.d.ts +4 -24
  23. package/build/utils/config.d.ts.map +1 -1
  24. package/build/utils/config.js +74 -87
  25. package/build/utils/config.js.map +1 -1
  26. package/build/utils/connection/types.d.ts +17 -0
  27. package/build/utils/connection/types.d.ts.map +1 -0
  28. package/build/utils/connection/types.js +2 -0
  29. package/build/utils/connection/types.js.map +1 -0
  30. package/build/utils/connection.d.ts +2 -13
  31. package/build/utils/connection.d.ts.map +1 -1
  32. package/build/utils/connection.js +33 -37
  33. package/build/utils/connection.js.map +1 -1
  34. package/package.json +14 -13
  35. package/src/bootstrap.ts +13 -11
  36. package/src/index.ts +2 -0
  37. package/src/service.ts +28 -58
  38. package/src/types.local.ts +5 -0
  39. package/src/utils/config/types.ts +28 -0
  40. package/src/utils/config.ts +80 -89
  41. package/src/utils/connection/types.ts +17 -0
  42. package/src/utils/connection.ts +36 -36
  43. package/tests/context.ts +3 -3
  44. package/tests/criteria.spec.ts +107 -0
  45. package/tests/crud.spec.ts +68 -18
  46. package/tests/custom-sql.spec.ts +3 -2
  47. package/tests/migration.spec.ts +34 -3
  48. package/tests/sync.spec.ts +91 -1
package/README.md CHANGED
@@ -14,7 +14,7 @@ provisioning, and an opt-in least-privilege bootstrap path.
14
14
  ## Installation
15
15
 
16
16
  ```bash
17
- bun add @owlmeans/postgres @owlmeans/postgres-resource
17
+ bun add @owlmeans/postgres@^0.1.18 @owlmeans/postgres-resource@^0.1.18
18
18
  ```
19
19
 
20
20
  ## Usage
@@ -46,8 +46,8 @@ A whole connection string works too, and wins over `host`/`user`/`secret`:
46
46
  cfg.dbs = [{ service: 'postgres', alias: 'postgres', schema: 'app', meta: { url: process.env.DATABASE_URL } }]
47
47
  ```
48
48
 
49
- `schema` is the Postgres **schema**, not the database — `dbName()` suffixes it per Entity/User layer,
50
- so per-tenant namespaces stay cheap. The database comes from `meta.database` and is never suffixed.
49
+ `schema` is the Postgres **schema**, not the database — `dbName()` resolves it as
50
+ `config.schema ?? config.alias ?? service.alias`. The database comes from `meta.database`.
51
51
 
52
52
  At `init()` the service opens a pool, runs a `SELECT 1` readiness probe (30 attempts, 2s apart by
53
53
  default — a Postgres sidecar routinely accepts TCP before it accepts queries), issues
@@ -102,8 +102,9 @@ Extends `PostgresDbService` from `@owlmeans/postgres-resource`:
102
102
 
103
103
  ### Helpers
104
104
 
105
- - `parseUrl(url)` / `prepareConfig(config, overrides?)` / `poolDatabase(pool)`
106
- - `probe(pool, meta, location)` / `ensureSchema(pool, schema)`
105
+ - `pgConfigHelper` (`PgConfigHelper`) — `.parseUrl(url)` / `.prepareConfig(config, overrides?)` /
106
+ `.poolDatabase(pool)`
107
+ - `makePgConnectionHelper(pool)` (`PgConnectionHelper`) — `.probe(meta, location)` / `.ensureSchema(schema)`
107
108
  - `bootstrapDb(...)` — the bootstrap implementation, usable without a context
108
109
  - `drainMiddleware(alias?)`
109
110
 
@@ -129,7 +130,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
129
130
  your project's skill store (`.agents/skills/`):
130
131
 
131
132
  ```sh
132
- npx @owlmeans/agent-skills
133
+ npx @owlmeans/agent-skills@^0.1.18
133
134
  ```
134
135
 
135
136
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
- "schemaVersion": 2,
2
+ "schemaVersion": 3,
3
3
  "package": "@owlmeans/postgres",
4
- "version": "0.1.18-rc.8",
5
- "generatedAt": "2026-08-24T21:14:00.143Z",
4
+ "version": "0.1.18",
5
+ "generatedAt": "2026-10-28T00:31:34.772Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: postgres
3
- description: How to use @owlmeans/postgres — PostgreSQL connection service (makePostgresDbService / appendPostgres) registered on a server context, plus the least-privilege bootstrap admin path. Auto-invoked when wiring PostgreSQL into a server app.
3
+ description: How to use @owlmeans/postgres — PostgreSQL connection service (makePostgresDbService / appendPostgres) registered on a server context, its health checks, plus the least-privilege bootstrap admin path. Auto-invoked when wiring PostgreSQL into a server app.
4
4
  user-invocable: false
5
5
  ---
6
6
  <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/postgres
9
9
 
10
10
  **Layer:** Infra
11
- **Install:** `"@owlmeans/postgres": "^0.1.18-rc.8"` in `dependencies`
11
+ **Install:** `"@owlmeans/postgres": "^0.1.18"` in `dependencies`
12
12
 
13
13
  Pooled `pg` connections for a server context, plus the admin path that provisions the role, database
14
14
  and schema an app connects with. All DDL for application tables belongs to [[postgres-resource]] —
@@ -21,7 +21,9 @@ this package only creates the schema those tables live in.
21
21
  | `makePostgresDbService(alias?)` | The connection service. `alias` defaults to `DEFAULT_ALIAS` (`'postgres'`). |
22
22
  | `appendPostgres(context, alias?)` | Registers the service **and** its drain middleware. Use this, not a bare `registerService`. |
23
23
  | `PostgresService` | `PostgresDbService` + `bootstrap(configAlias, opts)`. |
24
- | `BootstrapOptions`, `BootstrapReport`, `bootstrapDb` | The admin path; `bootstrapDb` is usable without a context. |
24
+ | `BootstrapOptions`, `BootstrapReport`, `bootstrapDb` | The admin path. `bootstrapDb(service, configAlias, opts)` is what `service.bootstrap(configAlias, opts)` calls — both read the config through a **context-bound** service, so neither runs outside a context. |
25
+ | `pingDb(context, alias?, configAlias?)` / `checkDbHealth(...)` | Health checks through the registered service; `DbHealth` = `{ ok, summary, error? }`. |
26
+ | `getLastDbHealth(alias?, configAlias?)` / `formatDbError(error)` | The cached verdict, and the cause-chain error formatter. |
25
27
  | `drainMiddleware(alias?)` | Drains work deferred until every resource has initialized. |
26
28
  | `parseUrl`, `prepareConfig`, `poolDatabase`, `probe`, `ensureSchema` | Config and connection helpers. |
27
29
  | `DEFAULT_ALIAS`, `DEF_ADMIN_ALIAS`, `DEF_MAINTENANCE_DB`, `DEF_PORT`, `DEF_POOL_SIZE`, `DEF_RETRIES`, `DEF_RETRY_DELAY`, `TERMINAL_CONNECT_CODES` | Constants. |
@@ -50,20 +52,36 @@ cfg.dbs = [{
50
52
  for a `DATABASE_URL` env var. Because a leading `/` is auto-read, moving to file-mounted secrets
51
53
  later is a config change, not a code change.
52
54
 
53
- **`schema` is the SCHEMA, not the database.** `dbName()` suffixes it per Entity/User layer, so
54
- per-tenant namespaces cost a `CREATE SCHEMA` rather than a `CREATE DATABASE`. The database comes
55
- from `meta.database` and is never suffixed.
55
+ **`schema` is the SCHEMA, not the database.** The service's `name(alias?)` returns it as given
56
+ (`config.schema ?? config.alias ?? service.alias`), so a separate namespace costs a `CREATE SCHEMA`
57
+ inside a shared database rather than a `CREATE DATABASE`. The database comes from `meta.database`.
56
58
 
57
59
  Other `meta` keys: `autoSync` (see [[postgres-resource]]), `ssl`, `max`, `idleTimeoutMillis`,
58
60
  `connectionTimeoutMillis`, `statementTimeoutMillis`, `retries`, `retryDelayMillis`.
59
61
 
60
62
  ## What `init()` does
61
63
 
62
- Opens a `pg.Pool` → `SELECT 1` readiness probe (30 attempts, 2s apart) → `CREATE SCHEMA IF NOT
63
- EXISTS` → `SIGTERM` handler that drains the pool. Do **not** hand-roll the retry loop around it: a
64
- Postgres sidecar routinely accepts TCP before it accepts queries, which is precisely what the probe
65
- is for. Credential, missing-database and permission failures (`TERMINAL_CONNECT_CODES`) fail
66
- immediately instead of burning the full retry budget on an error that will never clear.
64
+ Opens a `pg.Pool` → attaches the pool's `error` handler → `SELECT 1` readiness probe
65
+ (`DEF_RETRIES` 30 attempts, `DEF_RETRY_DELAY` 2s apart, both overridable through
66
+ `meta.retries`/`meta.retryDelayMillis`) → `SIGTERM` handler that drains the pool → registers the
67
+ client → `CREATE SCHEMA IF NOT EXISTS`.
68
+
69
+ Do **not** hand-roll the retry loop around it: a Postgres sidecar routinely accepts TCP before it
70
+ accepts queries, which is precisely what the probe is for. Credential, missing-database and
71
+ permission failures (`TERMINAL_CONNECT_CODES`) fail immediately instead of burning the full retry
72
+ budget on an error that will never clear. A probe that gives up ends the pool before raising, so a
73
+ failed boot leaves no sockets behind.
74
+
75
+ **The schema is created only when the config entry names one.** `config.schema` absent means no
76
+ `CREATE SCHEMA` at all — an entry that identifies its database through `meta.database` or
77
+ `meta.url` and omits `schema` gets none, deliberately: resources create the schema they need
78
+ anyway, and inventing one from the service alias would leave an empty `postgres` schema behind on
79
+ every boot of the admin connection.
80
+
81
+ **The pool's `error` handler is not optional.** `node-postgres` emits `error` on *idle* clients
82
+ whenever the server closes a connection — routine behind a load balancer — and an unhandled
83
+ `error` on an EventEmitter terminates the process. The service attaches one that logs; a pool you
84
+ open yourself needs the same.
67
85
 
68
86
  Keep the pool small. Postgres caps connections cluster-wide (`max_connections`, 100 by default), so
69
87
  an oversized per-process pool starves every other client of the same server — the opposite of the
@@ -73,7 +91,8 @@ Mongo driver's tuning instinct.
73
91
 
74
92
  `db(alias?)` → `{ drizzle, pool, schema, database }` · `client(alias?)` / `clients` ·
75
93
  `qualify(resourceAlias, configAlias?)` · `query(text, params?, configAlias?)` ·
76
- `transaction(fn, configAlias?)` · `lock`/`unlock` (AES via `config.encryptionKey`) ·
94
+ `transaction(fn, configAlias?)` · `lock`/`unlock` (field encryption through
95
+ `makeKeyPairModel(config.encryptionKey)` from `@owlmeans/basic-keys`) ·
77
96
  `defer(configAlias, task)` / `drain(configAlias?)`.
78
97
 
79
98
  `defer` exists for work that can't run during one resource's `init()` because it points at another
@@ -81,6 +100,35 @@ resource that hasn't initialized yet — foreign keys, above all. Queue it; the
81
100
  `appendPostgres` registers drains it once the context is up. Do not reorder resource registrations
82
101
  to work around this.
83
102
 
103
+ ## Health
104
+
105
+ Do not hand-roll a health check, and never open a connection of your own for one: `pingDb` and
106
+ `checkDbHealth` resolve the service by alias exactly as any other consumer does, so a probe can
107
+ never report on a connection the app does not use. Both return `{ ok, summary, error? }` and never
108
+ throw.
109
+
110
+ ```typescript
111
+ const health = await checkDbHealth(context) // boot gate, after init()
112
+ if (!health.ok) throw new Error(health.error ?? health.summary)
113
+
114
+ const live = await pingDb(ctx) // request time, in a health handler
115
+ const boot = getLastDbHealth()
116
+ ```
117
+
118
+ `checkDbHealth` awaits `service.ready()`, runs `SELECT 1` and caches its verdict for
119
+ `getLastDbHealth`; `pingDb` is the bare `SELECT 1` and caches nothing. Neither inspects the schema
120
+ — structure is reconciled by the resources during `init()`, so a process that reached the check has
121
+ the tables it was built with and there is nothing left to assert beyond "the connection works".
122
+
123
+ The context is a parameter, not a module import: a handler is handed the context that actually
124
+ served the request (possibly an entity-scoped derivative), and passing it keeps these functions out
125
+ of the boot import cycle. Errors go through `formatDbError`, which walks the `cause` chain and
126
+ surfaces the `severity`/`code`/`detail`/`hint` a bare `.message` hides — that is where the real
127
+ FATAL/permission reason lives.
128
+
129
+ Pair it with the bind-first boot in [[server-app]]: `checkDbHealth` is the boot gate, and a failure
130
+ becomes `setBootPhase('failed', …)` on a port that is already bound.
131
+
84
132
  ## Bootstrap — the admin path
85
133
 
86
134
  Superuser credentials belong to a **separate config alias**. The application's own entry connects as
@@ -94,10 +142,13 @@ await context.service<PostgresService>('postgres').bootstrap('pg-admin', {
94
142
 
95
143
  Idempotent by design — every OwlMeans deployment calls it on each start and each rebuild. It probes
96
144
  `pg_roles` / `pg_database` before creating, rotates the password of an existing role (the caller
97
- generated the password it just passed in, so the role has to accept it), and with `leastPrivilege`
98
- applies `REVOKE CONNECT … FROM PUBLIC`, `REVOKE CREATE ON SCHEMA public FROM PUBLIC`,
99
- `GRANT CONNECT … TO <role>`, `ALTER ROLE … SET search_path`. The returned `BootstrapReport` says
100
- what actually changed. Identifiers are validated and quoted; the password is the only literal.
145
+ generated the password it just passed in, so the role has to accept it). The two grant branches are
146
+ independent: `leastPrivilege` applies `REVOKE CONNECT … FROM PUBLIC`,
147
+ `REVOKE CREATE ON SCHEMA public FROM PUBLIC` and `GRANT CONNECT … TO <role>`, while `schema`
148
+ applies `CREATE SCHEMA … AUTHORIZATION <role>`, `GRANT ALL ON SCHEMA … TO <role>` and
149
+ `ALTER ROLE … SET search_path`. **`search_path` comes from `schema`** — a call with
150
+ `leastPrivilege` and no `schema` sets none. The returned `BootstrapReport` says what actually
151
+ changed. Identifiers are validated and quoted; the password is the only literal.
101
152
 
102
153
  **This replaces hand-written bootstrap SQL.** If you find `CREATE ROLE` / `CREATE DATABASE` /
103
154
  `GRANT` strings in a deployment script, a provisioner, or a `DEPLOYMENT.md`, they are a duplicate of
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AASpF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,YACb,eAAe,eAAe,MAAM,QAAQ,gBAAgB,KACpE,OAAO,CAAC,eAAe,CAwFzB,CAAA"}
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAWpF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,YACb,eAAe,eAAe,MAAM,QAAQ,gBAAgB,KACpE,OAAO,CAAC,eAAe,CAyFzB,CAAA"}
@@ -1,6 +1,8 @@
1
- import { assertSqlIdentifier, PostgresBootstrapError, quoteIdent, quoteLiteral } from '@owlmeans/postgres-resource';
1
+ import { pgNameHelper, PostgresBootstrapError } from '@owlmeans/postgres-resource';
2
+ import { logger } from '@owlmeans/log';
2
3
  import { Pool } from 'pg';
3
- import { prepareConfig } from './utils/config.js';
4
+ import { pgConfigHelper } from './utils/config.js';
5
+ const log = logger('postgres');
4
6
  const exists = async (client, text, value) => {
5
7
  const result = await client.query(text, [value]);
6
8
  return result.rowCount != null && result.rowCount > 0;
@@ -19,6 +21,7 @@ const exists = async (client, text, value) => {
19
21
  * @throws {PostgresBootstrapError}
20
22
  */
21
23
  export const bootstrapDb = async (service, configAlias, opts) => {
24
+ const { assertSqlIdentifier, quoteIdent, quoteLiteral } = pgNameHelper;
22
25
  const role = assertSqlIdentifier(opts.role, 'role');
23
26
  const database = assertSqlIdentifier(opts.database ?? opts.role, 'database');
24
27
  const schema = opts.schema != null ? assertSqlIdentifier(opts.schema, 'schema') : null;
@@ -66,7 +69,7 @@ export const bootstrapDb = async (service, configAlias, opts) => {
66
69
  finally {
67
70
  client.release();
68
71
  }
69
- const target = new Pool(prepareConfig(config, { database, max: 1 }));
72
+ const target = new Pool(pgConfigHelper.prepareConfig(config, { database, max: 1 }));
70
73
  try {
71
74
  if (schema != null) {
72
75
  /**
@@ -92,10 +95,12 @@ export const bootstrapDb = async (service, configAlias, opts) => {
92
95
  finally {
93
96
  await target.end().catch(() => undefined);
94
97
  }
95
- console.log(`@owlmeans/postgres: bootstrap ${role}@${database} —`
96
- + ` role ${report.roleCreated ? 'created' : report.passwordRotated ? 'rotated' : 'present'},`
97
- + ` database ${report.databaseCreated ? 'created' : 'present'}`
98
- + (schema != null ? `, schema ${schema} ready` : ''));
98
+ log.info('Postgres bootstrap applied', {
99
+ role, database,
100
+ roleState: report.roleCreated ? 'created' : report.passwordRotated ? 'rotated' : 'present',
101
+ databaseState: report.databaseCreated ? 'created' : 'present',
102
+ ...(schema != null ? { schema } : {}),
103
+ }, { event: 'db.bootstrap' });
99
104
  return report;
100
105
  };
101
106
  const wrap = (error, subject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAAE,sBAAsB,EAAE,UAAU,EAAE,YAAY,EACtE,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAIzB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,MAAM,MAAM,GAAG,KAAK,EAAE,MAAkB,EAAE,IAAY,EAAE,KAAa,EAAoB,EAAE;IACzF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEhD,OAAO,MAAM,CAAC,QAAQ,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAA;AACvD,CAAC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,OAAwB,EAAE,WAAmB,EAAE,IAAsB,EAC3C,EAAE;IAC5B,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACnD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IAC5E,MAAM,MAAM,GAAG,IAA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CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,IAAI,QAAQ,EAAE,CAAC,CAAA;IAC1C,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAC3C,CAAC;IAED,GAAG,CAAC,IAAI,CAAC,4BAA4B,EAAE;QACrC,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAC1F,aAAa,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAC7D,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtC,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAA;IAE7B,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,OAAe,EAAS,EAAE;IACtD,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC,GAAG,OAAO,IAAK,KAAe,EAAE,OAAO,IAAI,KAAK,EAAE,CAAC,CAAA;IAC9F,OAAO,CAAC,KAAK,GAAG,KAAK,CAAA;IAErB,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
package/build/index.d.ts CHANGED
@@ -4,5 +4,7 @@ export * from './bootstrap.js';
4
4
  export * from './middleware.js';
5
5
  export * from './service.js';
6
6
  export * from './utils/config.js';
7
+ export type * from './utils/config/types.js';
7
8
  export * from './utils/connection.js';
9
+ export type * from './utils/connection/types.js';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,mBAAmB,yBAAyB,CAAA;AAC5C,cAAc,uBAAuB,CAAA;AACrC,mBAAmB,6BAA6B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AAEjC,cAAc,uBAAuB,CAAA"}
@@ -1,9 +1,5 @@
1
- import type { ServerConfig, ServerContext } from '@owlmeans/server-context';
2
1
  import type { PostgresService } from './types.js';
3
- type Config = ServerConfig;
4
- interface Context<C extends Config = Config> extends ServerContext<C> {
5
- }
2
+ import type { Config, Context } from './types.local.js';
6
3
  export declare const makePostgresDbService: (alias?: string) => PostgresService;
7
4
  export declare const appendPostgres: <C extends Config, T extends Context<C> = Context<C>>(context: T, alias?: string) => T;
8
- export {};
9
5
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAS3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,KAAK,MAAM,GAAG,YAAY,CAAA;AAC1B,UAAU,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;CAAI;AAEzE,eAAO,MAAM,qBAAqB,WAAW,MAAM,KAAmB,eA2PrE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,WACvE,CAAC,UAAS,MAAM,KACxB,CAOF,CAAA"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAKvD,eAAO,MAAM,qBAAqB,WAAW,MAAM,KAAmB,eAkOrE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,WACvE,CAAC,UAAS,MAAM,KACxB,CAOF,CAAA"}
package/build/service.js CHANGED
@@ -1,20 +1,25 @@
1
1
  import { makeKeyPairModel } from '@owlmeans/basic-keys';
2
- import { assertContext, Layer } from '@owlmeans/context';
3
- import { makeTx, pgErrorToResourceError, pgIdentifier, refOf, resolvePlaceholders } from '@owlmeans/postgres-resource';
2
+ import { assertContext } from '@owlmeans/context';
3
+ import { makeTx, pgErrorHelper, pgNameHelper, pgPlaceholdersOf } from '@owlmeans/postgres-resource';
4
+ import { logThrottle, logger } from '@owlmeans/log';
4
5
  import { createDbService } from '@owlmeans/resource';
5
6
  import { drizzle } from 'drizzle-orm/node-postgres';
6
7
  import { Pool } from 'pg';
7
8
  import { DEFAULT_ALIAS } from './consts.js';
8
9
  import { bootstrapDb } from './bootstrap.js';
9
10
  import { drainMiddleware } from './middleware.js';
10
- import { poolDatabase, prepareConfig } from './utils/config.js';
11
- import { ensureSchema, probe } from './utils/connection.js';
11
+ import { pgConfigHelper } from './utils/config.js';
12
+ import { makePgConnectionHelper } from './utils/connection.js';
13
+ const log = logger('postgres');
12
14
  export const makePostgresDbService = (alias = DEFAULT_ALIAS) => {
13
15
  const location = `postgres:${alias}`;
16
+ const { pgErrorToResourceError } = pgErrorHelper;
17
+ const { pgIdentifier } = pgNameHelper;
18
+ const { poolDatabase, prepareConfig } = pgConfigHelper;
14
19
  /**
15
20
  * Handles are cached per config alias rather than rebuilt per call: `db()` runs on every
16
21
  * single resource operation, and both the Drizzle binding and the schema name are fixed
17
- * for the lifetime of a service instance — a layer switch produces a *new* instance.
22
+ * for the lifetime of the service — one instance per alias, for the whole process.
18
23
  */
19
24
  const handles = new Map();
20
25
  const deferred = new Map();
@@ -28,9 +33,9 @@ export const makePostgresDbService = (alias = DEFAULT_ALIAS) => {
28
33
  drizzle: drizzle(pool),
29
34
  pool,
30
35
  /**
31
- * `name()` is the layer aware namespace — the Postgres SCHEMA here, where Mongo
32
- * reads the same value as a database name. It can outgrow 63 bytes once a layer
33
- * suffix is appended, which Postgres would truncate silently.
36
+ * `name()` is the configured namespace — the Postgres SCHEMA here, where Mongo
37
+ * reads the same value as a database name. `pgIdentifier` holds it inside the
38
+ * 63 byte limit Postgres would otherwise truncate silently.
34
39
  */
35
40
  schema: pgIdentifier(service.name(configAlias)),
36
41
  database: poolDatabase(pool)
@@ -45,32 +50,21 @@ export const makePostgresDbService = (alias = DEFAULT_ALIAS) => {
45
50
  if (service.clients[configAlias] != null) {
46
51
  return;
47
52
  }
48
- if (service.layers == null) {
49
- service.layers = [Layer.Global];
50
- }
51
- /**
52
- * Sensitivity *adds* a layer the service is willing to serve. The Mongo copy of this
53
- * block tests `includes` where it means `!includes`, so it only ever appends a layer
54
- * that is already there — a latent no-op, corrected here.
55
- */
56
- if (config.serviceSensitive === true && !service.layers.includes(Layer.Service)) {
57
- service.layers.push(Layer.Service);
58
- }
59
- if (config.entitySensitive === true && !service.layers.includes(Layer.Entity)) {
60
- service.layers.push(Layer.Entity);
61
- }
62
53
  const meta = (config.meta ?? {});
63
54
  const pool = new Pool(prepareConfig(config));
55
+ const connection = makePgConnectionHelper(pool);
64
56
  /**
65
57
  * Not optional: node-postgres emits `error` on *idle* clients when the server closes
66
58
  * a connection — a routine event behind a load balancer — and an unhandled `error`
67
59
  * on an EventEmitter terminates the process.
68
60
  */
69
61
  pool.on('error', error => {
70
- console.error(`${location}: idle client error — ${error.message}`);
62
+ if (logThrottle(`${location}:idle-error`)) {
63
+ log.warn('Postgres idle client error', { location, error });
64
+ }
71
65
  });
72
66
  try {
73
- await probe(pool, meta, location);
67
+ await connection.probe(meta, location);
74
68
  }
75
69
  catch (error) {
76
70
  await pool.end().catch(() => undefined);
@@ -88,7 +82,7 @@ export const makePostgresDbService = (alias = DEFAULT_ALIAS) => {
88
82
  * from the service alias would leave an empty `postgres` schema behind on every boot.
89
83
  */
90
84
  if (config.schema != null) {
91
- await ensureSchema(pool, pgIdentifier(service.name(configAlias)));
85
+ await connection.ensureSchema(pgIdentifier(service.name(configAlias)));
92
86
  }
93
87
  },
94
88
  /**
@@ -98,13 +92,13 @@ export const makePostgresDbService = (alias = DEFAULT_ALIAS) => {
98
92
  */
99
93
  qualify: resourceAlias => {
100
94
  const context = assertContext(service.ctx, location);
101
- return refOf(context, null, resourceAlias);
95
+ return pgPlaceholdersOf(context).refOf(null, resourceAlias);
102
96
  },
103
97
  query: async (text, params, configAlias) => {
104
98
  const db = await service.db(configAlias);
105
99
  const context = assertContext(service.ctx, location);
106
100
  try {
107
- const result = await db.pool.query(resolvePlaceholders(text, context, null), params);
101
+ const result = await db.pool.query(pgPlaceholdersOf(context).resolvePlaceholders(text, null), params);
108
102
  return result.rows;
109
103
  }
110
104
  catch (error) {
@@ -114,10 +108,11 @@ export const makePostgresDbService = (alias = DEFAULT_ALIAS) => {
114
108
  transaction: async (fn, configAlias) => {
115
109
  const db = await service.db(configAlias);
116
110
  const context = assertContext(service.ctx, location);
111
+ const placeholders = pgPlaceholdersOf(context);
117
112
  const client = await db.pool.connect();
118
113
  try {
119
114
  await client.query('BEGIN');
120
- const result = await fn(makeTx(client, text => resolvePlaceholders(text, context, null), resourceAlias => refOf(context, null, resourceAlias)));
115
+ const result = await fn(makeTx(client, text => placeholders.resolvePlaceholders(text, null), resourceAlias => placeholders.refOf(null, resourceAlias)));
121
116
  await client.query('COMMIT');
122
117
  return result;
123
118
  }
@@ -188,19 +183,6 @@ export const makePostgresDbService = (alias = DEFAULT_ALIAS) => {
188
183
  /** A value that was never locked decrypts to itself rather than failing. */
189
184
  fields.includes(field) ? await key.decrypt(value).catch(() => value) : value
190
185
  ])));
191
- },
192
- reinitializeContext: (context) => {
193
- const _service = makePostgresDbService(alias);
194
- _service.ctx = context;
195
- _service.layers = service.layers;
196
- /**
197
- * Pools carry over instead of being reopened. A layer switch changes the Postgres
198
- * *schema*, not the server, and `max_connections` is a cluster wide budget — a pool
199
- * per tenant exhausts it long before the tenants run out. The handle cache is
200
- * deliberately *not* carried: its schema name is what the switch just changed.
201
- */
202
- Object.assign(_service.clients, service.clients);
203
- return _service;
204
186
  }
205
187
  }, service => async () => {
206
188
  const context = assertContext(service.ctx, location);
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE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CAAA;QAErB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,OAAU,EAAE,KAAK,GAAW,aAAa,EACtC,EAAE;IACL,MAAM,OAAO,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAA;IAE5C,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IAChC,OAAO,CAAC,kBAAkB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAA;IAElD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { ServerConfig, ServerContext } from '@owlmeans/server-context';
2
+ export type Config = ServerConfig;
3
+ export interface Context<C extends Config = Config> extends ServerContext<C> {
4
+ }
5
+ //# sourceMappingURL=types.local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAE3E,MAAM,MAAM,MAAM,GAAG,YAAY,CAAA;AAEjC,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;CAAI"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.js","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ import type { DbConfig } from '@owlmeans/resource';
2
+ import type { PoolConfig } from 'pg';
3
+ /** A db config entry as the `pg` pool configuration it describes. */
4
+ export interface PgConfigHelper {
5
+ /**
6
+ * Split a `postgres://` URL into pool fields.
7
+ *
8
+ * node-postgres accepts a `connectionString` directly, but the parsed values *override*
9
+ * every sibling field — so `{ connectionString, database }` silently ignores the
10
+ * database. Parsing here instead keeps overriding possible, which the admin path needs
11
+ * to reach both the maintenance database and the target one over the same credentials.
12
+ *
13
+ * @throws {PostgresConnectionError}
14
+ */
15
+ parseUrl: (url: string) => PoolConfig;
16
+ /**
17
+ * Turn a {@link DbConfig} into a `pg` pool configuration.
18
+ *
19
+ * Values that start with `/` have already been read from disk by the `fileConfigReader`
20
+ * middleware, so a file mounted secret and a literal one are indistinguishable here —
21
+ * which is what lets a deployment move from env vars to mounted files without a code
22
+ * change.
23
+ */
24
+ prepareConfig: (config: DbConfig, overrides?: PoolConfig) => PoolConfig;
25
+ /** Effective database of an open pool, as `pg` resolved it. */
26
+ poolDatabase: (pool: {
27
+ options?: PoolConfig;
28
+ }) => string;
29
+ }
30
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAEpC,qEAAqE;AACrE,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;OASG;IACH,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,CAAA;IACrC;;;;;;;OAOG;IACH,aAAa,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,UAAU,KAAK,UAAU,CAAA;IACvE,+DAA+D;IAC/D,YAAY,EAAE,CAAC,IAAI,EAAE;QAAE,OAAO,CAAC,EAAE,UAAU,CAAA;KAAE,KAAK,MAAM,CAAA;CACzD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/config/types.ts"],"names":[],"mappings":""}
@@ -1,27 +1,7 @@
1
- import type { DbConfig } from '@owlmeans/resource';
2
1
  import type { PoolConfig } from 'pg';
3
- /**
4
- * Split a `postgres://` URL into pool fields.
5
- *
6
- * node-postgres accepts a `connectionString` directly, but the parsed values *override*
7
- * every sibling field — so `{ connectionString, database }` silently ignores the
8
- * database. Parsing here instead keeps overriding possible, which the admin path needs
9
- * to reach both the maintenance database and the target one over the same credentials.
10
- *
11
- * @throws {PostgresConnectionError}
12
- */
2
+ import type { PgConfigHelper } from './config/types.js';
3
+ export declare const createPgConfigHelper: () => PgConfigHelper;
4
+ export declare const pgConfigHelper: PgConfigHelper;
5
+ /** @deprecated compat:factory-refactor — use `pgConfigHelper.parseUrl(…)` */
13
6
  export declare const parseUrl: (url: string) => PoolConfig;
14
- /**
15
- * Turn a {@link DbConfig} into a `pg` pool configuration.
16
- *
17
- * Values that start with `/` have already been read from disk by the `fileConfigReader`
18
- * middleware, so a file mounted secret and a literal one are indistinguishable here —
19
- * which is what lets a deployment move from env vars to mounted files without a code
20
- * change.
21
- */
22
- export declare const prepareConfig: (config: DbConfig, overrides?: PoolConfig) => PoolConfig;
23
- /** Effective database of an open pool, as `pg` resolved it. */
24
- export declare const poolDatabase: (pool: {
25
- options?: PoolConfig;
26
- }) => string;
27
7
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAIpC;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,UAsCtC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,WAAY,QAAQ,cAAc,UAAU,KAAG,UAuCxE,CAAA;AAED,+DAA+D;AAC/D,eAAO,MAAM,YAAY,SAAU;IAAE,OAAO,CAAC,EAAE,UAAU,CAAA;CAAE,KAAG,MACV,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAGpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,eAAO,MAAM,oBAAoB,QAAO,cAsFvC,CAAA;AAED,eAAO,MAAM,cAAc,gBAAyB,CAAA;AAEpD,6EAA6E;AAC7E,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,UAA0C,CAAA"}