Socket
Socket
Sign inDemoInstall

@sap/cds

Package Overview
Dependencies
Maintainers
3
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap/cds - npm Package Compare versions

Comparing version 1.15.1 to 2.3.1

apis/cds-ql.d.ts

2

package.json

@@ -1,1 +0,1 @@

{"dependencies":{"@sap/hdbext":"^4.3.0","@sap/xsenv":"^1.2.6","async":"1.5.0","winston":"1.1.2"},"description":"SAP HANA Core Data Services Client for node.js","devDependencies":{"expect":"^1.4.0","mocha":"4.0.1"},"engines":{"node":"^0.12.7 || ^4.4.0 || ^6.0.0","npm":"^2.11.x"},"keywords":["sap","hana","cds"],"main":"./cds.js","maintainers":[{"name":"https-support.sap.com","email":"do-not-reply@sap.com"}],"name":"@sap/cds","optionalDependencies":{},"readme":"node-cds: Core Data Services for node.js\n========================================\n\nImportant note: \n---------------\n The node-cds library is now considered feature complete. \n It will remain fully supported but will not receive further \n enhancements in future releases.\n\nAbstract\n--------\n\nThe *Core Data Services for node.js* (node-cds) are a JavaScript\nclient library for Core Data Services that allow node.js applications\nto consume CDS artifacts natively in node.js applications.\n\nnode-cds supports major CDS features, in particular entities, types,\nassociations, and views. The library offers a *managed mode* and an\n*unmanaged mode* that differ in the way that data is retrieved from\nthe database.\n\nThe node-cds project is the successor of the XS Data Services (XSDS)\nlibrary available for the HANA XS Engine.\n\n\nAPI Overview\n------------\n\n### Library Import\n\nTo use *node-cds*, require its main file:\n\n var cds = require('cds');\n\nOn Cloud Foundry, add a depencency on the latest node-cds release to\nyour `package.json`:\n\n \"dependencies\": {\n \"cds\": \"*\",\n ...\n }\n\t\t\n\n### CDS Import\n\nCDS entities are imported by name. The import function takes a callback that\nis invoked when all imports have completed. Additional fields and overrides\nmay be supplied for each entity.\n\n cds.importEntities([\n { $entity: \"xsds.test.cds::ds_test.e1\" },\n { $entity: \"xsds.test.cds::ds_test.e2\",\n $fields: {\n a: { $association: \"xsds.test.cds::ds_test.e2\",\n $viaBacklink: \"b\" }\n }\n }\n ], callback);\n\n function callback(error, entities) {\n var E1 = entities[\"xsds.test.cds::ds_test.e1\"];\n var E2 = entities[\"xsds.test.cds::ds_test.e2\"];\n // ...\n }\n\nNote that the import is a regular asynchronous node.js function. You may\nimport entities at any point in time, and in as many calls as you want.\n\nEntities may not be imported more than once. To retrieve an imported entity\nuse `$getEntity` or `$getEntities`:\n\n cds.$getEntities([\n \"xsds.test.cds::ds_test.e1\",\n \"xsds.test.cds::ds_test.e2\"\n ], function(err, entities) {\n var E1 = entities[\"xsds.test.cds::ds_test.e1\"];\n // ...\n });\n\nBoth functions will wait until the requested entity has been imported successfully.\nThere is also a synchronous version:\n\n var E1 = $getEntitySync(\"xsds.test.cds::ds_test.e1\");\n\nNote that `$getEntitySync` will return `null` if the import has not completed yet.\n\n\n### Database Connections and Transactions\n\nOpen new connection and transaction:\n\n cds.$getTransaction(function(error, tx) {\n tx.$get(...);\n // ...\n tx.$close();\n });\n\nReuse existing database connection `dbconn`, e.g., from `express` framework:\n\n cds.$getTransaction(dbconn, function(error, tx) {\n tx.$get(...);\n // ...\n tx.$close();\n });\n\nNote: We recommend `node-hdbext` for setting up the\nconnection to your HANA instance.\n\nTransaction management\n\n tx.$setAutoCommit(<boolean>);\n tx.$commit(callback);\n tx.$rollback(callback);\n\nBy default, transactions are in auto commit mode. Note that auto commit refers\nto node-cds operations, not database operations.\n\n\n### Managed Instances\n\nRetrieve entity instances by key:\n\n tx.$get(E1, { id1: 1, id2: 2, ... }, function(error, instance) {\n console.log(JSON.stringify(instance));\n });\n\nBatch retrieval for multiple instances:\n\n var requests = [\n { $entity: E1, id11: 1, id2: 2 },\n { $entity: E2, id: \"key\" }, ...\n ];\n tx.$getAll(requests, function(error, instances) {\n console.log(\"e1 = \" + JSON.stringify(instances[0]);\n console.log(\"e2 = \" + JSON.stringify(instances[1]);\n });\n\nSyntactic sugar for above:\n\n var requests = [\n E1.$prepare({ id1: 1, id2: 2 }),\n E2.$prepare({ id: \"key\" }), ...\n ];\n tx.$getAll(requests, ...);\n\nRetrieve entity instances by condition:\n\n tx.$find(E1, { value: { $gt: 69 } }, function(error, instances) {\n console.log(\"found \" + instance.length + \" instances\");\n });\n\nBatch retrieval by condition:\n\n tx.$findAll([\n { $entity: E1, { prop: { $eq: 1 } },\n { $entity: E2, { prop: { $ne: 2 } }\n ], callback);\n\nNote that the result of `$findAll` is an array of arrays; to flatten the result\nset you may use\n\n var flattenedInstanceArray = [].concat.apply([], findAllResult));\n\nFor complex data types you need to supply a comparison function using `$using` that\ncompares their values in JavaScript:\n\n tx.$find(E1, { prop: { $lt: \"1.0e-10\", $using: function(arg1, arg2) {\n return Math.sign(parseFloat(arg1) - parseFloat(arg2));\n } }, callback);\n\nA comparison function takes two arguments and returns values `< 0`, `== 0`, or `> 0`\ndepending on their relation to each other.\n\nCreate new instance:\n\n tx.$save({ $entity: E, key: 1, value: \"hello world\" }, function(error, instance) {\n if (!error)\n console.log(\"instance created\");\n });\n\nBatch creation:\n\n var newinsts = [\n { $entity: E1, id1: 1, value: 2 },\n E2.$prepare({ id: \"new\", value: 4 }), ...\n ];\n tx.$saveAll(newinsts, function(error, instances) {\n console.log(\"\" + instances.length + \" instances created\");\n });\n\nUpdate existing instance:\n\n instance.value++;\n tx.$save(instance, function (error, savedInstance) {\n if (!error)\n console.log(\"instance updated\");\n });\n\nBatch update:\n\n tx.$saveAll([ instance1, instance2, ... ], function (error, instances) {\n console.log(\"instances updated\");\n });\n\nDiscard entity instances:\n\n tx.$discard(instance, function(error) {\n if (error)\n console.error(\"Error discarding instance: \" + error);\n });\n\nBatch discard:\n\n tx.$discardAll([ instance1, instance2, ...], function(error) {\n if (error)\n console.error(\"Error discarding instances: \" + error);\n });\n\nUnmanaged delete:\n\n tx.$delete(entity, condition, callback);\n\n*CAUTION!* Unmanaged `delete`s bypass the cache and will not cascade to\ntarget instances! The `$delete` method is merely syntactic sugar for\n`$query().$matching().$delete()`!\n\n\n### Associations\n\nAdding via backlink 1:n associations:\n\n cds.importEntities([{\n $entity: \"cds.test::parent\",\n $fields: {\n BacklinkAssoc: {\n $association: {\n $entity: \"cds.test::target\",\n $viaBacklink: \"backassoc\"\n }\n }\n }\n }], callback);\n\nAdding via entity m:n associations:\n\n cds.importEntities([{\n $entity: \"cds.test::parent\",\n $fields: {\n BacklinkAssoc: {\n\t\t\t\t$association: {\n\t\t\t\t\t$entity: \"cds.test::target\",\n\t\t\t\t\t$viaEntity: \"cds.test::link\",\n\t\t\t\t\t$source: \"sourceassoc\",\n\t\t\t\t\t$target: \"targetassoc\"\n\t\t\t\t}\n }\n }\n }], callback);\n\nDeclaring lazy associations:\n\n cds.importEntities([{\n $entity: \"cds.test::parent\",\n $fields: {\n LazyAssoc: {\n $association: {\n\t\t\t\t\t$lazy: true\n\t\t\t\t}\n }\n }\n ], callback);\n\nLazy retrieval of lazy associations:\n\n instance.lazyAssoc.$load(function (error, targets) {\n // targets == instance.lazyAssoc\n console.log(\"\" + targets.length + \" targets retrieved\");\n });\n\nRe-syncing backlinking and unmanaged associations\n\n instance.unmanagedAssoc.$reload(function (error, targets) {\n // targets == instance.unmanagedAssoc\n console.log(\"association has \" + targets.length + \" targets\");\n });\n\n\n### Unmanaged Queries\n\nBasic query:\n\n E1.$query().$matching({ key: 1 })\n .$execute({}, function(error, result) {\n console.log(\"result = \" + JSON.stringify(result);\n });\n\nMore complex query conditions:\n\n E1.$query().$matching({ value1: { $lt: 42 }, value2: { $null: true } })\n .$execute({}, function(error, result) {\n console.log(\"result = \" + JSON.stringify(result);\n });\n\nProjection and navigation:\n\n E2.$query().$matching({ key: 1 })\n .$project({ value1: true, assoc: { value2: true, value3: true })\n .$execute({}, function(error, result) { ... });\n\nStream interface:\n\n E1.$query().$execute({ $stream: true }, function(error, stream) {\n stream.on('data', function(chunk) {\n console.log(chunk);\n }).on('end', function() {\n console.log(\"done\");\n });\n });\n","readmeFilename":"README.md","scripts":{"cleanBundle":"find $PWD -name package.json -exec node .filter/filter-package.js {} \\; ; rm -rf .filter init_sign.py","prepareRelease":"rm -rf doc/ test/ .gitignore .xmake.cfg && npm prune --production","test-disabled":"node node_modules/mocha/bin/mocha --recursive"},"version":"1.15.1","warnings":[{"code":"ENOTSUP","required":{"node":"^0.12.7 || ^4.4.0 || ^6.0.0","npm":"^2.11.x"},"pkgid":"@sap/cds@1.15.1"},{"code":"ENOTSUP","required":{"node":"^0.12.7 || ^4.4.0 || ^6.0.0","npm":"^2.11.x"},"pkgid":"@sap/cds@1.15.1"}],"license":"SEE LICENSE IN developer-license-3.1.txt"}
{"bin":{"cds":"bin/cds.js"},"dependencies":{"@sap/cds-compiler":"1.0.27","@sap/cds-reflect":"1.2.0","fs-extra":"5.0.0"},"description":"Entry Point and API Facade for CDS","devDependencies":{"eslint":"^4.19.0","express":"^4.16.2","hasbin":"^1.2.3","jest":"^22.4.2","jest-junit":"^3.6.0","sqlite3":"^3.1.13","supertest":"^3.0.0"},"engines":{"node":">= 6.12.0"},"jest":{"roots":["<rootDir>/bin/","<rootDir>/lib/","<rootDir>/tests/"],"modulePathIgnorePatterns":["/_out/","/edmx/","/projects/"],"moduleFileExtensions":["js","json","cds","properties"],"coverageDirectory":"reports/coverage","collectCoverageFrom":["lib/**","bin/**","!bin/init/**","!**/*.json"],"testResultsProcessor":"jest-junit","testPathIgnorePatterns":["/node_modules/","/integration/","/services/"]},"jest-junit":{"suiteName":"jest tests","output":"reports/sonar/test-reporter.xml","classNameTemplate":"{classname}-{title}","titleTemplate":"{classname}-{title}","ancestorSeparator":" › ","usePathForSuiteName":"true"},"main":"lib/index.js","maintainers":[{"name":"https-support.sap.com","email":"do-not-reply@sap.com"}],"name":"@sap/cds","optionalDependencies":{},"readme":"# @sap/cds\n\nThe API package for the different parts of CDS.\nIt provides access to CDS compiler, both on command line and programmatically.\n\n## Building Models on Command Line\nGiven an application with structure\n```\ndb/\n data-model.cds\nsrv/\n my-service.cds\n```\nyou can execute `cds build` to build the models.\n\nSee the [docs](https://<TODO ADD LINK>/get-started/in-a-nutshell) for more.\n\n## Building Models Programmatically\n```bash\ncds -e \"cds.load('db') .then (cds.compile.to.hana)\"\ncds -e \"cds.load('srv').then (cds.compile.to.edmx)\"\n```\n\nSee the [docs](https://<TODO ADD LINK>/APIs/) for more.\n","readmeFilename":"README.md","scripts":{"beforePublish":"rm bin/.dev-internal.js","lint":"eslint .","test":"jest --coverage && npm run test:new","test:all":"jest --coverage --testPathIgnorePatterns /node_modules/ /services/","test:integration":"jest --testRegex integration.*\\.js --testPathIgnorePatterns /node_modules/ /services/","test:new":"jest --testRegex test-new\\.js","test:watch":"jest --watchAll"},"typings":"apis/cds.d.ts","version":"2.3.1","warnings":[{"code":"ENOTSUP","required":{"node":">= 6.12.0"},"pkgid":"@sap/cds@2.3.1"},{"code":"ENOTSUP","required":{"node":">= 6.12.0"},"pkgid":"@sap/cds@2.3.1"}],"license":"SEE LICENSE IN developer-license-3.1.txt"}

