@cap-js/cds-types 0.2.0 → 0.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/apis/linked.d.ts DELETED
@@ -1,104 +0,0 @@
1
- import { CSN, FQN, Association, Definition, entity, kinds } from './csn'
2
-
3
- export type LinkedDefinition = linked & Definition & LinkedEntity & LinkedAssociation
4
- export type Definitions = { [name: string]: LinkedDefinition }
5
- // FIXME: this is only a temporary alias. Definitions is actually correct,
6
- // but the name may be misleading, as it is indeed a mapping of strings to LinkedDefinition objects.
7
- export type LinkedDefinitions = Definitions
8
- export interface linked {
9
- is(kind: kinds | 'Association' | 'Composition'): boolean
10
- name: FQN
11
- }
12
-
13
- interface LinkedEntity extends linked, entity {
14
- keys: Definitions
15
- drafts?: LinkedEntity
16
- }
17
-
18
- interface LinkedAssociation extends linked, Association {
19
- is2one: boolean
20
- is2many: boolean
21
- }
22
-
23
- export interface LinkedCSN extends CSN {
24
-
25
- /**
26
- * Fetches definitions matching the given filter, returning an iterator on them.
27
- * @example
28
- * ```js
29
- * let m = cds.reflect (aParsedModel)
30
- * for (let d of m.each('entity')) console.log (d.kind, d.name)
31
- * let entities = [...m.each('entity')] //> capture all
32
- * let entities = m.all('entity') //> equivalent shortcut
33
- * ```
34
- */
35
- each(x: Filter, defs?: Definitions): IterableIterator<any>
36
-
37
- /**
38
- * Fetches definitions matching the given filter, returning them in an array.
39
- * Convenience shortcut for `[...reflect.each('entity')]`
40
- */
41
- all(x: Filter, defs?: Definitions): any[]
42
-
43
- /**
44
- * Fetches definitions matching the given filter, returning the first match, if any.
45
- * @example
46
- * let service = model.find('service')
47
- * @param x - the filter
48
- * @param defs - the definitions to fetch in, default: `this.definitions`
49
- */
50
- find(x: Filter, defs?: Definitions): any
51
-
52
- /**
53
- * Calls the visitor for each definition matching the given filter.
54
- * @see [capire](https://github.wdf.sap.corp/pages/cap/node.js/api#cds-reflect-foreach)
55
- */
56
- foreach(x: Filter, visitor: Visitor, defs?: Definitions): this
57
- foreach(visitor: Visitor, defs?: Definitions): this
58
-
59
- /**
60
- * Same as foreach but recursively visits each element definition
61
- * @see [capire](https://github.wdf.sap.corp/pages/cap/node.js/api#cds-reflect-foreach)
62
- */
63
- forall(x: Filter, visitor: Visitor, defs?: Definitions): this
64
- forall(visitor: Visitor, defs?: Definitions): this
65
-
66
- /**
67
- * Fetches definitions declared as children of a given parent context or service.
68
- * It fetches all definitions whose fully-qualified names start with the parent's name.
69
- * Returns the found definitions as an object with the local names as keys.
70
- * @example
71
- * ```js
72
- * let service = model.find ('service')
73
- * let entities = m.childrenOf (service)
74
- * ```
75
- * @param parent - either the parent itself or its fully-qualified name
76
- * @param filter - an optional filter to apply before picking a child
77
- */
78
- childrenOf(parent: any | string, filter?: ((def: LinkedDefinition) => boolean)): Definitions
79
-
80
- /**
81
- * Provides convenient access to the model's top-level definitions.
82
- * For example, you can use it in an es6-import-like fashion to avoid
83
- * working with fully-qualified names as follows:
84
- *
85
- * @example
86
- * ```js
87
- * let model = cds.reflect (cds.parse(`
88
- * namespace our.lovely.bookshop;
89
- * entity Books {...}
90
- * entity Authors {...}
91
- * `))
92
- * const {Books,Authors} = model.exports
93
- * SELECT.from (Books) .where ({ID:11})
94
- * ```
95
- */
96
- exports: Definitions & ((namespace: string) => Definitions)
97
- entities: Definitions & ((namespace: string) => Definitions)
98
- services: Definitions & ((namespace: string) => Definitions)
99
- definitions: Definitions
100
-
101
- }
102
-
103
- type Visitor = (def: LinkedDefinition, name: string, parent: LinkedDefinition, defs: Definitions) => void
104
- type Filter = string | ((def: LinkedDefinition) => boolean)
package/apis/log.d.ts DELETED
@@ -1,173 +0,0 @@
1
-
2
- /**
3
- * Create a new logger, or install a custom log formatter
4
- */
5
- export declare const log: LogFactory
6
-
7
- /**
8
- * Shortcut to `cds.log(...).debug`, returning `undefined` if `cds.log(...)._debug` is `false`.
9
- * Use like this:
10
- * @example
11
- * ```js
12
- * const dbg = cds.debug('foo')
13
- * ...
14
- * dbg && dbg('message')
15
- * ```
16
- *
17
- * @param name - logger name
18
- */
19
- export declare function debug (name: string): undefined | Log
20
-
21
- declare type LogFactory = {
22
-
23
- /**
24
- * Returns a trace logger for the given module if trace is switched on for it,
25
- * otherwise returns null. All cds runtime packages use this method for their
26
- * trace and debug output.
27
- *
28
- * By default this logger would prefix all output with `[sql] - `
29
- * You can change this by specifying another prefix in the options:
30
- * @example
31
- * ```js
32
- * const LOG = cds.log('sql|db', { prefix: 'cds.ql' })
33
- * ```
34
- *
35
- * Call `cds.log()` for a given module again to dynamically change the log level
36
- * of all formerly created loggers, for example:
37
- * @example
38
- * ```js
39
- * const LOG = cds.log('sql')
40
- * LOG.info ('this will show, as default level is info')
41
- * cds.log('sql', 'warn')
42
- * LOG.info('this will be suppressed now')
43
- * ```
44
- *
45
- * @param name - logger name
46
- * @param options - level, label and prefix
47
- * @returns the logger
48
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-log)
49
- */
50
- (name: string, options?: string | number | { level?: number, label?: string, prefix?: string }): Logger,
51
-
52
- /**
53
- * Set a custom formatter function like that:
54
- * ```js
55
- * cds.log.format = (module, level, ...args) => [ '[', module, ']', ...args ]
56
- * ```
57
- *
58
- * The formatter shall return an array of arguments, which are passed to the logger (for example, `console.log()`)
59
- */
60
- format: Formatter,
61
-
62
- /**
63
- * Set a custom logger.
64
- * ```js
65
- * cds.log.Logger = ...
66
- * ```
67
- */
68
- Logger: Logger,
69
-
70
- // FIXME
71
- /* eslint-disable-next-line @typescript-eslint/ban-types */
72
- winstonLogger (LoggerOptions?: { level?: string, levels?: any, format?: any, transports?: any, exitOnError?: boolean | Function, silent?: boolean }),
73
- }
74
-
75
- declare class Logger {
76
-
77
-
78
- /**
79
- * Logs with 'trace' level
80
- */
81
- trace: Log
82
-
83
- /**
84
- * Logs with 'debug' level
85
- */
86
- debug: Log
87
-
88
- /**
89
- * Logs with 'info' level
90
- */
91
- info: Log
92
-
93
- /**
94
- * Logs with 'warn' level
95
- */
96
- warn: Log
97
-
98
- /**
99
- * Logs with 'error' level
100
- */
101
- error: Log
102
-
103
- /**
104
- * Logs with default level
105
- */
106
- log: Log
107
-
108
- /**
109
- * @returns whether 'trace' level is active
110
- */
111
- _trace: boolean
112
-
113
- /**
114
- * @returns whether 'debug' level is active
115
- */
116
- _debug: boolean
117
-
118
- /**
119
- * @returns whether 'info' level is active
120
- */
121
- _info: boolean
122
-
123
- /**
124
- * @returns whether 'warn' level is active
125
- */
126
- _warn: boolean
127
-
128
- /**
129
- * @returns whether 'error' level is active
130
- */
131
- _error: boolean
132
-
133
- /**
134
- * Change the format for this logger instance:
135
- * ```
136
- * cds.log('foo').setFormat((module, level, ...args) => [ '[', module, ']', ...args ])
137
- * ```
138
- *
139
- * The formatter shall return an array of arguments, which are passed to the logger (for example, `console.log()`)
140
- */
141
- setFormat (formatter: Formatter)
142
-
143
- }
144
-
145
- declare type Formatter = {
146
-
147
- /**
148
- * Custom format function
149
- *
150
- * @param module - logger name
151
- * @param level - log level
152
- * @param args - additional arguments
153
- * @returns an array of arguments, which are passed to the logger (for example, `console.log()`)
154
- */
155
- (module: string, level: number, args: any[]): any[],
156
- }
157
-
158
- declare type Log = {
159
-
160
- /**
161
- * Logs a message
162
- *
163
- * @param message - text to log
164
- * @param optionalParams - additional parameters, same as in `console.log(text, param1, ...)`
165
- */
166
- (message?: any, ...optionalParams: any[]): void,
167
- }
168
-
169
- declare enum levels {
170
- // FIXME: check if this is a copy-paste error
171
- /* eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values */
172
- SILENT = 0, ERROR = 1, WARN = 2, INFO = 3, DEBUG = 4, TRACE = 5, SILLY = 5, VERBOSE = 5
173
- }
package/apis/models.d.ts DELETED
@@ -1,173 +0,0 @@
1
- import { Query as CQN, expr, _xpr } from './cqn'
2
- import { LinkedCSN } from './linked'
3
- import { CSN } from './csn'
4
-
5
- type _flavor = 'parsed' | 'xtended' | 'inferred'
6
- type _odata_options = {
7
- flavor?: 'v2' | 'v4' | 'w4' | 'x4',
8
- version?: 'v2' | 'v4',
9
- structs?: boolean,
10
- refs?: boolean,
11
- }
12
- type _options = {
13
- flavor?: _flavor,
14
- plain?: boolean,
15
- docs?: boolean,
16
- names?: string,
17
- odata?: _odata_options,
18
- } | _flavor
19
-
20
- type JSON = string
21
- type YAML = string
22
- type CDL = string
23
- type SQL = string
24
- type XML = string
25
- type EDM = { $version: string }
26
- type EDMX = XML
27
- type filename = string
28
-
29
-
30
- /**
31
- * The effective CDS model loaded during bootstrapping, which contains all service and entity definitions,
32
- * including required services.
33
- * Should only be ever set explictly in test scenarios!
34
- */
35
- export let model: LinkedCSN | undefined
36
-
37
- /**
38
- * Provides a set of methods to parse a given model, query or expression.
39
- * You can also use `cds.parse()` as a shortcut to `cds.parse.cdl()`.
40
- */
41
- export const parse: {
42
-
43
- /** Shortcut to `cds.parse.cdl()` */
44
- (cdl: CDL): CSN,
45
- cdl (cdl: CDL): CSN,
46
- cql (src: string): CQN,
47
- expr (src: string): expr,
48
- xpr (src: string): _xpr,
49
- ref (src: string): string[],
50
- }
51
-
52
- /**
53
- * Loads and parses models from the specified files.
54
- * Uses `cds.resolve` to fetch the respective models.
55
- * Essentially a shortcut for `cds.compile.to.csn(files)`
56
- * @param files - filenames of models or if folder containing models
57
- */
58
- export function get (files: '*' | filename | filename[], o?: _options): Promise<CSN>
59
-
60
- /**
61
- * Shortcut for `cds.get(files, 'inferred')`
62
- * @param files - filenames of models or if folder containing models
63
- */
64
- export function load (files: '*' | filename | filename[], o?: _options): Promise<CSN>
65
-
66
-
67
- /**
68
- * Resolves given file or module name(s) to an array of absolute file names.
69
- * Uses Node's `require.resolve` internally with the following additions:
70
- * - relative names are resolved relative to the current working directory instead of the current JavaScript module; hence, use __dirname if you want to find or load models relative to the current module.
71
- * - if no file extension is given, `.csn` and `.cds` will be appended in that order.
72
- * @param files - The file or module name(s) of a model or a folder containing models. Specify `'*'` to fetch moels from default locations, i.e. `[ 'db/', 'srv/', 'app/' ]`
73
- * @returns An array of absolute file names or `undefined` if none could be resolved.
74
- */
75
- export function resolve (files: '*' | filename | filename[]): filename[] | undefined
76
-
77
- /**
78
- * Turns the given plain CSN model into a linked model
79
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
80
- */
81
- declare const linked: (model: CSN) => LinkedCSN
82
-
83
- /**
84
- * Turns the given plain CSN model into a reflected model
85
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
86
- */
87
- export const reflect: (model: CSN) => LinkedCSN
88
-
89
- /**
90
- * Provides a set of methods to parse a given model, query or expression.
91
- * You can also use `cds.compile(csn).to('<output>')` as a fluent variant.
92
- */
93
- export const compile: {
94
-
95
- /** Shortcut for `cds.compile.to.csn()` */
96
- cdl (model: CDL, o?: _options): CSN,
97
-
98
- for: {
99
- odata (model: CSN, o?: _options): CSN,
100
- sql (model: CSN, o?: _options): CSN,
101
- },
102
- to: {
103
- parsed: {
104
- csn (files: filename[], o?: _options): Promise<CSN>,
105
- csn (model: CDL, o?: _options): CSN,
106
- },
107
- xtended: {
108
- csn (files: filename[], o?: _options): Promise<CSN>,
109
- csn (model: CDL, o?: _options): CSN,
110
- },
111
- inferred: {
112
- csn (files: filename[], o?: _options): Promise<CSN>,
113
- csn (model: CDL, o?: _options): CSN,
114
- },
115
- csn (files: filename[], o?: _options): Promise<CSN>,
116
- csn (model: CDL, o?: _options): CSN,
117
- yml (model: CSN, o?: _options): YAML,
118
- yaml (model: CSN, o?: _options): YAML,
119
- json (model: CSN, o?: _options): JSON,
120
- sql (model: CSN, o?: _options): SQL[],
121
- cdl (model: CSN, o?: _options): CDL | Iterable<[CDL, { file: filename }]>,
122
- edm (model: CSN, o?: _options | _odata_options): EDM | string,
123
- edmx (model: CSN, o?: _options | _odata_options): EDMX | Iterable<[EDMX, { file: filename }]>,
124
- hdbcds (model: CSN, o?: _options): SQL | Iterable<[SQL, { file: filename }]>,
125
- hdbtable (model: CSN, o?: _options): SQL | Iterable<[SQL, { file: filename }]>,
126
- },
127
-
128
- /** Fluent API variant */
129
- (model: CSN | CDL): {
130
- for: {
131
- odata (o?: _options): CSN,
132
- sql (o?: _options): CSN,
133
- },
134
- to: {
135
- parsed: { csn (o?: _options): CSN },
136
- xtended: { csn (o?: _options): CSN },
137
- inferred: { csn (o?: _options): CSN },
138
- csn (o?: _options): CSN,
139
- yml (o?: _options): YAML,
140
- yaml (o?: _options): YAML,
141
- json (o?: _options): JSON,
142
- sql (o?: _options): SQL[],
143
- cdl (o?: _options): CDL | Iterable<[CDL, { file: filename }]>,
144
- edm (o?: _options | _odata_options): EDM | string,
145
- edmx (o?: _options | _odata_options): EDMX | Iterable<[EDMX, { file: filename }]>,
146
- hdbcds (o?: _options): SQL | Iterable<[SQL, { file: filename }]>,
147
- hdbtable (o?: _options): SQL | Iterable<[SQL, { file: filename }]>,
148
- },
149
- },
150
-
151
- /** Async fluent variant reading from files */
152
- (files: filename[]): {
153
- for: {
154
- odata (o?: _options): Promise<CSN>,
155
- sql (o?: _options): Promise<CSN>,
156
- },
157
- to: {
158
- parsed: { csn (o?: _options): Promise <CSN> },
159
- xtended: { csn (o?: _options): Promise <CSN> },
160
- inferred: { csn (o?: _options): Promise <CSN> },
161
- csn (o?: _options): Promise <CSN>,
162
- yml (o?: _options): Promise <YAML>,
163
- yaml (o?: _options): Promise <YAML>,
164
- json (o?: _options): Promise <JSON>,
165
- sql (o?: _options): Promise <SQL[]>,
166
- cdl (o?: _options): Promise <CDL | Iterable<[CDL, { file: filename }]>>,
167
- edm (o?: _options | _odata_options): Promise <EDM | string>,
168
- edmx (o?: _options | _odata_options): Promise <EDMX | Iterable<[EDMX, { file: filename }]>>,
169
- hdbcds (o?: _options): Promise <SQL | Iterable<[SQL, { file: filename }]>>,
170
- hdbtable (o?: _options): Promise <SQL | Iterable<[SQL, { file: filename }]>>,
171
- },
172
- },
173
- }