@cap-js/postgres 1.2.1 → 1.3.1

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,11 +4,21 @@
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
+ ### Version 1.3.1 - 2023-10-10
8
+
9
+ - `cds build`-relevant files are now correctly packaged into the release. #266
10
+
11
+ ### Version 1.3.0 - 2023-10-06
12
+
13
+ ### Added
14
+
15
+ - `cds build` is now natively supported in `@cap-js/postgres`. Thus, a `cds build` will automatically generate deployment artifacts for Postgres-enabled projects.
16
+
7
17
  ## Version 1.2.1 - 2023-09-08
8
18
 
9
19
  ### Changed
10
20
 
11
- - Bump minimum required version of `@cap-js/db-service`
21
+ - Bump minimum required version of `@cap-js/db-service`
12
22
 
13
23
  ## Version 1.2.0 - 2023-09-06
14
24
 
@@ -49,7 +59,7 @@
49
59
 
50
60
  ### Changed
51
61
 
52
- - Updated minimum required version of `@cap-js/db-service`
62
+ - Updated minimum required version of `@cap-js/db-service`
53
63
 
54
64
  ## Version 1.0.0 - 2023-06-23
55
65
 
package/README.md CHANGED
@@ -1,7 +1,34 @@
1
1
  # CDS database service for Postgres
2
2
 
3
3
  Welcome to the new Postgres database service for [SAP Cloud Application Programming Model](https://cap.cloud.sap) Node.js, based on new, streamlined database architecture and [*pg* driver](https://www.npmjs.com/package/pg) .
4
- Find full documentation at https://cap.cloud.sap/docs/guides/databases-postgres.
4
+
5
+ ## Setup
6
+
7
+ In general, all you need to do is to install one of the database packages, as follows:
8
+
9
+
10
+ ```sh
11
+ npm add @cap-js/postgres
12
+ ```
13
+
14
+ Learn more about setup and usage in the [respective database guide](https://cap.cloud.sap/docs/guides/databases-postgres).
15
+
16
+
17
+ ## Support
18
+
19
+ This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/cds-dbs/issues).
20
+
21
+ ## Contribution
22
+
23
+ Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
24
+
25
+ ## Code of Conduct
26
+
27
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
28
+
29
+ ## Licensing
30
+
31
+ Copyright 2023 SAP SE or an SAP affiliate company and cds-dbs contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js/cds-dbs).
5
32
 
6
33
  ## migration guide from `cds-pg` to `@cap-js/postgres`
7
34
 
package/cds-plugin.js CHANGED
@@ -3,3 +3,7 @@ const cds = require('@sap/cds/lib')
3
3
  if (!cds.env.fiori.lean_draft) {
4
4
  throw new Error('"@cap-js/postgres" only works if cds.fiori.lean_draft is enabled. Please adapt your configuration.')
5
5
  }
6
+
7
+ if (cds.cli.command === 'build') {
8
+ module.exports = require('./lib/build')
9
+ }
package/lib/build.js ADDED
@@ -0,0 +1,54 @@
1
+ const cds = require('@sap/cds')
2
+
3
+ let BuildPlugin
4
+ try {
5
+ ({ BuildPlugin } = require('@sap/cds-dk/lib/build'))
6
+ } catch (e) {
7
+ if (e.code === 'ENOTFOUND') throw `No build plugin mechanism for @sap/cds-dk found. Please install @sap/cds-dk for development using 'npm i -D @sap/cds-dk@^7.3.0'`
8
+ else throw e
9
+ }
10
+
11
+ const { fs, path, rimraf } = cds.utils
12
+
13
+ module.exports = class PostgresBuildPlugin extends BuildPlugin {
14
+ static hasTask() { // REVISIT: should be unnecessary -> plugin mechanism knows what to pull
15
+ return cds.requires.db.kind === 'postgres'
16
+ }
17
+
18
+ static getTaskDefaults() {
19
+ return { src: cds.env.folders.db }
20
+ }
21
+
22
+ init() {
23
+ this.task.dest = cds.env.build.target === '.' ? path.join('gen','pg') : path.join('gen', 'pg')
24
+ }
25
+
26
+ async clean() {
27
+ await rimraf(this.task.dest)
28
+ }
29
+
30
+ async build() {
31
+ const model = await this.model()
32
+ if (!model) {
33
+ return
34
+ }
35
+
36
+ const promises = []
37
+ promises.push(this.write({
38
+ dependencies: { '@sap/cds': '^7', '@cap-js/postgres': '^1' },
39
+ scripts: { start: 'cds-deploy' },
40
+ }).to('package.json'))
41
+ promises.push(this.write(cds.compile.to.json(model)).to(path.join('db', 'csn.json')))
42
+
43
+ let data
44
+ if (fs.existsSync(path.join(this.task.src, 'data'))) {
45
+ data = 'data'
46
+ } else if (fs.existsSync(path.join(this.task.src, 'csv'))) {
47
+ data = 'csv'
48
+ }
49
+ if (data) {
50
+ promises.push(this.copy(data).to(path.join('db', 'data')))
51
+ }
52
+ return Promise.all(promises)
53
+ }
54
+ }
package/lib/func.js CHANGED
@@ -2,7 +2,7 @@ const session = require('./session.json')
2
2
 
3
3
  const StandardFunctions = {
4
4
  session_context: x => {
5
- let sql = `current_setting('${ session[x.val] || x.val }')`
5
+ let sql = `current_setting('${session[x.val] || x.val}')`
6
6
  if (x.val === '$now') sql += '::timestamp'
7
7
  return sql
8
8
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/postgres",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
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": {
@@ -31,11 +31,17 @@
31
31
  "start": "docker-compose -f pg-stack.yml up -d"
32
32
  },
33
33
  "dependencies": {
34
- "@cap-js/db-service": "^1.2.1",
34
+ "@cap-js/db-service": "^1.3.1",
35
35
  "pg": "^8"
36
36
  },
37
37
  "peerDependencies": {
38
- "@sap/cds": ">=7"
38
+ "@sap/cds": ">=7",
39
+ "@sap/cds-dk": ">=7"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "cds-dk": {
43
+ "optional": true
44
+ }
39
45
  },
40
46
  "cds": {
41
47
  "requires": {