@@ -1,318 +0,24 @@

node-cds: Core Data Services for node.js
========================================
# @sap/cds
Important note:
---------------
The node-cds library is now considered feature complete.
It will remain fully supported but will not receive further
enhancements in future releases.
The API package for the different parts of CDS.
It provides access to CDS compiler, both on command line and programmatically.
Abstract
--------
## Building Models on Command Line
Given an application with structure
```
db/
data-model.cds
srv/
my-service.cds
```
you can execute `cds build` to build the models.
The *Core Data Services for node.js* (node-cds) are a JavaScript
client library for Core Data Services that allow node.js applications
to consume CDS artifacts natively in node.js applications.
See the [docs](https://<TODO ADD LINK>/get-started/in-a-nutshell) for more.
node-cds supports major CDS features, in particular entities, types,
associations, and views. The library offers a *managed mode* and an
*unmanaged mode* that differ in the way that data is retrieved from
the database.
## Building Models Programmatically
```bash
cds -e "cds.load('db') .then (cds.compile.to.hana)"
cds -e "cds.load('srv').then (cds.compile.to.edmx)"
```
The node-cds project is the successor of the XS Data Services (XSDS)
library available for the HANA XS Engine.
API Overview
------------
### Library Import
To use *node-cds*, require its main file:
var cds = require('cds');
On Cloud Foundry, add a depencency on the latest node-cds release to
your `package.json`:
"dependencies": {
"cds": "*",
...
}
### CDS Import
CDS entities are imported by name. The import function takes a callback that
is invoked when all imports have completed. Additional fields and overrides
may be supplied for each entity.
cds.importEntities([
{ $entity: "xsds.test.cds::ds_test.e1" },
{ $entity: "xsds.test.cds::ds_test.e2",
$fields: {
a: { $association: "xsds.test.cds::ds_test.e2",
$viaBacklink: "b" }
}
}
], callback);
function callback(error, entities) {
var E1 = entities["xsds.test.cds::ds_test.e1"];
var E2 = entities["xsds.test.cds::ds_test.e2"];
// ...
}
Note that the import is a regular asynchronous node.js function. You may
import entities at any point in time, and in as many calls as you want.
Entities may not be imported more than once. To retrieve an imported entity
use `$getEntity` or `$getEntities`:
cds.$getEntities([
"xsds.test.cds::ds_test.e1",
"xsds.test.cds::ds_test.e2"
], function(err, entities) {
var E1 = entities["xsds.test.cds::ds_test.e1"];
// ...
});
Both functions will wait until the requested entity has been imported successfully.
There is also a synchronous version:
var E1 = $getEntitySync("xsds.test.cds::ds_test.e1");
Note that `$getEntitySync` will return `null` if the import has not completed yet.
### Database Connections and Transactions
Open new connection and transaction:
cds.$getTransaction(function(error, tx) {
tx.$get(...);
// ...
tx.$close();
});
Reuse existing database connection `dbconn`, e.g., from `express` framework:
cds.$getTransaction(dbconn, function(error, tx) {
tx.$get(...);
// ...
tx.$close();
});
Note: We recommend `node-hdbext` for setting up the
connection to your HANA instance.
Transaction management
tx.$setAutoCommit(<boolean>);
tx.$commit(callback);
tx.$rollback(callback);
By default, transactions are in auto commit mode. Note that auto commit refers
to node-cds operations, not database operations.
### Managed Instances
Retrieve entity instances by key:
tx.$get(E1, { id1: 1, id2: 2, ... }, function(error, instance) {
console.log(JSON.stringify(instance));
});
Batch retrieval for multiple instances:
var requests = [
{ $entity: E1, id11: 1, id2: 2 },
{ $entity: E2, id: "key" }, ...
];
tx.$getAll(requests, function(error, instances) {
console.log("e1 = " + JSON.stringify(instances[0]);
console.log("e2 = " + JSON.stringify(instances[1]);
});
Syntactic sugar for above:
var requests = [
E1.$prepare({ id1: 1, id2: 2 }),
E2.$prepare({ id: "key" }), ...
];
tx.$getAll(requests, ...);
Retrieve entity instances by condition:
tx.$find(E1, { value: { $gt: 69 } }, function(error, instances) {
console.log("found " + instance.length + " instances");
});
Batch retrieval by condition:
tx.$findAll([
{ $entity: E1, { prop: { $eq: 1 } },
{ $entity: E2, { prop: { $ne: 2 } }
], callback);
Note that the result of `$findAll` is an array of arrays; to flatten the result
set you may use
var flattenedInstanceArray = [].concat.apply([], findAllResult));
For complex data types you need to supply a comparison function using `$using` that
compares their values in JavaScript:
tx.$find(E1, { prop: { $lt: "1.0e-10", $using: function(arg1, arg2) {
return Math.sign(parseFloat(arg1) - parseFloat(arg2));
} }, callback);
A comparison function takes two arguments and returns values `< 0`, `== 0`, or `> 0`
depending on their relation to each other.
Create new instance:
tx.$save({ $entity: E, key: 1, value: "hello world" }, function(error, instance) {
if (!error)
console.log("instance created");
});
Batch creation:
var newinsts = [
{ $entity: E1, id1: 1, value: 2 },
E2.$prepare({ id: "new", value: 4 }), ...
];
tx.$saveAll(newinsts, function(error, instances) {
console.log("" + instances.length + " instances created");
});
Update existing instance:
instance.value++;
tx.$save(instance, function (error, savedInstance) {
if (!error)
console.log("instance updated");
});
Batch update:
tx.$saveAll([ instance1, instance2, ... ], function (error, instances) {
console.log("instances updated");
});
Discard entity instances:
tx.$discard(instance, function(error) {
if (error)
console.error("Error discarding instance: " + error);
});
Batch discard:
tx.$discardAll([ instance1, instance2, ...], function(error) {
if (error)
console.error("Error discarding instances: " + error);
});
Unmanaged delete:
tx.$delete(entity, condition, callback);
*CAUTION!* Unmanaged `delete`s bypass the cache and will not cascade to
target instances! The `$delete` method is merely syntactic sugar for
`$query().$matching().$delete()`!
### Associations
Adding via backlink 1:n associations:
cds.importEntities([{
$entity: "cds.test::parent",
$fields: {
BacklinkAssoc: {
$association: {
$entity: "cds.test::target",
$viaBacklink: "backassoc"
}
}
}
}], callback);
Adding via entity m:n associations:
cds.importEntities([{
$entity: "cds.test::parent",
$fields: {
BacklinkAssoc: {
$association: {
$entity: "cds.test::target",
$viaEntity: "cds.test::link",
$source: "sourceassoc",
$target: "targetassoc"
}
}
}
}], callback);
Declaring lazy associations:
cds.importEntities([{
$entity: "cds.test::parent",
$fields: {
LazyAssoc: {
$association: {
$lazy: true
}
}
}
], callback);
Lazy retrieval of lazy associations:
instance.lazyAssoc.$load(function (error, targets) {
// targets == instance.lazyAssoc
console.log("" + targets.length + " targets retrieved");
});
Re-syncing backlinking and unmanaged associations
instance.unmanagedAssoc.$reload(function (error, targets) {
// targets == instance.unmanagedAssoc
console.log("association has " + targets.length + " targets");
});
### Unmanaged Queries
Basic query:
E1.$query().$matching({ key: 1 })
.$execute({}, function(error, result) {
console.log("result = " + JSON.stringify(result);
});
More complex query conditions:
E1.$query().$matching({ value1: { $lt: 42 }, value2: { $null: true } })
.$execute({}, function(error, result) {
console.log("result = " + JSON.stringify(result);
});
Projection and navigation:
E2.$query().$matching({ key: 1 })
.$project({ value1: true, assoc: { value2: true, value3: true })
.$execute({}, function(error, result) { ... });
Stream interface:
E1.$query().$execute({ $stream: true }, function(error, stream) {
stream.on('data', function(chunk) {
console.log(chunk);
}).on('end', function() {
console.log("done");
});
});
See the [docs](https://<TODO ADD LINK>/APIs/) for more.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc