@cap-js/postgres 2.0.2 → 2.0.3

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/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@
4
4
  - The format is based on [Keep a Changelog](http://keepachangelog.com/).
5
5
  - This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [2.0.3](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.2...postgres-v2.0.3) (2025-06-30)
8
+
9
+
10
+ ### Fixed
11
+
12
+ * **`cds-build`:** retain more build relevant options in the deployer app ([#1206](https://github.com/cap-js/cds-dbs/issues/1206)) ([e7ed70f](https://github.com/cap-js/cds-dbs/commit/e7ed70f36920867ec0063d29255e3681dec1b60c))
13
+
7
14
  ## [2.0.2](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.1...postgres-v2.0.2) (2025-06-04)
8
15
 
9
16
 
package/cds-plugin.js CHANGED
@@ -5,19 +5,22 @@ if (!cds.env.fiori.lean_draft) {
5
5
  throw new Error('"@cap-js/postgres" only works if cds.fiori.lean_draft is enabled. Please adapt your configuration.')
6
6
  }
7
7
 
8
+ // copy over build relevant cds options to the package.json of the deployer app
9
+ const CDS_BUILD_OPTIONS = ['assert_integrity']
10
+
11
+ // cdsc options are build relevant too, but we need to filter out some
12
+ const CDSC_DISALLOW = ['moduleLookupDirectories']
13
+
8
14
  // requires @sap/cds-dk version >= 7.5.0
9
15
  cds.build?.register?.('postgres', class PostgresBuildPlugin extends cds.build.Plugin {
10
-
11
16
  static taskDefaults = { src: cds.env.folders.db }
12
-
13
- static hasTask() { return cds.requires.db?.kind === 'postgres' }
14
-
15
- init() {
17
+ static hasTask () { return cds.requires.db?.kind === 'postgres' }
18
+ init () {
16
19
  // different from the default build output structure
17
20
  this.task.dest = path.join(cds.root, cds.env.build.target !== '.' ? cds.env.build.target : 'gen', 'pg')
18
21
  }
19
22
 
20
- async build() {
23
+ async build () {
21
24
  const model = await this.model()
22
25
  if (!model) return
23
26
 
@@ -27,23 +30,36 @@ cds.build?.register?.('postgres', class PostgresBuildPlugin extends cds.build.Pl
27
30
  } else {
28
31
  const packageJson = {
29
32
  dependencies: {
30
- '@sap/cds': '^8',
31
- '@cap-js/postgres': '^1'
33
+ '@sap/cds': '^9',
34
+ '@cap-js/postgres': '^2'
32
35
  },
33
- scripts: {
34
- start: 'cds-deploy'
36
+ scripts: { start: 'cds-deploy' }
37
+ }
38
+
39
+ // propagate cds.env.features (allow-listed)
40
+ const envFeatures = cds.env?.features ?? {}
41
+ for (const name of CDS_BUILD_OPTIONS) {
42
+ const val = envFeatures[name]
43
+ if (val !== undefined) {
44
+ packageJson.cds ??= {}
45
+ packageJson.cds.features ??= {}
46
+ packageJson.cds.features[name] = val
35
47
  }
36
48
  }
37
- const assertIntegrity = cds.env?.features?.assert_integrity
38
- if (assertIntegrity) {
49
+
50
+ // propagate cds.env.cdsc (minus disallowed)
51
+ const envCdsc = cds.env?.cdsc ?? {}
52
+ const cdscClean = Object.fromEntries(
53
+ Object.entries(envCdsc).filter(([key]) => !CDSC_DISALLOW.includes(key))
54
+ )
55
+ if (Object.keys(cdscClean).length) {
39
56
  packageJson.cds ??= {}
40
- packageJson.cds.features ??= {}
41
- packageJson.cds.features.assert_integrity = assertIntegrity
57
+ packageJson.cds.cdsc = cdscClean
42
58
  }
43
- promises.push(
44
- this.write(packageJson).to('package.json')
45
- )
59
+
60
+ promises.push(this.write(packageJson).to('package.json'))
46
61
  }
62
+
47
63
  promises.push(this.write(cds.compile.to.json(model)).to(path.join('db', 'csn.json')))
48
64
 
49
65
  let data
@@ -50,6 +50,8 @@ class PostgresService extends SQLService {
50
50
  }
51
51
  const dbc = new Client({ ...credentials, ...clientOptions })
52
52
  await dbc.connect()
53
+ dbc.open = true
54
+ dbc.on('end', () => { dbc.open = false })
53
55
  return dbc
54
56
  },
55
57
  destroy: dbc => dbc.end(),
@@ -283,7 +285,7 @@ GROUP BY k
283
285
  return target && this.run(cds.ql.CREATE(target))
284
286
  }
285
287
  }
286
-
288
+
287
289
  try {
288
290
  return await super.onPlainSQL(req, next)
289
291
  }
@@ -379,7 +381,7 @@ GROUP BY k
379
381
  }
380
382
 
381
383
  orderByICU(orderBy, localized) {
382
- const locale = this.context.locale ? `${this.context.locale.replace('_', '-')}-x-icu` : this.context.locale
384
+ const locale = this.context.locale ? `${this.context.locale.replace('_', '-')}-x-icu` : this.context.locale
383
385
  return this._orderBy(orderBy, localized, locale)
384
386
  }
385
387
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/postgres",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "CDS database service for Postgres",
5
5
  "homepage": "https://github.com/cap-js/cds-dbs/tree/main/postgres#cds-database-service-for-postgres",
6
6
  "repository": {