Comparing version 2.8.1 to 2.9.1
@@ -1,175 +0,22 @@ | ||
import core from "./core"; | ||
import CSN from "./csn"; | ||
import QL from "./cds-ql"; | ||
import { DataSource } from "./connect"; | ||
declare const cds : cds_facade | ||
export = cds | ||
/** This is the central entry point to cds. */ | ||
class cds extends core.cds { | ||
// Models | ||
/** https://coreds.github.io/API/#cdsget */ | ||
get (id:string, parent?:{id:string, filename?:string}) : Promise<CSN.Model> | ||
type cds_facade = DataSource //> after cds.connect() | ||
& typeof import ("./models") | ||
& typeof import ("./reflect") | ||
& typeof import ("./connect") | ||
& typeof import ("./services") | ||
/** https://coreds.github.io/API/#cdsparse */ | ||
parse : { | ||
cdl (src:string) : CSN.Model | ||
cql (src:string) : CSN.Query | ||
expr (src:string) : CSN.Expression | ||
} | ||
/** https://coreds.github.io/API/#cdsunfold */ | ||
unfold: { | ||
all (model:CSN.Model) : linked.Model | ||
localized (model:CSN.Model) : linked.Model | ||
compositions (model:CSN.Model) : linked.Model | ||
toMany (model:CSN.Model) : linked.Model | ||
toOne (model:CSN.Model) : linked.Model | ||
} | ||
/** https://coreds.github.io/API/#cdscheck */ | ||
check (model:CSN.Model) : linked.Model | ||
/** https://coreds.github.io/API/#cdsinferred */ | ||
inferred (model:CSN.Model) : linked.Model | ||
/** https://coreds.github.io/API/#cdscompile */ | ||
compile : { | ||
to: { | ||
json (model:CSN.Model) : string | ||
yaml (model:CSN.Model) : string | ||
cdl (model:CSN.Model) : string | ||
sql (model:CSN.Model) : string | ||
odata (model:CSN.Model) : CSN.Model | ||
edm (model:CSN.Model) | ||
edmx (model:CSN.Model) | ||
} | ||
} | ||
// Runtime | ||
Session = Session | ||
ql = QL | ||
odata = cds_odata | ||
// Shortcuts & Helpers | ||
load (m,p) : linked.Model | ||
clone (m) : CSN.Model | ||
options() : { | ||
data : ConnectOptions, | ||
odata : {} | ||
} | ||
in (cwd) : cds | ||
} | ||
export = new cds | ||
import QL from "./ql" | ||
declare global { | ||
const { SELECT, INSERT, UPDATE, DELETE, CREATE, DROP } = QL | ||
const cds = new cds | ||
const cds : cds_facade | ||
const SELECT : QL.SELECT | ||
const INSERT : QL.INSERT | ||
const UPDATE : QL.UPDATE | ||
const DELETE : QL.DELETE | ||
const CREATE : QL.CREATE | ||
const DROP : QL.DROP | ||
} | ||
//-------------------------------------------------------------------------- | ||
// QL Sessions | ||
export class Session { | ||
connect (options? : ConnectOptions) : this | ||
deploy (options? : ConnectOptions) : this | ||
run (stmts) : Promise<any> | ||
foreach (stmt, callback) : this | ||
then (callback) : this | ||
catch (callback) : this | ||
} | ||
type ConnectOptions = { | ||
/** A module name of a driver implementation to use. */ | ||
driver?:string, | ||
database?:string, | ||
model?:string, | ||
log?:string | ||
} | ||
//-------------------------------------------------------------------------- | ||
// OData | ||
const cds_odata : { | ||
load (model:string) : linked.Model | ||
model (model:CSN.Model) : CSN.Model | ||
query (url:string) : object | ||
config (options:{entitySet:string}) | ||
/** | ||
* Constructs an OData service for the given model. | ||
* @param model the filename, relative to cwd, of a CDS model defining a service | ||
* @param options optional object with options, such as .impl | ||
* @param impl an init function to register custom handlers | ||
*/ | ||
service ( | ||
model:string, | ||
options?: { impl: string }, | ||
impl?: ServiceImpl | ||
) : ServiceProvider | ||
log: { all (req,res,next) } | ||
to: { | ||
edm (model:CSN.Model) : string | ||
} | ||
} | ||
interface ServiceProvider { | ||
on (op: CRUDx, entity?: Target, handler?: RequestHandler) : this | ||
before (op: CRUDx, entity?: Target, handler?: RequestHandler) : this | ||
after (op: CRUDx, entity?: Target, handler?: ResultsHandler) : this | ||
reject (ops: CRUD | CRUD[], ...entity: Target[]) : this | ||
} | ||
type Target = linked.Definition | string | ||
type CRUDx = CRUD | string | ||
enum CRUD { | ||
'CREATE', 'READ', 'UPDATE', 'DELETE', 'COMMIT', 'ROLLBACK' | ||
} | ||
class ServiceDefinition extends linked.Definition { | ||
/** | ||
* Wraps a service implementation function to support IntelliSense in vscode. | ||
* It does nothing but simply returns the passed in function. | ||
* | ||
* @param fn the service implementation function. Within it's body... | ||
* - this refers to the current instance of cds.odata.service, used to register custom handlers. | ||
* - 1st arg refers to the entity definitions in the service's CSN | ||
*/ | ||
static impl (fn: ServiceImpl) : typeof fn | ||
/** | ||
* Constructs a new service provider for the given model. | ||
* @param model the filename, relative to cwd, of a CDS model defining a service | ||
* @param options optional object with options, such as .impl | ||
* @param impl an init function to register custom handlers | ||
*/ | ||
static provider ( | ||
model:string, | ||
options?: { impl: string }, | ||
impl?: ServiceImpl | ||
) : ServiceProvider | ||
} | ||
/** | ||
* A service implementation function. | ||
* @param this - the ODataService | ||
* @param entities - | ||
*/ | ||
interface ServiceImpl { | ||
(this: ServiceProvider, entities: linked.Definitions) | ||
} | ||
interface RequestHandler { | ||
(req) | ||
} | ||
interface ResultsHandler { | ||
(results : any[]) | ||
(each : any) | ||
} | ||
//-------------------------------------------------------------------------- |
@@ -118,6 +118,6 @@ module.exports = Object.assign ( build, { | ||
const service = config.service || {} | ||
service.odata = service.odata || {} | ||
const version = service.odata.version || DEFAULT_ODATA_VERSION | ||
const suffix = (service.odata.edmxFileSuffix === undefined ? | ||
DEFAULT_ODATA_FILE_SUFFIX : service.odata.edmxFileSuffix) + '.xml' | ||
const odata = config.odata || {} | ||
const version = odata.version || DEFAULT_ODATA_VERSION | ||
const suffix = (odata.edmxFileSuffix === undefined ? | ||
DEFAULT_ODATA_FILE_SUFFIX : odata.edmxFileSuffix) + '.xml' | ||
const ui = config.ui || {} | ||
@@ -124,0 +124,0 @@ |
@@ -27,7 +27,7 @@ const path = require('path'); | ||
service: 'all' | ||
}, options, options.odata) | ||
}, options, this.config.odata) | ||
o.sql_mapping = this.config.data.sql_mapping | ||
// csn for service providers | ||
let csn = this.unfold.for.odata(m, o) | ||
let csn = this.compile(m).for('odata',o) | ||
this.write(csn).to('csn.json') | ||
@@ -34,0 +34,0 @@ |
@@ -6,6 +6,16 @@ const path = require('path') | ||
conf: 'service', | ||
dest: '${folder}/gen', //NOSONAR | ||
dest: '${folder}/gen', //NOSONAR, | ||
prebuild, | ||
build | ||
} | ||
function prebuild(options) { | ||
if (this.resolve(path.join(options.folder, 'package.json')) && this.config.data && this.config.data.includeServiceViews !== false) { | ||
const db = this.all.find(m => m.category === 'db') // REVISIT: what to do in case of more than one db module? | ||
if (db) db.models.push(...options.models) | ||
} | ||
} | ||
function build (options) { | ||
@@ -12,0 +22,0 @@ const srvPath = this.resolve(path.join(options.folder, 'package.json')) |
@@ -46,3 +46,3 @@ #!/usr/bin/env node | ||
} catch (err) { | ||
args.unshift(cmd) | ||
if (cmd) args.unshift(cmd) | ||
cmd = './compile' | ||
@@ -55,3 +55,3 @@ } | ||
const {argv, options} = cli.parseArgs(cmd, args) | ||
if (options['sql']) require ('../lib/index.js').config.data.sql_mapping = options.sql | ||
@@ -58,0 +58,0 @@ if (options['new-csn']) require ('../lib/index.js').config.build.new_csn = true |
@@ -105,16 +105,17 @@ module.exports = Object.assign ( compile, { | ||
if (typeof models === 'string') models = [models] | ||
if (Array.isArray(models)) { | ||
if (!models[0]) return Promise.reject ('You must specify a model to compile!') | ||
if (Array.isArray(models) && models.length > 0) { // any arguments? | ||
chain = cds.load (models, options) | ||
src = models[0] .replace (/\.[^.]+$/,'') //> excluding source file extension, e.g. .cds | ||
} else { | ||
chain = Promise.resolve (models) | ||
src = 'output' | ||
src = models[0] .replace (/\.[^.]+$/,'') //> excluding source file extension, e.g. .cds | ||
} else if (!process.stdin.isTTY && process.argv[1].endsWith('cds')) { // else check for stdin | ||
chain = readModelFromStdin() | ||
src = 'stdin' | ||
} else { // no args, no stdin | ||
return Promise.reject ('You must specify a model to compile!') | ||
} | ||
if (options.unfold) for (let each of options.unfold.split(',')) { | ||
chain = chain.then (next (processor4 (cds.unfold, each))) | ||
chain = chain.then (next (processor4 (cds.compile.for, each))) | ||
} | ||
if (options.for) { | ||
chain = chain.then (next (processor4 (cds.unfold.for, options.for))) | ||
chain = chain.then (next (processor4 (cds.compile.for, options.for))) | ||
} | ||
@@ -161,5 +162,12 @@ if (options.lang) { | ||
function readModelFromStdin(){ | ||
return new Promise ((_resolved, _error) => { | ||
let src=""; process.stdin | ||
.on ('data', chunk => src += chunk) | ||
.on ('end', ()=> _resolved (src[0] === '{' ? JSON.parse(src) : cds.parse(src))) | ||
.on ('error', _error) | ||
}) | ||
} | ||
} | ||
function suffix4 (x) { return x && ({ | ||
@@ -166,0 +174,0 @@ edmx: '.xml', |
@@ -99,3 +99,3 @@ module.exports = Object.assign ( dev, { | ||
let isnew = false | ||
const projects = pck['sub-projects'] || (pck['sub-projects'] = | ||
const projects = pck['projects'] || (pck['projects'] = | ||
/cd[sx]/.test (pck.name) ? require('./.dev-internal.js') : isnew = { | ||
@@ -160,4 +160,4 @@ ">>>>": "specify your sub projects with local folder and git repo link as in the examples below...", | ||
function pull(){ | ||
process.stdout.write ('Pulling latest updates from sub-projects... ') | ||
const root = process.cwd(), projects = pck['sub-projects'] | ||
process.stdout.write ('Pulling latest updates from projects... ') | ||
const root = process.cwd(), projects = pck['projects'] | ||
return Object.entries(projects) .reduce ((prev,[dest,url]) => prev.then (()=>{ | ||
@@ -164,0 +164,0 @@ let [repo, branch='master'] = url.replace('git://','https://').split('#') |
@@ -15,3 +15,3 @@ module.exports = Object.assign (repl, { options: [], help: ` | ||
const fs = require('fs') | ||
const util = require('util') | ||
const {inspect} = require('util') | ||
@@ -28,10 +28,20 @@ function repl (_, options={}) { | ||
function print (o) { | ||
if (o && o.then && !(o instanceof cds.ql.BaseStatement)) { | ||
if (o == null || typeof o === 'string') return o | ||
if (o._isQuery) for (let x in o) { | ||
const v = o[x]; if (typeof v === 'function') continue | ||
return inspect ({[x]:v}, {colors, depth: 22}) | ||
.replace(/{ ref: \[([^\]]*)\] }/g, (_,ref) => '{ref:['+ref.slice(1,-1)+']}') | ||
.replace(/{ val: ([^ ]*) }/g, '{val:$1}') | ||
.replace(/{ (xpr|ref|val): /g, '{$1:') | ||
} | ||
if (o.then) { | ||
o.then (r => { if (r) log(print(r)) }) | ||
return '[async:]' | ||
} | ||
// for strings we assume they are pre-formatted, don't mess them up with util.inspect | ||
if (typeof o === 'string') return o | ||
// for others install cds inspect | ||
return util.inspect(require('./utils/format').install(o), {colors, depth: 11}) | ||
// REVISIT: wow, das ist aber recht teuer! | ||
return inspect(require('./utils/format').install(o), {colors, depth: 11}) | ||
.replace(/{ ref: \[([^\]]*)\] }/g, (_,ref) => '{ref:['+ref.slice(1,-1)+']}') | ||
.replace(/{ val: ([^ ]*) }/g, '{val:$1}') | ||
@@ -41,4 +51,4 @@ .replace(/{ (xpr|ref|val): /g, '{$1:') | ||
Object.assign (repl.context, {cds}) | ||
Object.defineProperties (repl.context, { | ||
cds: {value:cds}, | ||
SELECT: {get:()=> cds.ql.SELECT}, | ||
@@ -45,0 +55,0 @@ INSERT: {get:()=> cds.ql.INSERT}, |
@@ -12,3 +12,3 @@ module.exports.parseArgs = (cmd, args) => { | ||
for (let i = 0; i < args.length; ++i) { | ||
if (args.length>0) for (let i = 0; i < args.length; ++i) { | ||
let a = args[i] | ||
@@ -15,0 +15,0 @@ let ox = _shortcuts.indexOf(a) |
@@ -9,11 +9,21 @@ # Change Log | ||
## Version 2.9.1 | ||
### Fixes | ||
- `cds build` no longer blocks if running inside a Maven build. | ||
## Version 2.8.1 | ||
## Version 2.9.0 | ||
### Added | ||
- `common.cds` model got annotations for title, description, and value lists. | ||
- `cds` executable now can read from stdin, e.g. `echo 'entity Foo {ID:UUID;}' | cds -2 sql` | ||
- `cds -2 sql` now outputs plain (non-HANA) SQL. Use `-2 hana` for HANA SQL. | ||
- `cds config` shows the current CDS configuration. Use `cds help config` to learn more. | ||
### Fixes | ||
- Packages `@sap/cds-ql` and `@sap/cds-services` are now found. | ||
- Implementations connected to services through `@impl` are resolved correctly. | ||
- Entities from `common.cds` like `Languages`, `Countries`, and `Currencies` are now only persisted to the database if they are actually used. | ||
### Also see | ||
- Changes of `@sap/cds-ql` 0.9.1 | ||
- Changes of `@sap/cds-services` 0.9.2 | ||
- Changes of `@sap/cds-compiler` 1.1.2 | ||
- Changes of `@sap/cds-reflect` 1.6.0 | ||
- Changes of `@sap/cds-ql` 0.10.0 | ||
- Changes of `@sap/cds-services` 0.10.1 | ||
@@ -20,0 +30,0 @@ ## Version 2.8.0 |
@@ -1,34 +0,26 @@ | ||
const core = require ('@sap/cds-reflect/lib/core'); (()=> require = core.lazy(require))() // eslint-disable-line | ||
const cds = module.exports = Object.assign ( core, { | ||
const core = require ('@sap/cds-reflect'), $=require; require = (id)=> lazy=> $(id) // eslint-disable-line | ||
const cds = module.exports = global.cds = Object.assign ( core, { | ||
// Models | ||
resolve: require ('./models/resolve'), | ||
get: require ('./models/get'), | ||
load: lazy => cds.get.all, | ||
parse: require ('./models/parse'), | ||
unfold: require ('./models/unfold'), | ||
compile: require ('./models/compile'), | ||
localize: require ('./models/i18n'), | ||
// Model Processing | ||
resolve: require ('./models/resolve'), | ||
load: require ('./models/load'), | ||
parse: require ('./models/parse'), | ||
compile: require ('./models/compile'), | ||
localize: require ('./models/i18n'), | ||
unfold: lazy => cds.compile, | ||
get: lazy => cds.load.only, | ||
// Services | ||
service: require ('./service/provider'), | ||
serve: require ('./service/serve'), | ||
client: require ('./service/client'), | ||
// Services and Querying | ||
connect: require ('./runtime/connect'), | ||
serve: require ('./runtime/serve'), | ||
ql: lazy => cds.connect.ql, | ||
// Data Access | ||
Session: require ('./connect/session'), | ||
connect: require ('./connect'), | ||
ql: require('./connect/ql'), | ||
// Helpers | ||
in: cwd => !cwd ? cds : {__proto__:cds, cwd, config:cds.config.in(cwd) }, | ||
require: require ('./utils/require-local'), | ||
config: require ('./utils/config'), | ||
write: require ('./utils/write'), | ||
home: lazy => __dirname.slice(0,-4), | ||
version: lazy => require('../package.json').version, | ||
// Helpers | ||
in: cwd => !cwd ? cds : {__proto__:cds, cwd, config:cds.config.in(cwd) }, | ||
cwd: lazy => process.cwd(), | ||
config: require('./utils/config'), | ||
write: require ('./utils/write'), | ||
require: require ('./utils/require-local'), | ||
version: lazy => require._('../package.json').version, | ||
home: lazy => require._('path').dirname (__dirname), | ||
build: require ('../bin/build/all') | ||
}) | ||
cds.lazify() | ||
}) .lazify() |
@@ -5,12 +5,16 @@ const cds = require('../index') | ||
const conf = cds.config && cds.config.cdsv || {} | ||
const _ = o => Object.assign (o||{},conf) | ||
module.exports = { | ||
parse: (...args) => _csn4 (cdsv.compileSources (...args)), | ||
parseToCqn: cdsv.parseToCqn, | ||
parseToExpr: cdsv.parseToExpr, | ||
collectSources: (...args) => cdsv.collectSources(...args), | ||
compile: (...args) => cdsv.compile(...args) .then (_csn4), | ||
forOData: (csn,o) => _csn4x(csn,o,'odata'), | ||
forSql: (csn,o) => _csn4x(csn,o,'sql'), | ||
forSql: (csn,o) => _csn4x(csn,_(o),'sql'), | ||
toHana: (csn,o) => cdsv.toHana(_xsn4(csn),o), | ||
toCdl: (csn,o) => cdsv.toCdl(_xsn4(csn),o), | ||
toSql: (csn,o) => cdsv.toSql(_xsn4(csn),o), | ||
toSql: (csn,o) => cdsv.toSql(_xsn4(csn),_(o)), | ||
toSwagger: (csn,o) => cdsv.toSwagger (_xsn4(csn),o), | ||
@@ -17,0 +21,0 @@ toOdata: (csn,o) => cdsv.toOdata (_xsn4(csn),o), |
@@ -8,8 +8,21 @@ const cdsv = require('./cdsv') | ||
// Fluent API, i.e. compile(csn).to('yml') --> see also: https://bit.ly/capire/APIs#cds-compile) | ||
const compile = (csn) => ({ to:(x,o) => { | ||
let fn = compile.to[x]; if (!fn) throw new TypeError (`cds.compile.to.${x} is not defined`) | ||
if (typeof csn === 'string') csn = cds.parse (csn) | ||
return fn (csn,o) | ||
}}) | ||
const compile = (csn) => ({ | ||
for:(x,o) => _fluent (compile_for,x, csn,o), | ||
to:(x,o) => _fluent (compile_to,x, csn,o), | ||
}) | ||
function _fluent (compile_, to_or_for, csn, o) { | ||
let fn = compile_[to_or_for]; if (!fn) throw new TypeError (`cds.compile.for.${to_or_for} is not defined`) | ||
if (typeof csn === 'string') csn = cds.parse (csn) | ||
return fn (csn,o) | ||
} | ||
// Dedicated API, i.e. compile.for.sql('csn') | ||
const compile_for = { | ||
odata: (csn, o) => cdsv.forOData(csn, o), | ||
sql: (csn, o) => cdsv.forSql(csn, o) | ||
} | ||
// Dedicated API, i.e. compile.to.yml('csn') | ||
@@ -20,5 +33,5 @@ const compile_to = { | ||
yml: YAML.stringify, | ||
sql: (csn,o={}) => _2sqlOut(cdsv.toSql(csn,o).sql,o), | ||
sql: (csn,o={}) => _2sqlOut(cdsv.toSql(_skipUnused(csn),o).sql,o), | ||
cdl: (csn,o={}) => _2structuredOut(cdsv.toCdl(csn,o),'.cds'), | ||
hana: (csn,o={}) => _many (cdsv.toHana(csn,toHanaOptions(o)).hdbcds, o, '.hdbcds'), | ||
hana: (csn,o={}) => _many (cdsv.toHana(_skipUnused(csn),toHanaOptions(o)).hdbcds, o, '.hdbcds'), | ||
edm: (csn,o={}) => _2odata (csn,o, 'metadata_json'), | ||
@@ -31,2 +44,16 @@ edmx: (csn,o={}) => _2odata (csn,o, {off: 'metadata', only: 'annotations'}[o.annos] || 'combined'), | ||
function _skipUnused (csn) { | ||
const m = cds.linked (csn) | ||
m.foreach (e => e instanceof cds.entity && !e.abstract && e['@cds.persistence.skip']=='if-unused', e => { | ||
let refs = 0; m.foreach (a => a._target === e, (ref, [parent]) => { | ||
if (parent instanceof cds.entity) ++refs | ||
}) | ||
if (!refs) { | ||
delete csn.definitions [e.name] | ||
if (csn._xsn) delete csn._xsn.definitions [e.name] | ||
} | ||
}) | ||
return csn | ||
} | ||
const suffixes = { | ||
@@ -136,2 +163,2 @@ cdl: '.cds', | ||
module.exports = Object.assign (compile, { to: compile_to, suffixes }) | ||
module.exports = Object.assign (compile, { to: compile_to, for: compile_for, suffixes }) |
@@ -7,6 +7,7 @@ const cds = require ('../index') | ||
const DefaultLanguage = cds.config.i18n.default_language || 'en' | ||
const FallbackBundle = cds.config.i18n.fallback_bundle || '' | ||
const I18nFolders = cds.config.i18n.folders || [ '_i18n', 'i18n' ] | ||
const I18nFile = cds.config.i18n.file || 'i18n' | ||
const conf = cds.config && cds.config.i18n || {} | ||
const DefaultLanguage = conf.default_language || 'en' | ||
const FallbackBundle = conf.fallback_bundle || '' | ||
const I18nFolders = conf.folders || [ '_i18n', 'i18n' ] | ||
const I18nFile = conf.file || 'i18n' | ||
const CachedFolders = {} | ||
@@ -13,0 +14,0 @@ |
@@ -8,6 +8,14 @@ /** Both, a namespace and a shortcut for cds.parse.cdl */ | ||
/** @returns {object} the parsed query as a CQN object */ | ||
cql: (src,o) => (parse.cql = _require('../connect/cql-parser').parse) (src,o), | ||
cql: (src,o) => (parse.cql = _require('../runtime/cql-parser').parse) (src,o), | ||
/* | ||
* Change to following once it supports SQL and simplified CQL | ||
* cql: (...args) => (parse.cql = _require('./cdsv').parseToCqn) (...args), | ||
*/ | ||
/** @returns {object} the parsed expression as a CQN expr object */ | ||
expr: (src) => parse.cql (src, {startRule:'XPR'}), | ||
/* | ||
* Change to following once it supports inline as a filter | ||
* expr: (...args) => (parse.expr = _require('./cdsv').parseToExpr) (...args), | ||
*/ | ||
@@ -18,2 +26,2 @@ xpr: x => parse.expr(x).xpr, | ||
}) | ||
const _require = require // workaround for vscode IntelliSense | ||
const _require = require // workaround for vscode IntelliSense |
const path = require('path') | ||
const fs = require('fs') | ||
const cwd = process.cwd() | ||
@@ -10,3 +11,3 @@ module.exports = function cds_resolve (model, options={}) { | ||
)) | ||
const base = path.resolve (options.root || this.cwd, model) | ||
const base = path.resolve (options.root || this.cwd || cwd, model) | ||
@@ -13,0 +14,0 @@ // ... use an existing file under the given name w/ suffix .csn, .cds or .json |
module.exports = { | ||
"service": { | ||
"odata": { | ||
"version": "v2" | ||
} | ||
build: { version: 1.4 }, | ||
data: { sql_mapping:"plain" }, | ||
odata: { version:"v2" }, | ||
service: {}, | ||
i18n: { | ||
folders: ['_i18n', 'i18n', 'assets/i18n'], | ||
default_language: 'en' | ||
}, | ||
"data": { | ||
"sql_mapping": "plain" | ||
}, | ||
"i18n": { | ||
"folders": ['_i18n', 'i18n', 'assets/i18n'], | ||
"default_language": 'en' | ||
}, | ||
"build": { | ||
"version": 1.4 | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
const env = process.env.NODE_ENV || process.env.CDS_ENV || 'dev' | ||
const defaults = require('./_defaults') | ||
const ENV = '['+( process.env.NODE_ENV || process.env.CDS_ENV || 'dev' )+']' | ||
const DEFAULTS = require.resolve ('./_defaults'), defaults = require(DEFAULTS) | ||
const home = require('os').homedir() | ||
@@ -10,10 +10,18 @@ const path = require('path') | ||
*/ | ||
class CDSConfig { | ||
const Config = [ class { | ||
constructor(){ Object.assign (this,defaults) } | ||
constructor(){ | ||
_clone (defaults, /*into:*/ this) | ||
Object.defineProperty (this, '_source', {value:[DEFAULTS]}) | ||
} | ||
/** | ||
* @returns {Config} | ||
*/ | ||
in (cwd) { return cached[cwd] || ( | ||
cached[cwd] = (new CDSConfig) | ||
cached[cwd] = (new Config) | ||
.load (home, '.cdsrc') | ||
.load (cwd,'package.json', p => p.cds) | ||
.load (cwd, '.cdsrc') | ||
.load (cwd, 'package.json', p => p.cds) | ||
.load ('$','CDS_CONF', JSON.parse) | ||
)} | ||
@@ -23,6 +31,7 @@ | ||
try { | ||
const src = path.resolve (cwd, res) | ||
const conf = _conf (require (src)) | ||
const env = cwd == '$' && (process.env[res] || '0') | ||
const src = env ? '$'+res : require.resolve (path.join(cwd, res)) | ||
const conf = _conf (env || require (src)) | ||
if (conf) { | ||
(this._source||(this._source = [])) .push (src) | ||
this._source.push (src) | ||
this.add (conf) | ||
@@ -33,21 +42,43 @@ } | ||
} | ||
return this | ||
return _fix (this) | ||
} | ||
add (conf) { | ||
for (let p in conf) { | ||
if (p === '['+env+']') this.add(conf[p]) | ||
else if (Array.isArray(conf[p])) this[p] = (this[p] || []).concat(conf[p]) | ||
else if (typeof conf[p] === 'object') this[p] = Object.assign({}, this[p], conf[p]) | ||
else this[p] = conf[p] | ||
add (_overlay, /*to:*/ conf=this) { | ||
let _profile = undefined | ||
for (let p in _overlay) { | ||
const v = _overlay[p] | ||
if (p[0] == '[') { if (p === ENV) _profile = v } | ||
else if (Array.isArray(v)) conf[p] = (conf[p]||[]) .concat (v) | ||
else if (typeof v === 'object' && p in conf) this.add (v, /*to:*/ conf[p]) | ||
else conf[p] = v | ||
} | ||
return this | ||
if (_profile) this.add (_profile, /*to:*/ conf) | ||
return conf | ||
} | ||
get (path='') { | ||
return path.split('.').reduce ((p,n)=> p && p[n], this) | ||
} | ||
for (conf) { | ||
return (new CDSConfig) .add (conf) | ||
return _fix ((new Config) .add (conf)) | ||
} | ||
} ][0] //> to make this a nameless class | ||
function _clone (o, /*into*/ conf) { | ||
for (let p in o) { | ||
const v = o[p] | ||
conf[p] = ( typeof v === 'object' && !Array.isArray(v) ) ? _clone(v,{}) : v | ||
} | ||
return conf | ||
} | ||
module.exports = (new CDSConfig) .in (process.cwd()) | ||
function _fix (conf) { | ||
if (conf.service.odata) conf.odata = conf.service.odata | ||
return conf | ||
} | ||
module.exports = (new Config) .in (process.cwd()) |
const resolve = require('module')._resolveFilename | ||
const path = require('path') | ||
const cwd = process.cwd() | ||
module.exports = function (id, options={}) { | ||
// this = cds or a derivate of it | ||
try { id = resolve (id, _paths4(this.cwd)) } catch (e) {_ignoreNotFound(e)} | ||
try { id = resolve (id, _paths4(this.cwd || cwd)) } catch (e) {_ignoreNotFound(e)} | ||
try { return require(id) } catch (e) {_ignoreNotFound(e) | ||
@@ -8,0 +9,0 @@ if (options.else) return options.else |
{ | ||
"name": "@sap/cds", | ||
"version": "2.8.1", | ||
"lockfileVersion": 1, | ||
"requires": true, | ||
"version": "2.9.1", | ||
"dependencies": { | ||
"@sap/cds-compiler": { | ||
"version": "1.1.1", | ||
"requires": { | ||
"ajv": "6.1.1", | ||
"antlr4": "4.7.1", | ||
"commander": "2.14.0", | ||
"fs-extra": "5.0.0", | ||
"resolve": "1.5.0", | ||
"sax": "1.2.4" | ||
} | ||
"version": "1.1.2" | ||
}, | ||
"@sap/cds-hana": { | ||
"version": "0.7.1", | ||
"requires": { | ||
"@sap/cds-sql": "0.9.2" | ||
} | ||
"version": "0.8.0" | ||
}, | ||
"@sap/cds-ql": { | ||
"version": "0.9.1", | ||
"requires": { | ||
"@sap/cds-hana": "0.7.1", | ||
"@sap/cds-sql": "0.9.2", | ||
"@sap/cds-sqlite": "0.7.1", | ||
"generic-pool": "3.4.2", | ||
"uuid": "3.2.1" | ||
} | ||
"version": "0.10.0" | ||
}, | ||
"@sap/cds-reflect": { | ||
"version": "1.5.1" | ||
"version": "1.6.0" | ||
}, | ||
"@sap/cds-services": { | ||
"version": "0.9.2", | ||
"requires": { | ||
"@sap/cds-ql": "0.9.1", | ||
"@sap/odata-v4": "^1.6.0" | ||
} | ||
"version": "0.10.1" | ||
}, | ||
"@sap/cds-sql": { | ||
"version": "0.9.2" | ||
"version": "0.10.0" | ||
}, | ||
"@sap/cds-sqlite": { | ||
"version": "0.7.1", | ||
"requires": { | ||
"@sap/cds-sql": "0.9.2" | ||
} | ||
"version": "0.8.0" | ||
}, | ||
"@sap/odata-v4": { | ||
"version": "1.6.1", | ||
"requires": { | ||
"big.js": "=5.1.2", | ||
"xmlbuilder": "=10.0.0" | ||
} | ||
"version": "1.7.0" | ||
}, | ||
"ajv": { | ||
"version": "6.1.1", | ||
"requires": { | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
"version": "6.1.1" | ||
}, | ||
@@ -78,3 +42,3 @@ "antlr4": { | ||
"fast-deep-equal": { | ||
"version": "1.1.0" | ||
"version": "1.0.0" | ||
}, | ||
@@ -85,8 +49,3 @@ "fast-json-stable-stringify": { | ||
"fs-extra": { | ||
"version": "5.0.0", | ||
"requires": { | ||
"graceful-fs": "^4.1.2", | ||
"jsonfile": "^4.0.0", | ||
"universalify": "^0.1.0" | ||
} | ||
"version": "5.0.0" | ||
}, | ||
@@ -103,15 +62,9 @@ "generic-pool": { | ||
"jsonfile": { | ||
"version": "4.0.0", | ||
"requires": { | ||
"graceful-fs": "^4.1.6" | ||
} | ||
"version": "4.0.0" | ||
}, | ||
"path-parse": { | ||
"version": "1.0.6" | ||
"version": "1.0.5" | ||
}, | ||
"resolve": { | ||
"version": "1.5.0", | ||
"requires": { | ||
"path-parse": "^1.0.5" | ||
} | ||
"version": "1.5.0" | ||
}, | ||
@@ -118,0 +71,0 @@ "sax": { |
@@ -1,1 +0,1 @@ | ||
{"bin":{"cds":"bin/cds.js"},"bundleDependencies":false,"dependencies":{"@sap/cds-compiler":"1.1.1","@sap/cds-ql":"0.9.1","@sap/cds-reflect":"1.5.1","@sap/cds-services":"0.9.2","fs-extra":"5.0.0"},"deprecated":false,"description":"Entry Point and API Facade for CDS","devDependencies":{"eslint":"^4.19.0","express":"^4.16.2","hasbin":"^1.2.3","jest":"^23.4.0","jest-junit":"^5.1.0","sqlite3":"4.0.1","supertest":"^3.0.0"},"engines":{"node":">= 6.12.0"},"jest":{"testEnvironment":"node","reporters":["default","jest-junit"],"roots":["<rootDir>/bin/","<rootDir>/lib/","<rootDir>/tests/"],"moduleDirectories":["node_modules"],"modulePathIgnorePatterns":["/_out/","/edmx/","/projects/"],"moduleFileExtensions":["js","json","cds","properties"],"coverageDirectory":"reports/coverage","coverageReporters":["lcov","text"],"collectCoverageFrom":["lib/**","bin/**","!bin/init/**","!**/*.json"],"testPathIgnorePatterns":["/node_modules/","/integration/"],"verbose":true},"jest-junit":{"suiteName":"jest tests","output":"reports/sonar/test-reporter.xml","classNameTemplate":"{classname}-{title}","titleTemplate":"{classname}-{title}","ancestorSeparator":" › ","usePathForSuiteName":"true"},"main":"lib/index.js","name":"@sap/cds","scripts":{"beforePublish":"rm bin/.dev-internal.js","dedupe":"npm dedupe","lint":"eslint .","test":"jest --coverage && npm run test:new && npm run lint","test:all":"jest --coverage --testPathIgnorePatterns /node_modules/","test:integration":"jest --testRegex integration.*\\.js --testPathIgnorePatterns /node_modules/","test:new":"jest --testRegex test-new\\.js","test:watch":"jest --watchAll"},"typings":"apis/cds.d.ts","version":"2.8.1","license":"SEE LICENSE IN developer-license-3.1.txt"} | ||
{"bin":{"cds":"bin/cds.js"},"bundleDependencies":false,"dependencies":{"@sap/cds-compiler":"1.1.2","@sap/cds-ql":"0.10.0","@sap/cds-reflect":"1.6.0","@sap/cds-services":"0.10.1","fs-extra":"5.0.0"},"deprecated":false,"description":"Entry Point and API Facade for CDS","devDependencies":{"eslint":"^4.19.0","express":"^4.16.2","hasbin":"^1.2.3","jest":"^23.4.0","jest-junit":"^5.1.0","sqlite3":"4.0.1","supertest":"^3.0.0"},"engines":{"node":">= 6.12.0"},"jest":{"testEnvironment":"node","reporters":["default","jest-junit"],"roots":["<rootDir>/bin/","<rootDir>/lib/","<rootDir>/tests/"],"moduleDirectories":["node_modules"],"modulePathIgnorePatterns":["/_out/","/edmx/","/projects/"],"moduleFileExtensions":["js","json","cds","properties"],"coverageDirectory":"reports/coverage","coverageReporters":["lcov","text"],"collectCoverageFrom":["lib/**","bin/**","!bin/init/**","!**/*.json"],"testPathIgnorePatterns":["/node_modules/","/integration/"],"verbose":true},"jest-junit":{"suiteName":"jest tests","output":"reports/sonar/test-reporter.xml","classNameTemplate":"{classname}-{title}","titleTemplate":"{classname}-{title}","ancestorSeparator":" › ","usePathForSuiteName":"true"},"main":"lib/index.js","name":"@sap/cds","scripts":{"beforePublish":"rm bin/.dev-internal.js","dedupe":"npm dedupe","lint":"eslint .","test":"jest --coverage && npm run test:new && npm run lint","test:all":"jest --coverage --testPathIgnorePatterns /node_modules/","test:integration":"jest --testRegex integration.*\\.js --testPathIgnorePatterns /node_modules/","test:new":"jest --testRegex test-new\\.js","test:watch":"jest --watchAll"},"typings":"apis/cds.d.ts","version":"2.9.1","license":"SEE LICENSE IN developer-license-3.1.txt"} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
340995
2876
60
44
+ Added@sap/cds-compiler@1.1.2(transitive)
+ Added@sap/cds-hana@0.8.0(transitive)
+ Added@sap/cds-ql@0.10.0(transitive)
+ Added@sap/cds-reflect@1.6.0(transitive)
+ Added@sap/cds-services@0.10.1(transitive)
+ Added@sap/cds-sql@0.10.0(transitive)
+ Added@sap/cds-sqlite@0.8.0(transitive)
- Removed@sap/cds-compiler@1.1.1(transitive)
- Removed@sap/cds-hana@0.7.1(transitive)
- Removed@sap/cds-ql@0.9.1(transitive)
- Removed@sap/cds-reflect@1.5.1(transitive)
- Removed@sap/cds-services@0.9.2(transitive)
- Removed@sap/cds-sql@0.9.2(transitive)
- Removed@sap/cds-sqlite@0.7.1(transitive)
Updated@sap/cds-compiler@1.1.2
Updated@sap/cds-ql@0.10.0
Updated@sap/cds-reflect@1.6.0
Updated@sap/cds-services@0.10.1