@sap/cds-compiler 2.12.0 → 2.13.6
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 +110 -15
- package/bin/cdsc.js +13 -13
- package/bin/cdsse.js +2 -2
- package/doc/CHANGELOG_BETA.md +13 -6
- package/doc/CHANGELOG_DEPRECATED.md +22 -6
- package/doc/NameResolution.md +21 -16
- package/lib/api/main.js +28 -63
- package/lib/api/options.js +3 -3
- package/lib/api/validate.js +0 -5
- package/lib/backends.js +15 -23
- package/lib/base/dictionaries.js +0 -8
- package/lib/base/error.js +26 -0
- package/lib/base/keywords.js +7 -17
- package/lib/base/location.js +9 -4
- package/lib/base/message-registry.js +25 -4
- package/lib/base/messages.js +16 -26
- package/lib/base/model.js +2 -63
- package/lib/base/optionProcessorHelper.js +158 -123
- package/lib/checks/annotationsOData.js +1 -1
- package/lib/checks/cdsPersistence.js +2 -1
- package/lib/checks/enricher.js +17 -1
- package/lib/checks/invalidTarget.js +3 -1
- package/lib/checks/managedWithoutKeys.js +3 -1
- package/lib/checks/selectItems.js +4 -4
- package/lib/checks/sql-snippets.js +27 -26
- package/lib/checks/types.js +1 -1
- package/lib/checks/validator.js +4 -7
- package/lib/compiler/assert-consistency.js +5 -3
- package/lib/compiler/builtins.js +8 -6
- package/lib/compiler/checks.js +14 -3
- package/lib/compiler/cycle-detector.js +1 -1
- package/lib/compiler/define.js +1103 -0
- package/lib/compiler/extend.js +983 -0
- package/lib/compiler/finalize-parse-cdl.js +231 -0
- package/lib/compiler/index.js +32 -13
- package/lib/compiler/kick-start.js +190 -0
- package/lib/compiler/moduleLayers.js +4 -4
- package/lib/compiler/populate.js +1226 -0
- package/lib/compiler/propagator.js +111 -46
- package/lib/compiler/resolve.js +1433 -0
- package/lib/compiler/shared.js +64 -37
- package/lib/compiler/tweak-assocs.js +529 -0
- package/lib/compiler/utils.js +197 -33
- package/lib/edm/.eslintrc.json +5 -0
- package/lib/edm/annotations/genericTranslation.js +5 -9
- package/lib/edm/annotations/preprocessAnnotations.js +2 -2
- package/lib/edm/csn2edm.js +9 -8
- package/lib/edm/edm.js +11 -12
- package/lib/edm/edmPreprocessor.js +137 -73
- package/lib/edm/edmUtils.js +116 -22
- package/lib/gen/Dictionary.json +10 -3
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +9 -1
- package/lib/gen/language.tokens +86 -83
- package/lib/gen/languageLexer.interp +10 -1
- package/lib/gen/languageLexer.js +860 -833
- package/lib/gen/languageLexer.tokens +78 -75
- package/lib/gen/languageParser.js +5282 -4265
- package/lib/json/from-csn.js +12 -1
- package/lib/json/to-csn.js +126 -66
- package/lib/language/docCommentParser.js +2 -2
- package/lib/language/genericAntlrParser.js +76 -3
- package/lib/language/language.g4 +297 -130
- package/lib/language/multiLineStringParser.js +5 -5
- package/lib/main.d.ts +468 -59
- package/lib/main.js +35 -9
- package/lib/model/api.js +3 -1
- package/lib/model/csnRefs.js +225 -156
- package/lib/model/csnUtils.js +192 -223
- package/lib/model/enrichCsn.js +70 -29
- package/lib/model/revealInternalProperties.js +27 -6
- package/lib/model/sortViews.js +2 -1
- package/lib/modelCompare/compare.js +17 -12
- package/lib/optionProcessor.js +5 -4
- package/lib/render/manageConstraints.js +35 -32
- package/lib/render/toCdl.js +73 -288
- package/lib/render/toHdbcds.js +25 -23
- package/lib/render/toSql.js +98 -41
- package/lib/render/utils/common.js +5 -10
- package/lib/render/utils/sql.js +4 -3
- package/lib/render/utils/stringEscapes.js +111 -0
- package/lib/sql-identifier.js +1 -1
- package/lib/transform/.eslintrc.json +5 -0
- package/lib/transform/db/.eslintrc.json +2 -0
- package/lib/transform/db/applyTransformations.js +35 -12
- package/lib/transform/db/assertUnique.js +1 -1
- package/lib/transform/db/associations.js +103 -305
- package/lib/transform/db/cdsPersistence.js +2 -2
- package/lib/transform/db/constraints.js +55 -52
- package/lib/transform/db/expansion.js +46 -24
- package/lib/transform/db/flattening.js +553 -102
- package/lib/transform/db/groupByOrderBy.js +3 -1
- package/lib/transform/db/transformExists.js +59 -6
- package/lib/transform/db/views.js +5 -4
- package/lib/transform/draft/.eslintrc.json +38 -0
- package/lib/transform/{db/draft.js → draft/db.js} +6 -5
- package/lib/transform/draft/odata.js +227 -0
- package/lib/transform/forHanaNew.js +67 -183
- package/lib/transform/forOdataNew.js +17 -171
- package/lib/transform/localized.js +34 -19
- package/lib/transform/odata/generateForeignKeyElements.js +1 -1
- package/lib/transform/odata/referenceFlattener.js +95 -89
- package/lib/transform/odata/structureFlattener.js +1 -1
- package/lib/transform/odata/toFinalBaseType.js +86 -12
- package/lib/transform/odata/typesExposure.js +5 -5
- package/lib/transform/odata/utils.js +2 -2
- package/lib/transform/transformUtilsNew.js +36 -22
- package/lib/transform/translateAssocsToJoins.js +2 -19
- package/lib/transform/universalCsn/.eslintrc.json +36 -0
- package/lib/transform/universalCsn/coreComputed.js +170 -0
- package/lib/transform/universalCsn/universalCsnEnricher.js +715 -0
- package/lib/transform/universalCsn/utils.js +63 -0
- package/lib/utils/objectUtils.js +30 -0
- package/package.json +1 -1
- package/share/messages/README.md +26 -0
- package/lib/compiler/definer.js +0 -2361
- package/lib/compiler/resolver.js +0 -3079
- package/lib/transform/universalCsnEnricher.js +0 -237
package/lib/main.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// These types are improved step by step and use a lot any types at the moment.
|
|
6
6
|
|
|
7
7
|
// Author's note: All "options" interfaces should actually be types. However, due to
|
|
8
|
-
// https://github.com/TypeStrong/typedoc/issues/1519 we can't use
|
|
8
|
+
// <https://github.com/TypeStrong/typedoc/issues/1519> we can't use
|
|
9
9
|
// intersection types at the moment.
|
|
10
10
|
|
|
11
11
|
export = compiler;
|
|
@@ -59,6 +59,36 @@ declare namespace compiler {
|
|
|
59
59
|
* Dictionaries are e.g. "definitions" and "elements".
|
|
60
60
|
*/
|
|
61
61
|
dictionaryPrototype?: any
|
|
62
|
+
/**
|
|
63
|
+
* CSN Flavor: The compiler supports different CSN flavors. Backends may support
|
|
64
|
+
* different flavors. This option is mainly used in `compile()`.
|
|
65
|
+
* Flavors are:
|
|
66
|
+
* - client : (default) Standard CSN consumable by clients and backends.
|
|
67
|
+
* - gensrc : CSN specifically for use as a source, e.g. for combination with
|
|
68
|
+
* additional "extend" or "annotate" statements, but not suitable
|
|
69
|
+
* for consumption by clients or backends.
|
|
70
|
+
* - universal : In development (BETA)
|
|
71
|
+
*/
|
|
72
|
+
csnFlavor?: string | 'client' | 'gensrc' | 'universal'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Options relevant for compilation and parsing of CDL and CSN files.
|
|
77
|
+
*/
|
|
78
|
+
export interface CompileOptions extends Options {
|
|
79
|
+
/**
|
|
80
|
+
* If the given filename does not have a known file extension,
|
|
81
|
+
* use this frontend as the fallback parser.
|
|
82
|
+
*/
|
|
83
|
+
fallbackParser?: string | 'cdl' | 'csn'
|
|
84
|
+
/**
|
|
85
|
+
* Option for {@link compileSources}. If set, all objects inside the
|
|
86
|
+
* provided sources dictionary are interpreted as XSN structures instead
|
|
87
|
+
* of CSN, i.e. a compiler-internal representation.
|
|
88
|
+
*
|
|
89
|
+
* @since v2.12.1
|
|
90
|
+
*/
|
|
91
|
+
$xsnObjects?: boolean
|
|
62
92
|
}
|
|
63
93
|
|
|
64
94
|
/**
|
|
@@ -235,6 +265,90 @@ declare namespace compiler {
|
|
|
235
265
|
}
|
|
236
266
|
}
|
|
237
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Options used by to.hdbcds()
|
|
270
|
+
*/
|
|
271
|
+
export interface HdbcdsOptions extends Options {
|
|
272
|
+
/**
|
|
273
|
+
* The SQL naming mode decides how names are represented.
|
|
274
|
+
* Among others, this includes whether identifiers are quoted or not.
|
|
275
|
+
*
|
|
276
|
+
* - `plain`:
|
|
277
|
+
* In this naming mode, dots are replaced by underscores.
|
|
278
|
+
* Identifiers are always uppercased. If "smart-quoting" is used, they are also quoted
|
|
279
|
+
if they are also HDBCDS keywords.
|
|
280
|
+
* - `quoted`:
|
|
281
|
+
* In this mode, all identifiers are quoted. Dots are not replaced in table
|
|
282
|
+
* and view names but are still replaced by underscores in element names.
|
|
283
|
+
* Identifier casing is kept as specified in the source.
|
|
284
|
+
* - `hdbcds`:
|
|
285
|
+
* This mode uses names that are compatible to SAP HANA CDS.
|
|
286
|
+
* In this mode, all identifiers are quoted. Dots are neither replaced in table
|
|
287
|
+
* nor element names: Structured elements persist, contexts are nested.
|
|
288
|
+
* Managed associations/compositions are left as-is. No association-to-join-translation
|
|
289
|
+
* is done.
|
|
290
|
+
*
|
|
291
|
+
* @default 'plain'
|
|
292
|
+
*/
|
|
293
|
+
sqlMapping?: string | 'plain' | 'quoted' | 'hdbcds'
|
|
294
|
+
/**
|
|
295
|
+
* For to.hdbcds(), the SQL dialect is always set to 'hana'.
|
|
296
|
+
*/
|
|
297
|
+
sqlDialect?: 'hana'
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Options used by to.hdi() and to.hdi.migration()
|
|
302
|
+
*/
|
|
303
|
+
export interface HdiOptions extends Options {
|
|
304
|
+
/**
|
|
305
|
+
* The SQL naming mode decides how names are represented.
|
|
306
|
+
* Among others, this includes whether identifiers are quoted or not.
|
|
307
|
+
*
|
|
308
|
+
* - `plain`:
|
|
309
|
+
* In this naming mode, dots are replaced by underscores.
|
|
310
|
+
* Names are neither upper-cased nor quoted, unless "smart-quoting" is used.
|
|
311
|
+
* - `quoted`:
|
|
312
|
+
* In this mode, all identifiers are quoted. Dots are not replaced in table
|
|
313
|
+
* and view names but are still replaced by underscores in element names.
|
|
314
|
+
* - `hdbcds`:
|
|
315
|
+
* This mode uses names that are compatible to SAP HANA CDS.
|
|
316
|
+
* In this mode, all identifiers are quoted. Dots are neither replaced in table
|
|
317
|
+
* nor element names. Namespace identifiers are separated from the remaining
|
|
318
|
+
* identifier by `::`, i.e. the dot is replaced. For example `Ns.Books`
|
|
319
|
+
* becomes `"Ns::Books"`.
|
|
320
|
+
*
|
|
321
|
+
* @default 'plain'
|
|
322
|
+
*/
|
|
323
|
+
sqlMapping?: string | 'plain' | 'quoted' | 'hdbcds'
|
|
324
|
+
/**
|
|
325
|
+
* For to.hdi(), the SQL dialect is always set to 'hana'.
|
|
326
|
+
*/
|
|
327
|
+
sqlDialect?: 'hana'
|
|
328
|
+
/**
|
|
329
|
+
* Only for to.hdi.migration().
|
|
330
|
+
* SQL change mode to use (for changed columns).
|
|
331
|
+
*
|
|
332
|
+
* @default 'alter'
|
|
333
|
+
*/
|
|
334
|
+
sqlChangeMode?: string | 'alter' | 'drop'
|
|
335
|
+
/**
|
|
336
|
+
* Only for `to.hdi.migration`. If `true`, `to.hdi.migration` allows that the two
|
|
337
|
+
* passed CSNs are of different CSN versions. Use at own risk.
|
|
338
|
+
*
|
|
339
|
+
* @default false
|
|
340
|
+
*/
|
|
341
|
+
allowCsnDowngrade?: boolean
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Options used by `to.cdl()` backend.
|
|
346
|
+
*
|
|
347
|
+
* @note `to.cdl()` currently has no specific options.
|
|
348
|
+
* @see to.cdl()
|
|
349
|
+
*/
|
|
350
|
+
export interface CdlOptions extends Options {}
|
|
351
|
+
|
|
238
352
|
/**
|
|
239
353
|
* The compiler's package version.
|
|
240
354
|
* For more details on versioning and SemVer, see `doc/Versioning.md`
|
|
@@ -245,7 +359,7 @@ declare namespace compiler {
|
|
|
245
359
|
* Main function: Compile the sources from the files given by the array of
|
|
246
360
|
* `filenames`. As usual with the `fs` library, relative file names are
|
|
247
361
|
* relative to the working directory `process.cwd()`. With argument `dir`, the
|
|
248
|
-
* file names are relative to `process.cwd()+dir
|
|
362
|
+
* file names are relative to `process.cwd()+dir` (or just `dir` if it is absolute).
|
|
249
363
|
*
|
|
250
364
|
* This function returns a Promise and can be used with `await`. For an example
|
|
251
365
|
* see `examples/api-usage/`.
|
|
@@ -263,15 +377,32 @@ declare namespace compiler {
|
|
|
263
377
|
* @param filenames Array of files that should be compiled.
|
|
264
378
|
* @param dir Working directory. Relative paths in `filenames` will be resolved relatively to this directory.
|
|
265
379
|
* @param options Compiler options. If you do not set `messages`, they will be printed to console.
|
|
266
|
-
* @param fileCache
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
380
|
+
* @param fileCache
|
|
381
|
+
*/
|
|
382
|
+
export function compile(filenames: string[], dir?: string, options?: CompileOptions, fileCache?: FileCache): Promise<CSN>;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Synchronous version of {@link compile}.
|
|
386
|
+
* Usage is discouraged. Use the asynchronous version if possible.
|
|
387
|
+
*
|
|
388
|
+
* @see compile
|
|
271
389
|
*/
|
|
272
|
-
export function
|
|
273
|
-
|
|
274
|
-
|
|
390
|
+
export function compileSync(filenames: string[], dir?: string, options?: CompileOptions, fileCache?: FileCache): CSN;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Synchronously compiles the given sources.
|
|
394
|
+
*
|
|
395
|
+
* Argument `sourcesDict` is a dictionary mapping filenames to either source texts (string)
|
|
396
|
+
* or JavaScript objects, which are usually CSNs, or XSNs (compiler internal AST-like augmented CSNs).
|
|
397
|
+
* The latter requires option `$xsnObjects` to be set to `true`.
|
|
398
|
+
* It could also be a simple string, which is then considered to be the source
|
|
399
|
+
* text of a file named `<stdin>.cds`.
|
|
400
|
+
*
|
|
401
|
+
* See function {@link compile} for the meaning of the argument `options`. If there
|
|
402
|
+
* are parse or other compilation errors, throws an exception {@link CompilationError}
|
|
403
|
+
* containing a list of individual errors.
|
|
404
|
+
*/
|
|
405
|
+
export function compileSources(sourcesDict: Record<string, string|object> | string, options?: CompileOptions): CSN;
|
|
275
406
|
|
|
276
407
|
/**
|
|
277
408
|
* In version 2 of cds-compiler, this is an identity function and
|
|
@@ -280,11 +411,17 @@ declare namespace compiler {
|
|
|
280
411
|
* @deprecated
|
|
281
412
|
* @returns The input parameter "csn".
|
|
282
413
|
*/
|
|
283
|
-
export function compactModel(csn: CSN):
|
|
414
|
+
export function compactModel(csn: CSN): CSN;
|
|
284
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Exception thrown by the compiler if errors are encountered.
|
|
418
|
+
*
|
|
419
|
+
* Note that compiler functions (e.g. renderers) may not always throw if errors are encountered.
|
|
420
|
+
* You always need to check the option's `messages` array for a {@link CompileMessage} of severity 'Error'.
|
|
421
|
+
*/
|
|
285
422
|
export class CompilationError extends Error {
|
|
286
|
-
constructor(messages:
|
|
287
|
-
messages:
|
|
423
|
+
constructor(messages: CompileMessage[], model?: any, text?: string, ...args: any[]);
|
|
424
|
+
messages: CompileMessage[];
|
|
288
425
|
toString(): string;
|
|
289
426
|
/**
|
|
290
427
|
* If `options.attachValidNames` is set, this non-enumerable property holds the CSN model.
|
|
@@ -298,6 +435,15 @@ declare namespace compiler {
|
|
|
298
435
|
hasBeenReported: boolean;
|
|
299
436
|
}
|
|
300
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Exception thrown by the compiler if {@link compile} and its variants are invoked incorrectly.
|
|
440
|
+
* For example, this error is thrown if the same file is passed to {@link compile} twice.
|
|
441
|
+
*/
|
|
442
|
+
export class InvocationError extends Error {
|
|
443
|
+
constructor(errs: any, ...args: any[]);
|
|
444
|
+
errors: any[]
|
|
445
|
+
}
|
|
446
|
+
|
|
301
447
|
/**
|
|
302
448
|
* Sort the given messages according to their location. Messages are sorted
|
|
303
449
|
* in ascending order according to their:
|
|
@@ -396,7 +542,7 @@ declare namespace compiler {
|
|
|
396
542
|
* @param config.withLineSpacer If true, an additional line (with `|`) will be inserted between message and location.
|
|
397
543
|
* @param config.color If true, ANSI escape codes will be used for coloring the severity. If false, no
|
|
398
544
|
* coloring will be used. If 'auto', we will decide based on certain factors such
|
|
399
|
-
* as whether the shell is a TTY and whether the environment variable
|
|
545
|
+
* as whether the shell is a TTY and whether the environment variable `NO_COLOR` is
|
|
400
546
|
* unset.
|
|
401
547
|
*/
|
|
402
548
|
export function messageStringMultiline(msg: CompileMessage, config?: {
|
|
@@ -428,7 +574,7 @@ declare namespace compiler {
|
|
|
428
574
|
* @param config Configuration for the message context.
|
|
429
575
|
* @param config.color If true, ANSI escape codes will be used for coloring the severity. If false, no
|
|
430
576
|
* coloring will be used. If 'auto', we will decide based on certain factors such
|
|
431
|
-
* as whether the shell is a TTY and whether the environment variable
|
|
577
|
+
* as whether the shell is a TTY and whether the environment variable `NO_COLOR` is
|
|
432
578
|
* unset.
|
|
433
579
|
|
|
434
580
|
*/
|
|
@@ -442,28 +588,39 @@ declare namespace compiler {
|
|
|
442
588
|
* If the message explanation does not exist, an exception is thrown.
|
|
443
589
|
*
|
|
444
590
|
* @throws May throw an ENOENT error if the message explanation cannot be found.
|
|
445
|
-
* @see
|
|
591
|
+
* @see hasMessageExplanation
|
|
446
592
|
*/
|
|
447
593
|
export function explainMessage(messageId: string): string;
|
|
448
594
|
/**
|
|
449
595
|
* Returns `true` if the given messageId has an explanatory text.
|
|
450
|
-
* Contrary to {@link explainMessage}, this function does not
|
|
451
|
-
*
|
|
596
|
+
* Contrary to {@link explainMessage}, this function does not do
|
|
597
|
+
* any file lookup.
|
|
452
598
|
*/
|
|
453
599
|
export function hasMessageExplanation(messageId: string): boolean;
|
|
454
600
|
|
|
455
|
-
export class InvocationError extends Error {
|
|
456
|
-
constructor(errs: any, ...args);
|
|
457
|
-
errors: any[]
|
|
458
|
-
}
|
|
459
|
-
|
|
460
601
|
/**
|
|
461
|
-
* Returns true if at least one of the given messages is of severity "Error"
|
|
602
|
+
* Returns true if at least one of the given messages is of severity "Error".
|
|
462
603
|
*/
|
|
463
604
|
export function hasErrors(messages: CompileMessage[]): boolean;
|
|
464
605
|
|
|
465
|
-
|
|
466
|
-
|
|
606
|
+
/**
|
|
607
|
+
* Same as {@link to.edm} but expects a {@link for.odata} transformed CSN.
|
|
608
|
+
*
|
|
609
|
+
* Note that parameter `service` is the same as `ODataOptions.service`.
|
|
610
|
+
* The latter is not used. OData specific options have an internal format.
|
|
611
|
+
*
|
|
612
|
+
* @deprecated Use {@link to.edm} instead. If it detects a pre-transformed CSN, it won't run for.odata().
|
|
613
|
+
*/
|
|
614
|
+
export function preparedCsnToEdm(csn: CSN, service: string, options: ODataOptions): object;
|
|
615
|
+
/**
|
|
616
|
+
* Same as {@link to.edm} but expects a {@link for.odata} transformed CSN.
|
|
617
|
+
*
|
|
618
|
+
* Note that parameter `service` is the same as `ODataOptions.service`.
|
|
619
|
+
* The latter is not used. OData specific options have an outdated format.
|
|
620
|
+
*
|
|
621
|
+
* @deprecated Use {@link to.edmx} instead. If it detects a pre-transformed CSN, it won't run for.odata().
|
|
622
|
+
*/
|
|
623
|
+
export function preparedCsnToEdmx(csn: CSN, service: string, options: ODataOptions): string;
|
|
467
624
|
|
|
468
625
|
export namespace parse {
|
|
469
626
|
/**
|
|
@@ -473,38 +630,42 @@ declare namespace compiler {
|
|
|
473
630
|
* @param filename Filename to be used in compiler messages.
|
|
474
631
|
* @param options Compiler options. Note that if `options.messages` is not set, messages will be printed to stderr.
|
|
475
632
|
*/
|
|
476
|
-
function cdl(cdl: string, filename: string, options?: Options):
|
|
633
|
+
function cdl(cdl: string, filename: string, options?: Options): CSN;
|
|
477
634
|
|
|
478
635
|
/**
|
|
479
|
-
* Parse the given CQL and return its corresponding
|
|
636
|
+
* Parse the given CQL and return its corresponding CQN representation.
|
|
480
637
|
*
|
|
481
638
|
* @param cdl CDL source as string.
|
|
482
639
|
* @param filename Filename to be used in compiler messages, default is '<query>.cds'
|
|
483
640
|
* @param options Compiler options. Note that if `options.messages` is not set, messages will be printed to stderr.
|
|
641
|
+
* @returns Returns the CSN representation of the expression, i.e. CDS Query Notation.
|
|
484
642
|
*/
|
|
485
|
-
function cql(cdl: string, filename?: string, options?: Options):
|
|
643
|
+
function cql(cdl: string, filename?: string, options?: Options): CQN;
|
|
486
644
|
|
|
487
645
|
/**
|
|
488
|
-
* Parse the given CDL expression and return its corresponding
|
|
646
|
+
* Parse the given CDL expression and return its corresponding CXN representation.
|
|
489
647
|
*
|
|
490
648
|
* @param cdl CDL source as string.
|
|
491
649
|
* @param filename Filename to be used in compiler messages, default is '<expr>.cds'
|
|
492
650
|
* @param options Compiler options. Note that if `options.messages` is not set, messages will be printed to stderr.
|
|
651
|
+
* @returns Returns the CSN representation of the expression, i.e. CDS Expression Notation.
|
|
493
652
|
*/
|
|
494
|
-
function expr(cdl: string, filename?: string, options?: Options):
|
|
653
|
+
function expr(cdl: string, filename?: string, options?: Options): CXN;
|
|
495
654
|
}
|
|
496
655
|
|
|
497
656
|
/**
|
|
498
657
|
* @deprecated Use {@link parse.cql} instead.
|
|
499
658
|
*/
|
|
500
|
-
export function parseToCqn(
|
|
659
|
+
export function parseToCqn(cql: string, filename?: string, options?: Options): CQN;
|
|
501
660
|
/**
|
|
502
661
|
* @deprecated Use {@link parse.expr} instead.
|
|
503
662
|
*/
|
|
504
|
-
export function parseToExpr(
|
|
663
|
+
export function parseToExpr(expr: string, filename?: string, options?: Options): CXN;
|
|
505
664
|
|
|
506
665
|
/**
|
|
507
|
-
* @note Actual name is "for" which can't be used directly in the documentation
|
|
666
|
+
* @note Actual name is "for" which can't be used directly in the documentation
|
|
667
|
+
* as it is a reserved name in TypeScript.
|
|
668
|
+
*
|
|
508
669
|
* @see for
|
|
509
670
|
*/
|
|
510
671
|
export namespace _for {
|
|
@@ -513,51 +674,292 @@ declare namespace compiler {
|
|
|
513
674
|
* Changes include flattening, type resolution and more, according to
|
|
514
675
|
* the provided options.
|
|
515
676
|
*/
|
|
516
|
-
function odata(csn: CSN, options
|
|
677
|
+
function odata(csn: CSN, options?: ODataOptions): CSN;
|
|
517
678
|
}
|
|
518
679
|
|
|
519
680
|
export { _for as for };
|
|
520
681
|
|
|
521
682
|
export namespace to {
|
|
522
|
-
|
|
523
|
-
|
|
683
|
+
/**
|
|
684
|
+
* Renders the given CSN into a CDL source representation.
|
|
685
|
+
*
|
|
686
|
+
* @returns Object containing the rendered model.
|
|
687
|
+
*/
|
|
688
|
+
function cdl(csn: CSN, options?: CdlOptions): CdlResult;
|
|
689
|
+
namespace cdl {
|
|
690
|
+
/**
|
|
691
|
+
* Immutable list of reserved keywords in CDL.
|
|
692
|
+
* These keywords are used for automatic quoting in {@link to.cdl}.
|
|
693
|
+
*/
|
|
694
|
+
const keywords: string[];
|
|
695
|
+
/**
|
|
696
|
+
* Immutable list of CDL functions, used for automatic quoting in {@link to.cdl}.
|
|
697
|
+
* Only relevant for element references of path length 1.
|
|
698
|
+
*/
|
|
699
|
+
const functions: string[];
|
|
700
|
+
}
|
|
524
701
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
702
|
+
/**
|
|
703
|
+
* Renders the given CSN into SQL statements such as `CREATE TABLE`, `CREATE VIEW`, etc.
|
|
704
|
+
*
|
|
705
|
+
* @returns Array of SQL statements as strings, tables first, views second and optionally table constraints last.
|
|
706
|
+
*/
|
|
707
|
+
function sql(csn: CSN, options?: SqlOptions): string[];
|
|
708
|
+
namespace sql {
|
|
709
|
+
namespace sqlite {
|
|
710
|
+
/**
|
|
711
|
+
* Immutable list of reserved keywords for SQLite. The list is used by {@link to.sql}.
|
|
712
|
+
* Taken from <http://www.sqlite.org/draft/lang_keywords.html>.
|
|
713
|
+
*/
|
|
714
|
+
const keywords: string[];
|
|
528
715
|
}
|
|
716
|
+
function smartId(name: string, dialect: string) : string;
|
|
717
|
+
function smartFunctionId(name: string, dialect: string) : string;
|
|
718
|
+
function delimitedId(name: string, dialect: string) : string;
|
|
719
|
+
}
|
|
529
720
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
721
|
+
/**
|
|
722
|
+
* Renders the given CSN into EDM (JSON format). Requires `options.service` to be set.
|
|
723
|
+
*
|
|
724
|
+
* @returns Rendered EDM as JSON structure.
|
|
725
|
+
*/
|
|
726
|
+
function edm(csn: CSN, options?: ODataOptions): object;
|
|
727
|
+
namespace edm {
|
|
728
|
+
/**
|
|
729
|
+
* Renders the given CSN into EDM (JSON format) for each service.
|
|
730
|
+
* If `options.serviceNames` is not set, all services will be rendered.
|
|
731
|
+
*
|
|
732
|
+
* @returns A map of `{ '<serviceName>': object }` entries.
|
|
733
|
+
*/
|
|
734
|
+
function all(csn: CSN, options: ODataOptions): Record<string, object>;
|
|
735
|
+
}
|
|
534
736
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
737
|
+
/**
|
|
738
|
+
* Renders the given CSN into EDMX. Requires `options.service` to be set.
|
|
739
|
+
*
|
|
740
|
+
* @returns Rendered EDMX as string.
|
|
741
|
+
*/
|
|
742
|
+
function edmx(csn: CSN, options: ODataOptions): string;
|
|
743
|
+
namespace edmx {
|
|
744
|
+
/**
|
|
745
|
+
* Renders the given CSN into EDMX for each service.
|
|
746
|
+
* If `options.serviceNames` is not set, all services will be rendered.
|
|
747
|
+
*
|
|
748
|
+
* @returns A map of `{ '<serviceName>': '<xml>' }` entries.
|
|
749
|
+
*/
|
|
750
|
+
function all(csn: CSN, options?: ODataOptions): Record<string, string>;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Renders the given CSN into HDBCDS artifacts.
|
|
755
|
+
*
|
|
756
|
+
* @returns A map of `{ '<artifactName>.hdbcds|hdbconstraint>': '<content>' }` entries.
|
|
757
|
+
*/
|
|
758
|
+
function hdbcds(csn: CSN, options?: HdbcdsOptions): Record<string, string>;
|
|
759
|
+
namespace hdbcds {
|
|
760
|
+
/**
|
|
761
|
+
* Immutable list of SAP HANA CDS keywords, used for smart quoting in
|
|
762
|
+
* {@link to.hdbcds} with option `sqlMapping: 'plain'`.
|
|
763
|
+
*/
|
|
764
|
+
const keywords: string[];
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Renders the given CSN into HDI statements such as `COLUMN TABLE`, `VIEW`, etc.
|
|
769
|
+
*
|
|
770
|
+
* @returns A map of `{ '<artifactName>.hdbtable|hdbview|hdbconstraint>': '<content>' }` entries.
|
|
771
|
+
*/
|
|
772
|
+
function hdi(csn: CSN, options?: HdiOptions): Record<string, string>;
|
|
773
|
+
namespace hdi {
|
|
774
|
+
/**
|
|
775
|
+
* Immutable list of SAP HANA keywords, used for smart quoting in
|
|
776
|
+
* {@link to.hdi} with option `sqlMapping: 'plain'`.
|
|
777
|
+
* Taken from <https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/28bcd6af3eb6437892719f7c27a8a285.html>.
|
|
778
|
+
*/
|
|
779
|
+
const keywords: string[];
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Return all changes in artifacts between two given models.
|
|
783
|
+
* Note: Only supports changes in entities (not views etc.) compiled/rendered as HANA-CSN/SQL.
|
|
784
|
+
*
|
|
785
|
+
* @param csn A clean input CSN representing the desired "after-image"
|
|
786
|
+
* @param options Options
|
|
787
|
+
* @param beforeImage A HANA-transformed CSN representing the "before-image", or null in case no such image
|
|
788
|
+
* is known, i.e. for the very first migration step
|
|
789
|
+
* @returns See {@link HdiMigrationResult} for details.
|
|
790
|
+
*/
|
|
791
|
+
function migration(csn: CSN, options: HdiOptions, beforeImage: CSN): HdiMigrationResult;
|
|
792
|
+
}
|
|
540
793
|
}
|
|
541
794
|
|
|
542
|
-
|
|
543
|
-
|
|
795
|
+
/**
|
|
796
|
+
* Result of the `to.cdl()` renderer.
|
|
797
|
+
*/
|
|
798
|
+
export type CdlResult = {
|
|
799
|
+
/**
|
|
800
|
+
* Rendered model, excluding not-applied extensions.
|
|
801
|
+
*/
|
|
802
|
+
model?: string
|
|
803
|
+
/**
|
|
804
|
+
* Rendered extend/annotate statements of `csn.extensions`
|
|
805
|
+
*/
|
|
806
|
+
unappliedExtensions?: string
|
|
807
|
+
/**
|
|
808
|
+
* Rendered csn.namespace property + using directives.
|
|
809
|
+
*/
|
|
810
|
+
[namespace: string]: string
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Result type of {@link to.hdi.migration}.
|
|
815
|
+
*/
|
|
816
|
+
export type HdiMigrationResult = {
|
|
817
|
+
/**
|
|
818
|
+
* The desired after-image in HANA-CSN format
|
|
819
|
+
*/
|
|
820
|
+
afterImage: CSN
|
|
821
|
+
/**
|
|
822
|
+
* An array of objects with all artifacts in the after-image. Each object specifies
|
|
823
|
+
* the artifact filename, the suffix, and the corresponding SQL statement to create
|
|
824
|
+
* the artifact.
|
|
825
|
+
*/
|
|
826
|
+
definitions: object[],
|
|
827
|
+
/**
|
|
828
|
+
* An array of objects with the deleted artifacts. Each object specifies the artifact
|
|
829
|
+
* filename and the suffix.
|
|
830
|
+
*/
|
|
831
|
+
deletions: object[],
|
|
832
|
+
/**
|
|
833
|
+
* An array of objects with the changed (migrated) artifacts. Each object specifies the
|
|
834
|
+
* artifact filename, the suffix, and the changeset (an array of changes, each specifying
|
|
835
|
+
* whether it incurs potential data loss, and its respective SQL statement(s), with
|
|
836
|
+
* multiple statements concatenated as a multi-line string in case the change e.g.
|
|
837
|
+
* consists of a column drop and add).
|
|
838
|
+
*/
|
|
839
|
+
migrations: Array<{
|
|
840
|
+
name: string
|
|
841
|
+
suffix: string
|
|
842
|
+
changeset: object[]
|
|
843
|
+
}>,
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Return the resulting database name for (absolute) 'artifactName', depending on the current naming
|
|
848
|
+
* mode.
|
|
849
|
+
*
|
|
850
|
+
* - For the 'hdbcds' naming mode, this means converting `.` to `::` on
|
|
851
|
+
* the border between namespace and top-level artifact and correctly replacing some `.` with `_`.
|
|
852
|
+
* - For the 'plain' naming mode, it means converting all `.` to `_` and upper-casing.
|
|
853
|
+
* - For the 'quoted' naming mode, this means correctly replacing some `.` with `_`.
|
|
854
|
+
*
|
|
855
|
+
* @param artifactName The fully qualified name of the artifact
|
|
856
|
+
* @param sqlMapping The naming mode to use. See {@link SqlOptions.sqlMapping} for more details.
|
|
857
|
+
* @param csn
|
|
858
|
+
* @returns {string} The resulting database name for (absolute) 'artifactName', depending on the current naming mode.
|
|
859
|
+
* @since v2.1.0
|
|
860
|
+
*/
|
|
861
|
+
export function getArtifactCdsPersistenceName(artifactName: string, sqlMapping: string, csn: CSN): string;
|
|
862
|
+
/**
|
|
863
|
+
* This is an old function signature. If it is used - with a namespace as the third argument - the result might be wrong,
|
|
864
|
+
* since the `.` -> `_` conversion for 'quoted'/'hdbcds' is missing.
|
|
865
|
+
*
|
|
866
|
+
* @deprecated Use the other overload with CSN instead.
|
|
867
|
+
*/
|
|
868
|
+
export function getArtifactCdsPersistenceName(artifactName: string, sqlMapping: string, namespace: string): string;
|
|
869
|
+
/**
|
|
870
|
+
* Return the resulting database element name for `elemName`, depending on the current
|
|
871
|
+
* naming mode.
|
|
872
|
+
* - For the 'hdbcds' naming mode, this is just 'elemName'.
|
|
873
|
+
* - For the 'plain' naming mode, it means converting all `.` to `_` and upper-casing.
|
|
874
|
+
* - For the 'quoted' naming mode, it means converting all `.` to `_`.
|
|
875
|
+
* No other naming modes are accepted!
|
|
876
|
+
*
|
|
877
|
+
* @param elemName The name of the element. For structured elements, concat by dot, e.g. `sub.elem`.
|
|
878
|
+
* @param sqlMapping The naming mode to use. See {@link SqlOptions.sqlMapping} for more details.
|
|
879
|
+
* @returns The resulting database element name for 'elemName', depending on the current naming mode.
|
|
880
|
+
*/
|
|
881
|
+
export function getElementCdsPersistenceName(elemName: string, sqlMapping: string): string;
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Traverse the CSN node `csn`.
|
|
885
|
+
*
|
|
886
|
+
* If `csn` is an array, call it recursively on each array item.
|
|
887
|
+
* If `csn` is an(other) object, call a function on each property:
|
|
888
|
+
* - The property name is a used as key in argument `userFunctions` and the
|
|
889
|
+
* constant `defaultFunctions` above to get the function which is called on
|
|
890
|
+
* the property value, see `defaultFunctions` for details.
|
|
891
|
+
* - If no function is found with the property name, try to find one with the
|
|
892
|
+
* first char, which is useful for annotations.
|
|
893
|
+
* - If still not found, call `traverseCsn` recursively.
|
|
894
|
+
*
|
|
895
|
+
* The functions in `userFunctions` are usually transformer functions, which
|
|
896
|
+
* change the input CSN destructively.
|
|
897
|
+
*/
|
|
898
|
+
export function traverseCsn(userFunctions: Record<string, Function>, csn: object|any[]);
|
|
544
899
|
|
|
545
900
|
/**
|
|
546
901
|
* @private
|
|
547
902
|
*/
|
|
548
903
|
export namespace $lsp {
|
|
549
|
-
|
|
550
|
-
|
|
904
|
+
/**
|
|
905
|
+
* Compiler internal notation.
|
|
906
|
+
* @private
|
|
907
|
+
*/
|
|
908
|
+
type XSN = any;
|
|
909
|
+
/**
|
|
910
|
+
* Compile the given files with the given options. The return object uses an internal object
|
|
911
|
+
* format that must not be used outside of the cds-lsp.
|
|
912
|
+
* Respects the value of `options.fallbackParser`.
|
|
913
|
+
*
|
|
914
|
+
* @param filenames Array of files that should be compiled.
|
|
915
|
+
* @param dir Working directory. Relative paths in `filenames` will be resolved relatively to this directory.
|
|
916
|
+
* @param options Compiler options. If you do not set `messages`, they will be printed to console.
|
|
917
|
+
* @param fileCache
|
|
918
|
+
* @private
|
|
919
|
+
*/
|
|
920
|
+
function compile(filenames: string[], dir?: string, options?: CompileOptions, fileCache?: FileCache): Promise<XSN>;
|
|
921
|
+
/**
|
|
922
|
+
* Parse the given source with the correct parser based on the file name's
|
|
923
|
+
* extension. For example uses CDL parser for `.cds` files.
|
|
924
|
+
* Respects the value of `options.fallbackParser`.
|
|
925
|
+
*
|
|
926
|
+
* @param {string} source Source code of the file.
|
|
927
|
+
* @param {string} filename Filename including its extension, e.g. "file.cds"
|
|
928
|
+
* @param {object} options Compile options
|
|
929
|
+
* @param {object} messageFunctions If not provided, parse errors will not lead to an exception
|
|
930
|
+
* @private
|
|
931
|
+
*/
|
|
932
|
+
function parse(source: string, filename: string, options?: CompileOptions, messageFunctions?: object): XSN;
|
|
933
|
+
/**
|
|
934
|
+
* Get the name of the given artifact. This function is internal and does not work with CSN.
|
|
935
|
+
* It should be used to retrieve an artifact's name instead of relying on `artifact.name`
|
|
936
|
+
* as that object may be modified in the future.
|
|
937
|
+
*
|
|
938
|
+
* @private
|
|
939
|
+
*/
|
|
940
|
+
function getArtifactName(artifact: object): object;
|
|
551
941
|
}
|
|
552
942
|
|
|
553
943
|
/**
|
|
554
|
-
*
|
|
944
|
+
* CDS Schema Notation. Not yet specified in this TypeScript declaration file.
|
|
945
|
+
* See <https://pages.github.tools.sap/cap/docs/cds/csn> for more.
|
|
555
946
|
*/
|
|
556
947
|
export type CSN = any;
|
|
557
948
|
|
|
949
|
+
/**
|
|
950
|
+
* CDS Query Notation. Not yet specified in this TypeScript declaration file.
|
|
951
|
+
* See <https://pages.github.tools.sap/cap/docs/cds/cqn> for more.
|
|
952
|
+
*/
|
|
953
|
+
export type CQN = any;
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* CDS Expression Notation. Not yet specified in this TypeScript declaration file.
|
|
957
|
+
* See <https://pages.github.tools.sap/cap/docs/cds/cxn> for more.
|
|
958
|
+
*/
|
|
959
|
+
export type CXN = any;
|
|
960
|
+
|
|
558
961
|
export class CompileMessage {
|
|
559
962
|
constructor(location: Location, msg: string, severity?: MessageSeverity, id?: string | null, home?: string | null, moduleName?: string | null);
|
|
560
|
-
|
|
561
963
|
/**
|
|
562
964
|
* Optional ID of the message. Can be used to reclassify messages.
|
|
563
965
|
*
|
|
@@ -571,7 +973,6 @@ declare namespace compiler {
|
|
|
571
973
|
* @deprecated Use `$location` instead.
|
|
572
974
|
*/
|
|
573
975
|
location: Location
|
|
574
|
-
|
|
575
976
|
/**
|
|
576
977
|
* Location information like file and line/column of the message.
|
|
577
978
|
*/
|
|
@@ -587,7 +988,6 @@ declare namespace compiler {
|
|
|
587
988
|
* String representation of the message. May be a multi-line message in the future.
|
|
588
989
|
*/
|
|
589
990
|
message: string
|
|
590
|
-
|
|
591
991
|
/**
|
|
592
992
|
* A string describing the path to the artifact, e.g. `entity:"E"/element:"x"`.
|
|
593
993
|
*/
|
|
@@ -603,7 +1003,6 @@ declare namespace compiler {
|
|
|
603
1003
|
* If `internalMsg` is set, then this property will have an error object with a stack trace.
|
|
604
1004
|
*/
|
|
605
1005
|
error?: Error
|
|
606
|
-
|
|
607
1006
|
/**
|
|
608
1007
|
* Returns a human readable string of the compiler message. Uses {@link messageString} to render
|
|
609
1008
|
* the message without filename normalization and without a message ID.
|
|
@@ -614,7 +1013,7 @@ declare namespace compiler {
|
|
|
614
1013
|
/**
|
|
615
1014
|
* Severities a compiler message can have.
|
|
616
1015
|
*/
|
|
617
|
-
export type MessageSeverity = 'Error' | 'Warning' | 'Info' | 'Debug';
|
|
1016
|
+
export type MessageSeverity = string | 'Error' | 'Warning' | 'Info' | 'Debug';
|
|
618
1017
|
|
|
619
1018
|
/**
|
|
620
1019
|
* CSN Location, often exposed by `$location` in CSN.
|
|
@@ -631,4 +1030,14 @@ declare namespace compiler {
|
|
|
631
1030
|
endCol?: number
|
|
632
1031
|
}
|
|
633
1032
|
|
|
1033
|
+
/**
|
|
1034
|
+
* File cache for compile() functions.
|
|
1035
|
+
* This cache is a dictionary of absolute file names to the file content with values:
|
|
1036
|
+
* - `false`: the file does not exist
|
|
1037
|
+
* - `true`: file exists (fstat), no further knowledge yet - i.e. value will change!
|
|
1038
|
+
* - `string` or `Buffer`: the file content
|
|
1039
|
+
* - `{ realname: fs.realpath(filename) }`: if filename is not canonicalized
|
|
1040
|
+
*/
|
|
1041
|
+
export type FileCache = Record<string, boolean | string | Buffer | { realname: string }>;
|
|
1042
|
+
|
|
634
1043
|
}
|