@cap-js/postgres 2.0.2 → 2.0.4

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,20 @@
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.4](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.3...postgres-v2.0.4) (2025-07-28)
8
+
9
+
10
+ ### Fixed
11
+
12
+ * ensure ordering of `ParameterStream` chunks ([#1280](https://github.com/cap-js/cds-dbs/issues/1280)) ([a49e200](https://github.com/cap-js/cds-dbs/commit/a49e200eb3c08cedcea04ffc5ecb7c664ee885c0))
13
+
14
+ ## [2.0.3](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.2...postgres-v2.0.3) (2025-06-30)
15
+
16
+
17
+ ### Fixed
18
+
19
+ * **`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))
20
+
7
21
  ## [2.0.2](https://github.com/cap-js/cds-dbs/compare/postgres-v2.0.1...postgres-v2.0.2) (2025-06-04)
8
22
 
9
23
 
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
 
@@ -806,17 +808,17 @@ class ParameterStream extends Writable {
806
808
  this.lengthBuffer = Buffer.from([0x64, 0, 0, 0, 0])
807
809
 
808
810
  // Flush quote character before input stream
809
- this.flushChunk = chunk => {
811
+ this.flushChunk = (chunk, cb) => {
810
812
  delete this.flushChunk
811
813
 
812
814
  this.lengthBuffer.writeUInt32BE(chunk.length + 5, 1)
813
815
  this.connection.stream.write(this.lengthBuffer)
814
- this.connection.stream.write(Buffer.from(this.constructor.sep))
815
- return this.connection.stream.write(chunk)
816
+ this.connection.stream.write(this.constructor.sep)
817
+ this.connection.stream.write(chunk, cb)
816
818
  }
817
819
  }
818
820
 
819
- static sep = String.fromCharCode(31) // Separator One
821
+ static sep = Buffer.from(String.fromCharCode(31)) // Separator One
820
822
  static done = Buffer.from([0x63, 0, 0, 0, 4])
821
823
 
822
824
  then(resolve, reject) {
@@ -867,17 +869,14 @@ class ParameterStream extends Writable {
867
869
  })
868
870
  }
869
871
 
870
- flush(chunk, callback) {
871
- if (this.flushChunk(chunk)) {
872
- return callback()
873
- }
874
- this.connection.stream.once('drain', callback)
872
+ flush(chunk, cb) {
873
+ this.flushChunk(chunk, cb)
875
874
  }
876
875
 
877
- flushChunk(chunk) {
876
+ flushChunk(chunk, cb) {
878
877
  this.lengthBuffer.writeUInt32BE(chunk.length + 4, 1)
879
878
  this.connection.stream.write(this.lengthBuffer)
880
- return this.connection.stream.write(chunk)
879
+ this.connection.stream.write(chunk, cb)
881
880
  }
882
881
 
883
882
  handleError(e) {
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.4",
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": {