@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51
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/@cds-models/CardanoAgentService/index.d.ts +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +358 -0
- package/@cds-models/CardanoBackendService/index.js +41 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
- package/@cds-models/CardanoIndexerService/index.js +74 -0
- package/@cds-models/CardanoODataService/index.d.ts +417 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +45 -19
- package/@cds-models/CardanoSignService/index.js +4 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
- package/@cds-models/CardanoTransactionService/index.js +5 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +114 -4
- package/@cds-models/index.js +20 -4
- package/@cds-models/odatano/cardano/index.d.ts +451 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +103 -167
- package/db/schema.cds +2455 -1705
- package/db/types.cds +456 -295
- package/package.json +41 -53
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +528 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
- package/srv/blockchain/backends/blockfrost-backend.js +125 -215
- package/srv/blockchain/backends/call-signal.d.ts +7 -0
- package/srv/blockchain/backends/call-signal.js +22 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +108 -170
- package/srv/blockchain/backends/koios-backend.js +488 -482
- package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
- package/srv/blockchain/backends/odatano-backend.js +211 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
- package/srv/blockchain/backends/ogmios-backend.js +683 -327
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +71 -241
- package/srv/blockchain/cardano-client.js +354 -322
- package/srv/blockchain/cardano-indexer.d.ts +295 -283
- package/srv/blockchain/cardano-indexer.js +1690 -502
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +2 -13
- package/srv/blockchain/circuit-breaker.js +11 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +173 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
- package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
- package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
- package/srv/blockchain/crawler/certificate-backfill.js +174 -0
- package/srv/blockchain/crawler/crawler.d.ts +125 -81
- package/srv/blockchain/crawler/crawler.js +738 -167
- package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
- package/srv/blockchain/crawler/credential-backfill.js +101 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +161 -0
- package/srv/blockchain/crawler/key-pages.d.ts +12 -0
- package/srv/blockchain/crawler/key-pages.js +48 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
- package/srv/blockchain/crawler/sync-state.d.ts +31 -47
- package/srv/blockchain/crawler/sync-state.js +135 -128
- package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/transaction-backfill.js +271 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/crawler/window-plan.d.ts +31 -0
- package/srv/blockchain/crawler/window-plan.js +59 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +521 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +22 -131
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/landing-proof.d.ts +60 -0
- package/srv/blockchain/signing/landing-proof.js +224 -0
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +71 -87
- package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
- package/srv/blockchain/signing/submission-finalizer.js +280 -86
- package/srv/blockchain/stored-chain.d.ts +19 -0
- package/srv/blockchain/stored-chain.js +258 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +12 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
- package/srv/blockchain/wallet-worker/build-request.js +40 -353
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
- package/srv/blockchain/wallet-worker/invalidation.js +128 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
- package/srv/blockchain/wallet-worker/job-store.js +200 -273
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
- package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +12 -9
- package/srv/cardano-backend-service.cds +81 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +259 -0
- package/srv/cardano-indexer-service.cds +393 -18
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +477 -16
- package/srv/cardano-service.cds +426 -269
- package/srv/cardano-service.js +640 -217
- package/srv/cardano-sign-service.cds +211 -180
- package/srv/cardano-sign-service.js +210 -287
- package/srv/cardano-tx-service.cds +462 -370
- package/srv/cardano-tx-service.js +283 -800
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +141 -125
- package/srv/cardano-worker-service.js +104 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +117 -0
- package/srv/config.js +419 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +83 -405
- package/srv/utils/agent-access.d.ts +11 -0
- package/srv/utils/agent-access.js +86 -0
- package/srv/utils/agent-grants-config.d.ts +0 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -237
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +62 -186
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +4 -10
- package/srv/utils/collections.js +14 -10
- package/srv/utils/const.d.ts +32 -75
- package/srv/utils/const.js +40 -80
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +11 -25
- package/srv/utils/db-indexes.d.ts +31 -0
- package/srv/utils/db-indexes.js +185 -0
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/detached-run.d.ts +41 -0
- package/srv/utils/detached-run.js +101 -0
- package/srv/utils/epoch-slots.d.ts +14 -0
- package/srv/utils/epoch-slots.js +45 -0
- package/srv/utils/error-codes.d.ts +26 -75
- package/srv/utils/error-codes.js +27 -72
- package/srv/utils/errors.d.ts +55 -187
- package/srv/utils/errors.js +161 -235
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +111 -223
- package/srv/utils/mappers.js +432 -371
- package/srv/utils/navigation.d.ts +17 -0
- package/srv/utils/navigation.js +52 -0
- package/srv/utils/network-context.d.ts +0 -1
- package/srv/utils/network-context.js +9 -15
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +25 -105
- package/srv/utils/tx-build-helper.js +108 -156
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +294 -232
- package/srv/utils/types.js +2 -22
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +60 -170
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odatano/core",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.51",
|
|
4
4
|
"description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#cds-models/*": "./@cds-models/*/index.js"
|
|
@@ -15,25 +15,29 @@
|
|
|
15
15
|
"srv/**/*.d.ts",
|
|
16
16
|
"srv/**/*.cds",
|
|
17
17
|
"db/**/*.cds",
|
|
18
|
-
"@cds-models/"
|
|
18
|
+
"@cds-models/",
|
|
19
|
+
"scripts/migrate-schema.mjs",
|
|
20
|
+
"scripts/deploy-schema.mjs",
|
|
21
|
+
"scripts/migrate-slot-leader.mjs"
|
|
19
22
|
],
|
|
20
23
|
"engines": {
|
|
21
24
|
"node": ">=22.5"
|
|
22
25
|
},
|
|
23
26
|
"peerDependencies": {
|
|
24
|
-
"@sap/cds": "
|
|
27
|
+
"@sap/cds": "^10"
|
|
25
28
|
},
|
|
26
29
|
"dependencies": {
|
|
27
|
-
"@blockfrost/blockfrost-js": "~6.
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@harmoniclabs/
|
|
31
|
-
"@harmoniclabs/cardano-
|
|
32
|
-
"@harmoniclabs/
|
|
33
|
-
"@harmoniclabs/
|
|
34
|
-
"@harmoniclabs/
|
|
30
|
+
"@blockfrost/blockfrost-js": "~6.2.0",
|
|
31
|
+
"@cardano-ogmios/client": "^7.0.0",
|
|
32
|
+
"@harmoniclabs/buildooor": "0.3.0",
|
|
33
|
+
"@harmoniclabs/cardano-costmodels-ts": "~1.7.0",
|
|
34
|
+
"@harmoniclabs/cardano-ledger-ts": "^0.6.1",
|
|
35
|
+
"@harmoniclabs/cbor": "^2.1.0",
|
|
36
|
+
"@harmoniclabs/crypto": "^0.3.2",
|
|
37
|
+
"@harmoniclabs/plutus-data": "^2.1.1",
|
|
35
38
|
"@harmoniclabs/uint8array-utils": "^1.0.4",
|
|
36
|
-
"@
|
|
39
|
+
"@harmoniclabs/uplc": "^2.0.8",
|
|
40
|
+
"@odatano/cap-auth": "^0.2.0",
|
|
37
41
|
"axios": "^1.18.0",
|
|
38
42
|
"bech32": "^2.0.0",
|
|
39
43
|
"blake2b": "^2.1.4"
|
|
@@ -55,10 +59,13 @@
|
|
|
55
59
|
"@cap-js/cds-test": "^0.4.1",
|
|
56
60
|
"@cap-js/cds-typer": "^0.40.0",
|
|
57
61
|
"@cap-js/cds-types": "^0.18.0",
|
|
62
|
+
"@cap-js/hana": "^3",
|
|
63
|
+
"@cap-js/postgres": "^3.1.1",
|
|
58
64
|
"@cap-js/sqlite": "^3",
|
|
59
65
|
"@sap/cds": "^10",
|
|
60
66
|
"@sap/cds-dk": "^10",
|
|
61
67
|
"@sap/eslint-plugin-cds": "^4.2.4",
|
|
68
|
+
"@sap/xssec": "^4",
|
|
62
69
|
"@types/blake2b": "^2.1.3",
|
|
63
70
|
"@types/node": "^22.19.7",
|
|
64
71
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
@@ -67,47 +74,24 @@
|
|
|
67
74
|
"dotenv": "^16.3.1",
|
|
68
75
|
"eslint": "^9.39.2",
|
|
69
76
|
"nock": "^13.5.6",
|
|
77
|
+
"semver": "^7.8.6",
|
|
70
78
|
"ts-node": "^10.9.2",
|
|
71
79
|
"tsx": "^4.21.0",
|
|
72
80
|
"typescript": "^5.9.3",
|
|
73
81
|
"vitest": "^4.1.10"
|
|
74
82
|
},
|
|
75
83
|
"cds": {
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{
|
|
87
|
-
"for": "hana",
|
|
88
|
-
"src": "db",
|
|
89
|
-
"dest": "../gen/db"
|
|
90
|
-
}
|
|
84
|
+
"log": {
|
|
85
|
+
"mask_headers": [
|
|
86
|
+
"/authorization/i",
|
|
87
|
+
"/cookie/i",
|
|
88
|
+
"/cert/i",
|
|
89
|
+
"/ssl/i",
|
|
90
|
+
"/token/i",
|
|
91
|
+
"/key/i",
|
|
92
|
+
"/secret/i",
|
|
93
|
+
"/project_id/i"
|
|
91
94
|
]
|
|
92
|
-
},
|
|
93
|
-
"requires": {
|
|
94
|
-
"db": {
|
|
95
|
-
"kind": "sqlite",
|
|
96
|
-
"credentials": {
|
|
97
|
-
"url": "db.sqlite"
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
"[production]": {
|
|
101
|
-
"db": {
|
|
102
|
-
"kind": "hana",
|
|
103
|
-
"pool": {
|
|
104
|
-
"acquireTimeoutMillis": 30000,
|
|
105
|
-
"min": 0,
|
|
106
|
-
"max": 10
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
"auth": "xsuaa"
|
|
110
|
-
}
|
|
111
95
|
}
|
|
112
96
|
},
|
|
113
97
|
"scripts": {
|
|
@@ -120,19 +104,20 @@
|
|
|
120
104
|
"start": "cds-serve",
|
|
121
105
|
"cds:watch": "cds watch",
|
|
122
106
|
"cds:serve": "cds serve --with-mocks",
|
|
123
|
-
"cds:types": "cds-typer \"*\" --outputDirectory @cds-models",
|
|
107
|
+
"cds:types": "cds-typer \"*\" --outputDirectory @cds-models --ieee754compatible true",
|
|
124
108
|
"lint": "eslint .",
|
|
125
109
|
"typecheck": "tsc --noEmit",
|
|
126
110
|
"db:deploy": "cds deploy",
|
|
127
|
-
"
|
|
111
|
+
"db:fresh": "node -e \"for(const f of ['db.sqlite','db.sqlite-wal','db.sqlite-shm'])require('fs').rmSync(f,{force:true})\" && npm run db:deploy",
|
|
112
|
+
"pretest": "npm run clean && npm run cds:types && npm run db:fresh",
|
|
128
113
|
"test": "vitest run",
|
|
129
|
-
"pretest:coverage": "npm run clean && npm run cds:types && npm run db:
|
|
114
|
+
"pretest:coverage": "npm run clean && npm run cds:types && npm run db:fresh",
|
|
130
115
|
"test:coverage": "vitest run --coverage",
|
|
131
|
-
"pretest:ci": "npm run clean && npm run cds:types && npm run db:
|
|
116
|
+
"pretest:ci": "npm run clean && npm run cds:types && npm run db:fresh",
|
|
132
117
|
"test:ci": "vitest run --exclude \"**/core-ogmios.test.ts\"",
|
|
133
|
-
"pretest:ci:coverage": "npm run clean && npm run cds:types && npm run db:
|
|
118
|
+
"pretest:ci:coverage": "npm run clean && npm run cds:types && npm run db:fresh",
|
|
134
119
|
"test:ci:coverage": "vitest run --coverage --exclude \"**/core-ogmios.test.ts\"",
|
|
135
|
-
"pretest:integration": "npm run clean && npm run cds:types && npm run db:
|
|
120
|
+
"pretest:integration": "npm run clean && npm run cds:types && npm run db:fresh",
|
|
136
121
|
"test:integration": "vitest run --project integration",
|
|
137
122
|
"test:integration:blockfrost": "vitest run test/integration/core.blockfrost.test.ts",
|
|
138
123
|
"test:integration:koios": "vitest run test/integration/core.koios.test.ts",
|
|
@@ -141,7 +126,10 @@
|
|
|
141
126
|
"pretest:unit": "npm run cds:types",
|
|
142
127
|
"test:unit": "vitest run --project unit",
|
|
143
128
|
"watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
|
|
144
|
-
"watch-wallet": "cds watch --open wallet/webapp/index.html"
|
|
129
|
+
"watch-wallet": "cds watch --open wallet/webapp/index.html",
|
|
130
|
+
"release:check": "node scripts/release-check.mjs",
|
|
131
|
+
"smoke:consumer": "node scripts/smoke-consumer.mjs",
|
|
132
|
+
"prepublishOnly": "node scripts/publish-guard.mjs"
|
|
145
133
|
},
|
|
146
134
|
"sapux": [
|
|
147
135
|
"app/odatano"
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Brings the configured database to the schema of this version: first the changes the additive
|
|
3
|
+
// deploy refuses (migrate-schema.mjs), then the deploy itself, which keeps every row.
|
|
4
|
+
// The upgrade command of a plugin project and of the Docker image. --dry-run only reports.
|
|
5
|
+
import cds from '@sap/cds';
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { assertDeployable, migrateSchema } from './migrate-schema.mjs';
|
|
9
|
+
|
|
10
|
+
const print = (line) => process.stdout.write(`schema migration: ${line}\n`);
|
|
11
|
+
|
|
12
|
+
/** Migrates, then deploys with schema evolution. Without it CAP drops and recreates every SQLite table. */
|
|
13
|
+
export async function deploySchema(db, { dryRun = false, log = print } = {}) {
|
|
14
|
+
return withDeployLock(db, log, async () => {
|
|
15
|
+
const ran = await migrateSchema(db, { dryRun, log });
|
|
16
|
+
if (dryRun) return ran;
|
|
17
|
+
await assertDeployable(db);
|
|
18
|
+
await cds.deploy('*', { schema_evolution: 'auto' }).to(db);
|
|
19
|
+
return ran;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Two instances starting together on PostgreSQL would run the steps and the deploy at the same time,
|
|
24
|
+
// and one fails. A session lock on a connection of its own makes the second wait until the first is done.
|
|
25
|
+
async function withDeployLock(db, log, run) {
|
|
26
|
+
const factory = db.kind === 'postgres' ? db.factory : null;
|
|
27
|
+
if (!factory) return run();
|
|
28
|
+
const dbc = await factory.create();
|
|
29
|
+
try {
|
|
30
|
+
const schema = db.options?.credentials?.schema;
|
|
31
|
+
if (schema) await dbc.query(`SET search_path TO "${String(schema).replace(/"/g, '""')}", public`);
|
|
32
|
+
const key = "hashtext('odatano_deploy_schema:' || current_schema())";
|
|
33
|
+
const { rows } = await dbc.query(`SELECT pg_try_advisory_lock(${key}) AS got`);
|
|
34
|
+
if (!rows[0]?.got) {
|
|
35
|
+
log('another instance deploys the schema; waiting for it');
|
|
36
|
+
await dbc.query(`SELECT pg_advisory_lock(${key})`);
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
return await run();
|
|
40
|
+
} finally {
|
|
41
|
+
await dbc.query(`SELECT pg_advisory_unlock(${key})`);
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
await factory.destroy(dbc);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The SQLite file the configured database names, or null when it is not a file on disk. */
|
|
49
|
+
function sqliteFile() {
|
|
50
|
+
const db = cds.env.requires.db ?? {};
|
|
51
|
+
const url = db.credentials?.url ?? db.credentials?.database;
|
|
52
|
+
if (!['sqlite', 'better-sqlite'].includes(db.kind) || !url || url === ':memory:') return null;
|
|
53
|
+
return path.resolve(cds.root, url);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** True when the error says the table does not exist; any other error is not an answer. */
|
|
57
|
+
export function isMissingTable(err) {
|
|
58
|
+
const e = err ?? {};
|
|
59
|
+
if (e.code === '42P01') return true;
|
|
60
|
+
return /no such table/i.test(String(e.message ?? ''));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** True when the database holds no table of this model yet. A failed connect or login is thrown. */
|
|
64
|
+
async function isEmpty(db) {
|
|
65
|
+
try {
|
|
66
|
+
await db.run('SELECT 1 FROM odatano_cardano_Blocks WHERE 1 = 0');
|
|
67
|
+
return false;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
if (isMissingTable(err)) return true;
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function main() {
|
|
75
|
+
const unknown = process.argv.slice(2).filter((a) => a !== '--dry-run');
|
|
76
|
+
if (unknown.length) throw new Error(`unknown argument ${unknown.join(' ')}; the only option is --dry-run`);
|
|
77
|
+
await cds.plugins;
|
|
78
|
+
const dryRun = process.argv.includes('--dry-run');
|
|
79
|
+
// connecting creates a missing SQLite file, which a dry run must not do
|
|
80
|
+
const file = sqliteFile();
|
|
81
|
+
if (dryRun && file && !existsSync(file)) {
|
|
82
|
+
console.log(`Dry run: ${file} does not exist. A deploy creates it with the schema of this version.`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
cds.db = await cds.connect.to('db');
|
|
86
|
+
try {
|
|
87
|
+
if (dryRun && await isEmpty(cds.db)) {
|
|
88
|
+
console.log('Dry run: the database is empty. A deploy creates the schema of this version; nothing changed.');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const ran = await deploySchema(cds.db, { dryRun });
|
|
92
|
+
if (dryRun) {
|
|
93
|
+
console.log(ran.length ? 'Dry run: the steps above are due, then the deploy; nothing changed.'
|
|
94
|
+
: 'Dry run: no migration step is due. A deploy still adds what this version adds; nothing changed.');
|
|
95
|
+
}
|
|
96
|
+
} finally {
|
|
97
|
+
await cds.db?.disconnect?.();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The command line: deploys to the configured database, exits with 1 on a failure. */
|
|
102
|
+
export async function runDeploySchemaCli() {
|
|
103
|
+
try {
|
|
104
|
+
await main();
|
|
105
|
+
process.exit(0);
|
|
106
|
+
} catch (err) {
|
|
107
|
+
process.stderr.write(`FATAL: schema deploy failed: ${err instanceof Error ? err.stack : String(err)}\n`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Replaces @sap/cds/bin/deploy.js, which prints the credentials.
|
|
113
|
+
if (process.argv[1] && import.meta.url === (await import('node:url')).pathToFileURL(process.argv[1]).href) await runDeploySchemaCli();
|