@cap-js/cds-typer 0.3.0 → 0.4.0

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 CHANGED
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/).
6
6
 
7
- ## Version 0.3.1 - TBD
7
+ ## Version 0.4.1 - TBD
8
+
9
+ ## Version 0.4.0 - 2023-07-06
10
+ ### Added
11
+ - Support for enums when they are defined separately (not inline in the property type of an entity)
8
12
 
9
13
  ## Version 0.3.0 - 2023-06-26
10
14
  ### Added
package/README.md CHANGED
@@ -6,7 +6,7 @@ Generates `.ts` files for a CDS model to receive code completion in VS Code.
6
6
 
7
7
 
8
8
  ## Requirements and Setup
9
- This project is [available as `@cds-js/cds-typer`](https://www.npmjs.com/package/@cap-js/cds-typer) as NPM package.
9
+ This project is [available as `@cap-js/cds-typer`](https://www.npmjs.com/package/@cap-js/cds-typer) as NPM package.
10
10
 
11
11
  ### Usage
12
12
  The type generator can either be used as a standalone tool, or as part of of the [CDS VSCode-Extension](https://www.npmjs.com/package/@sap/vscode-cds).
@@ -45,6 +45,8 @@ const { Books } = require('../@types/mybookshop')
45
45
 
46
46
  From that point on you should receive code completion from the type system for `Books`.
47
47
 
48
+ _Note:_ the above command generates types for the model contained within the mentioned `schema.cds` file. If you have multiple `.cds` files that are included via `using` statements by `schema.cds`, then those files will also be included in the type generation process. If you have `.cds` files that are _not_ in some way included in `schema.cds`, you have to explicitly pass those as positional argument as well, if you want types for them.
49
+
48
50
  _cds-typer_ comes with rudimentary CLI support and a few command line options:
49
51
 
50
52
  - `--help`: prints all available parameters.
package/lib/file.js CHANGED
@@ -101,11 +101,11 @@ class SourceFile extends File {
101
101
  this.preamble = new Buffer()
102
102
  /** @type {Buffer} */
103
103
  this.types = new Buffer()
104
- /** @type {Buffer} */
105
- this.enums = new Buffer()
104
+ /** @type {{ buffer: Buffer, fqs: {name: string, fq: string}[]}} */
105
+ this.enums = { buffer: new Buffer(), fqs: [] }
106
106
  /** @type {Buffer} */
107
107
  this.classes = new Buffer()
108
- /** @type {{ buffer: Buffer, names: string[]} */
108
+ /** @type {{ buffer: Buffer, names: string[]}} */
109
109
  this.actions = { buffer: new Buffer(), names: [] }
110
110
  /** @type {Buffer} */
111
111
  this.aspects = new Buffer()
@@ -191,13 +191,26 @@ class SourceFile extends File {
191
191
  * @param {[string, string][]} kvs list of key-value pairs
192
192
  */
193
193
  addEnum(fq, name, kvs) {
194
- this.enums.add(`export enum ${name} {`)
195
- this.enums.indent()
194
+ // CDS differ from TS enums as they can use bools as value (TS: only number and string)
195
+ // So we have to emulate enums by adding an object (name -> value mappings)
196
+ // and a type containing all disctinct values.
197
+ // We can get away with this as TS doesn't feature nominal typing, so the structure
198
+ // is all we care about.
199
+ this.enums.fqs.push({ name, fq })
200
+ const bu = this.enums.buffer
201
+ bu.add('// enum')
202
+ bu.add(`export const ${name} = {`)
203
+ bu.indent()
204
+ const vals = new Set()
196
205
  for (const [k, v] of kvs) {
197
- this.enums.add(`${k} = ${v},`)
206
+ bu.add(`${k}: ${v},`)
207
+ vals.add(v)
198
208
  }
199
- this.enums.outdent()
200
- this.enums.add('}')
209
+ bu.outdent()
210
+ bu.add('}')
211
+ bu.add(`export type ${name} = ${[...vals].join(' | ')}`)
212
+ bu.add('')
213
+
201
214
  }
202
215
 
203
216
  /**
@@ -272,7 +285,7 @@ class SourceFile extends File {
272
285
  this.getImports().join(),
273
286
  this.preamble.join(),
274
287
  this.types.join(),
275
- this.enums.join(),
288
+ this.enums.buffer.join(),
276
289
  namespaces.join(),
277
290
  this.aspects.join(), // needs to be before classes
278
291
  this.classes.join(),
@@ -300,6 +313,8 @@ class SourceFile extends File {
300
313
  ) // singular -> plural aliases
301
314
  .concat(['// actions'])
302
315
  .concat(this.actions.names.map(name => `module.exports.${name} = '${name}'`))
316
+ .concat(['// enums'])
317
+ .concat(this.enums.fqs.map(({fq, name}) => `module.exports.${name} = Object.fromEntries(Object.entries(cds.model.definitions['${fq}'].enum).map(([k,v]) => [k,v.val]))`))
303
318
  .join('\n') + '\n'
304
319
  }
305
320
  }
package/lib/util.js CHANGED
@@ -208,22 +208,20 @@ function fixCSN(csn) {
208
208
  entity.erased ??= {}
209
209
  entity.erased[attr] = ea
210
210
  delete entity[attr]
211
- this.logger.info(`Removing inherited attribute ${attr} from ${entity.name}.`)
211
+ //this.logger.info(`Removing inherited attribute ${attr} from ${entity.name}.`)
212
212
  }
213
213
  }
214
214
  }
215
215
 
216
216
  for (const entity of Object.values(csn.definitions)) {
217
217
  let i = 0
218
- if (entity.includes) {
219
- while (
220
- (getSingularAnnotation(entity) || getPluralAnnotation(entity)) &&
221
- i < entity.includes.length
222
- ) {
223
- const parent = this.csn.definitions[entity.includes[i]]
224
- Object.values(annotations).flat().forEach(an => erase(entity, parent, an))
225
- i++
226
- }
218
+ while (
219
+ (getSingularAnnotation(entity) || getPluralAnnotation(entity)) &&
220
+ i < (entity.includes ?? []).length
221
+ ) {
222
+ const parent = csn.definitions[entity.includes[i]]
223
+ Object.values(annotations).flat().forEach(an => erase(entity, parent, an))
224
+ i++
227
225
  }
228
226
  }
229
227
  }
package/lib/visitor.js CHANGED
@@ -260,10 +260,12 @@ class Visitor {
260
260
  const ns = this.resolver.resolveNamespace(name.split('.'))
261
261
  const file = this.getNamespaceFile(ns)
262
262
  if ('enum' in type) {
263
+ // in case of strings, wrap in quotes and fallback to key to make sure values are attached for every key
264
+ const val = (k,v) => type.type === 'cds.String' ? `"${v ?? k}"` : v
263
265
  file.addEnum(
264
266
  name,
265
267
  clean,
266
- Object.entries(type.enum).map(([k, v]) => [k, v.val])
268
+ Object.entries(type.enum).map(([k, v]) => [k, val(k, v.val)])
267
269
  )
268
270
  } else {
269
271
  // alias
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/cds-typer",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Generates .ts files for a CDS model to receive code completion in VS Code",
5
5
  "main": "index.js",
6
6
  "homepage": "https://cap.cloud.sap/",
package/lib/compile.d.ts DELETED
@@ -1,273 +0,0 @@
1
- import { Path, SourceFile} from './file'
2
- import { Logger } from './logging';
3
-
4
- // mock
5
- interface CSN {
6
- definitions?: { [key: string]: EntityCSN }
7
- }
8
-
9
- interface EntityCSN {
10
- cardinality?: {
11
- max?: '*' | number
12
- }
13
- }
14
-
15
- interface TypeResolveInfo {
16
- isBuiltin: boolean,
17
- isInlineDefinition: boolean,
18
- isForeignKeyReference: boolean,
19
- type: string,
20
- path?: Path,
21
- csn?: CSN,
22
-
23
- /**
24
- * When nested inline types require additional imports. E.g.:
25
- * // mymodel.cds
26
- * Foo {
27
- * bar: {
28
- * baz: a.b.c.Baz // need to require a.b.c in mymodel.cds!
29
- * }
30
- * }
31
- */
32
- imports: Path[]
33
- }
34
-
35
- interface CompileParameters {
36
- rootDirectory: String,
37
- logLevel: number,
38
- jsConfigPath?: string
39
- }
40
-
41
- interface VisitorOptions {
42
- // if set to true, _all_ properties are generated as optional ?:.
43
- // This is the standard CAP behaviour, where any property could not be available/ not yet be constructed
44
- // at any point
45
- propertiesOptional: boolean
46
- }
47
-
48
- type VisitorParameters = { logger?: Logger, options?: VisitorOptions }
49
-
50
- /**
51
- * Compiles a .cds file to Typescript types.
52
- * @param inputFile path to input .cds file
53
- * @param parameters path to root directory for all generated files, min log level
54
- */
55
- export function compileFromFile(inputFile: string, parameters: CompileParameters): Promise<string[]>;
56
-
57
- /**
58
- * Compiles a CSN object to Typescript types.
59
- * @param csn CSN
60
- * @param parameters path to root directory for all generated files, min log level
61
- */
62
- export function compileFromCSN(csn: CSN, parameters: CompileParameters): Promise<string[]>;
63
-
64
- /**
65
- * Writes the accompanying jsconfig.json file to the specified paths.
66
- * Tries to merge nicely if an existing file is found.
67
- * @param file filepath to jsconfig.json.
68
- * @param logger logger
69
- */
70
- export function writeJsConfig(file: string, logger: Logger);
71
-
72
- export class Visitor {
73
- /**
74
- * @param csn root CSN
75
- */
76
- constructor(csn: CSN, params: VisitorParameters);
77
-
78
- /**
79
- * Determines the file corresponding to the namespace.
80
- * If no such file exists yet, it is created first.
81
- * @param {string} path the name of the namespace (foo.bar.baz)
82
- * @returns the file corresponding to that namespace name
83
- */
84
- private getNamespaceFile(path: Path): SourceFile;
85
-
86
- /**
87
- * Conveniently combines _resolveNamespace and _trimNamespace
88
- * to end up with both the resolved Path of the namespace,
89
- * and the clean name of the class.
90
- * @param fq the fully qualified name of an entity.
91
- * @returns a tuple, [0] holding the path to the namespace, [1] holding the clean name of the entity.
92
- */
93
- private untangle(fq: string): [Path, string];
94
-
95
- /**
96
- * Visits all definitions within the CSN definitions.
97
- */
98
- private visitDefinitions(): void;
99
-
100
- /**
101
- * Visits a single entity from the CSN's definition field.
102
- * Will call _printEntity or _printAction based on the entity's kind.
103
- * @param name name of the entity, fully qualified as is used in the definition field.
104
- * @param entity CSN data belonging to the entity to perform lookups in.
105
- */
106
- private visitEntity(name: string, entity: CSN): void;
107
- private _printEntity(name: string, entity: CSN): void;
108
- private _printAction(name: string, action: CSN): void;
109
- private _printType(name: string, type: CSN): void;
110
- private _printAspect(name: string, aspect: CSN): void;
111
-
112
- /**
113
- * Visits a single element in an entity.
114
- * @param name name of the element
115
- * @param element CSN data belonging to the the element.
116
- * @param file the namespace file the surrounding entity is being printed into.
117
- * @param buffer buffer to add the definition to. If no buffer is passed, the passed file's class buffer is used instead.
118
- */
119
- public visitElement(name: string, element: CSN, file: SourceFile, buffer?: Buffer): void;
120
-
121
- /**
122
- * Attempts to retrieve the max cardinality of a CSN for an entity.
123
- * @param element csn of entity to retrieve cardinality for
124
- * @returns max cardinality of the element.
125
- * If no cardinality is attached to the element, cardinality is 1.
126
- * If it is set to '*', result is Infinity.
127
- */
128
- private getMaxCardinality(element: EntityCSN): number;
129
-
130
- /**
131
- * Convenience method to shave off the namespace of a fully qualified path.
132
- * More specifically, only the parts (reading from right to left) that are of
133
- * kind "entity" are retained.
134
- * a.b.c.Foo -> Foo
135
- * Bar -> Bar
136
- * sap.cap.Book.text -> Book.text (assuming Book and text are both of kind "entity")
137
- * @param p path
138
- * @returns the entity name without leading namespace.
139
- */
140
- private _trimNamespace(p: string): string;
141
-
142
- /**
143
- * Resolves a fully qualified identifier to a namespace.
144
- * In an identifier 'a.b.c.D.E', the namespace is the part of the identifier
145
- * read from left to right which does not contain a kind 'context' or 'service'.
146
- * That is, if in the above example 'D' is a context and 'E' is a service,
147
- * the resulting namespace is 'a.b.c'.
148
- * @param pathParts the distinct parts of the namespace, i.e. ['a','b','c','D','E']
149
- * @returns the namespace's name, i.e. 'a.b.c'.
150
- */
151
- private _resolveNamespace(pathParts: string[]): string;
152
-
153
- /**
154
- * Puts a passed string in docstring format.
155
- * @param doc raw string to docify. May contain linebreaks.
156
- * @returns an array of lines wrapped in doc format. The result is not
157
- * concatenated to be properly indented by `buffer.add(...)`.
158
- */
159
- private _docify(doc: string): string[];
160
-
161
- /**
162
- * Transforms an entity or CDS aspect into a JS aspect (aka mixin).
163
- * That is, for an element A we get:
164
- * - the function A(B) to mix the aspect into another class B
165
- * - the const AXtended which represents the entity A with all of its aspects mixed in (this const is not exported)
166
- * - the type A to use for external typing and is derived from AXtended.
167
- * @param name the name of the entity
168
- * @param element the pointer into the CSN to extract the elements from
169
- * @param buffer the buffer to write the resulting definitions into
170
- * @param cleanName the clean name to use. If not passed, it is derived from the passed name instead.
171
- */
172
- private _aspectify(name: string, element: CSN, buffer: Buffer, cleanName?: string);
173
-
174
- /**
175
- * Convenient API to consume resolveType.
176
- * Internally calls resolveType, determines how it has to be imported,
177
- * used, etc. relative to file and just returns the name under
178
- * which it will finally be known within file.
179
- *
180
- * For example:
181
- * model1.cds contains entity Foo
182
- * model2.cds references Foo
183
- *
184
- * calling resolveAndRequire({... Foo}, model2.d.ts) would then:
185
- * 1. add an import of model1 to model2 with proper path resolution and alias, e.g. "import * as m1 from './model1'"
186
- * 2. resolve any singular/ plural issues and association/ composition around it
187
- * 3. return a properly prefixed name to use within model2.d.ts, e.g. "m1.Foo"
188
- *
189
- * @param element the CSN element to resolve the type for.
190
- * @param file source file for context.
191
- * @returns name of the resolved type
192
- */
193
- private resolveAndRequire(element: CSN, file: SourceFile): string;
194
-
195
- /**
196
- * Resolves an element's type to either a builtin or a user defined type.
197
- * Enriched with additional information for improved printout (see return type).
198
- * @param element the CSN element to resolve the type for.
199
- * @param file source file for context.
200
- * @returns description of the resolved type
201
- */
202
- private resolveType(element: CSN, file: SourceFile): TypeResolveInfo;
203
-
204
- /**
205
- * Resolves the fully qualified name of an entity to its parent entity.
206
- * _resolveParent(a.b.c.D) -> CSN {a.b.c}
207
- * @param name fully qualified name of the entity to resolve the parent of.
208
- * @returns the resolved parent CSN.
209
- */
210
- private _resolveParent(name: String): CSN;
211
-
212
- /**
213
- * Attempts to resolve a type that could reference another type.
214
- * @param val
215
- * @param into see resolveType()
216
- * @param file only needed as we may call _resolveInlineDeclarationType from here. Will be expelled at some point.
217
- */
218
- private _resolvePotentialReferenceType(val: any, into: TypeResolveInfo, file: SourceFile);
219
-
220
-
221
- /**
222
- * Resolves an inline declaration of a type.
223
- * We can encounter declarations like:
224
- *
225
- * record : array of {
226
- * column : String;
227
- * data : String;
228
- * }
229
- *
230
- * These have to be resolved to a new type.
231
- *
232
- * @param items the properties of the inline declaration.
233
- * @param into see resolveType()
234
- * @param relativeToindent the sourcefile in which we have found the reference to the type.
235
- * This is important to correctly detect when a field in the inline declaration is referencing
236
- * types from the CWD. In that case, we will not add an import for that type and not add a namespace-prefix.
237
- */
238
- private _resolveInlineDeclarationType(items: Array<unknown>, into: TypeResolveInfo, relativeTo: SourceFile): void;
239
-
240
- /**
241
- * Attempts to resolve a string to a type.
242
- * String is supposed to refer to either a builtin type
243
- * or any type defined in CSN.
244
- * @param t fully qualified type, like cds.String, or a.b.c.d.Foo
245
- * @param into optional dictionary to fill by reference, see resolveType()
246
- * @returns see resolveType()
247
- */
248
- private _resolveTypeName(t: string, into: TypeResolveInfo): TypeResolveInfo;
249
-
250
- /**
251
- * Wraps type into association to scalar.
252
- * @param t the singular type name.
253
- */
254
- private _createToOneAssociation(t: string): string;
255
-
256
- /**
257
- * Wraps type into association to vector.
258
- * @param t the singular type name.
259
- */
260
- private _createToManyAssociation(t: string): string;
261
-
262
- /**
263
- * Wraps type into composition of scalar.
264
- * @param t the singular type name.
265
- */
266
- private _createCompositionOfOne(t: string): string;
267
-
268
- /**
269
- * Wraps type into composition of vector.
270
- * @param t the singular type name.
271
- */
272
- private _createCompositionOfMany(t: string): string;
273
- }
package/lib/file.d.ts DELETED
@@ -1,208 +0,0 @@
1
- type KVs = [string, string][]
2
- type Namespace = {[key: string]: Buffer}
3
- type ActionParams = [string, string][]
4
- type AsDirectoryParams = {relative: string | undefined, local: boolean, posix: boolean}
5
-
6
- /**
7
- * String buffer to conveniently append strings to.
8
- */
9
- export class Buffer {
10
- public parts: string[];
11
- private indentation: string;
12
- private currentIndent: string;
13
-
14
- constructor(indentation: string);
15
-
16
- /**
17
- * Indents by the predefined spacing.
18
- */
19
- indent(): void;
20
-
21
- /**
22
- * Removes one level of indentation.
23
- */
24
- outdent(): void;
25
-
26
- /**
27
- * Concats all elements in the buffer into a single string.
28
- * @param glue string to intersperse all buffer contents with
29
- * @returns string spilled buffer contents.
30
- */
31
- join(glue: string): string;
32
-
33
- /**
34
- * Clears the buffer.
35
- */
36
- clear(): void;
37
-
38
- /**
39
- * Adds an element to the buffer with the current indentation level.
40
- * @param part
41
- */
42
- add(part: string): void;
43
- }
44
-
45
- /**
46
- * Convenience class to handle path qualifiers.
47
- */
48
- export class Path {
49
- private parts: string[];
50
-
51
- /**
52
- *
53
- * @param parts parts of the path. 'a.b.c' -> ['a', 'b', 'c']
54
- * @param kind FIXME: currently unused
55
- */
56
- constructor(parts: string[], kind: string);
57
-
58
- /**
59
- * @returns the path to the parent directory. 'a.b.c'.getParent() -> 'a.b'
60
- */
61
- getParent(): Path;
62
-
63
- /**
64
- * Transfoms the Path into a directory path.
65
- * @param relative if defined, the path is constructed relative to this directory
66
- * @param local if set to true, './' is prefixed to the directory
67
- * @param posix if set to true, all slashes will be forward slashes on every OS. Useful for require/ import
68
- * @returns directory 'a.b.c'.asDirectory() -> 'a/b/c' (or a\b\c when on Windows without passing posix = true)
69
- */
70
- asDirectory(params: AsDirectoryParams): string;
71
-
72
- /**
73
- * Transforms the Path into a namespace qualifier.
74
- * @returns namespace qualifier 'a.b.c'.asNamespace() -> 'a.b.c'
75
- */
76
- asNamespace(): string;
77
-
78
- /**
79
- * Transforms the Path into an identifier that can be used as variable name.
80
- * @returns identifier 'a.b.c'.asIdentifier() -> '_a_b_c', ''.asIdentifier() -> '_'
81
- */
82
- asIdentifier(): string;
83
-
84
- /**
85
- * @returns true, iff the Path refers to the current working directory, aka './'
86
- */
87
- isCwd(relative: string | undefined): boolean;
88
- }
89
-
90
- /**
91
- * Source file containing several buffers.
92
- */
93
- export class SourceFile {
94
- public readonly path: Path;
95
- private imports: {}
96
- private types: Buffer;
97
- private classes: Buffer;
98
- private enums: Buffer;
99
- private actions: Buffer;
100
- private namespaces: Namespace;
101
- private classNames: {}
102
- private inflections: [string, string][]
103
-
104
- constructor(path: string);
105
-
106
- /**
107
- * Adds a pair of singular and plural inflection.
108
- * These are later used to generate the singular -> plural
109
- * aliases in the index.js file.
110
- * @param singular singular type without namespace.
111
- * @param plural plural type without namespace
112
- * @param original original entity name without namespace.
113
- * In many cases this will be the same as plural.
114
- */
115
- addInflection(singular: string, plural: string, original: string);
116
-
117
- /**
118
- * Adds an action definition in form of a arrow function to the file.
119
- * @param name name of the action
120
- * @param params list of parameters, passed as [name, type] pairs
121
- * @param returns the return type of the action
122
- */
123
- addAction(name: string, params: ActionParams, returns: string);
124
-
125
- /**
126
- * Adds an enum to this file.
127
- * @param fq fully qualified name of the enum
128
- * @param name local name of the enum
129
- * @param kvs list of key-value pairs
130
- */
131
- addEnum(fq: string, clean: string, kvs: KVs);
132
-
133
- /**
134
- * Adds an arbitrary piece of code that is added
135
- * right after the imports.
136
- * @param code the preamble code.
137
- */
138
- addPreamble(code: string);
139
-
140
- /**
141
- * Adds a type alias to this file.
142
- * @param fq fully qualified name of the enum
143
- * @param name local name of the enum
144
- * @param rhs the right hand side of the assignment
145
- */
146
- addType(fq: string, clean: string, rhs: string);
147
-
148
- /**
149
- * Adds a class to this file.
150
- * This differs from writing to the classes buffer,
151
- * as it is just a cache to collect all classes that
152
- * are supposed to be present in this file.
153
- * @param clean cleaned name of the class
154
- * @param fq fully qualified name, including the namespace
155
- */
156
- addClass(clean: string, fq: string): void;
157
-
158
- /**
159
- * Retrieves or creates and retrieves a sub namespace
160
- * with a given name.
161
- * @param name of the sub namespace.
162
- * @returns the sub namespace.
163
- */
164
- getSubNamespace(name: string): Namespace;
165
-
166
- /**
167
- * Adds an import if it does not exist yet.
168
- * @param imp qualifier for the namespace to import.
169
- */
170
- addImport(imp: Path): void;
171
-
172
- /**
173
- * Writes all imports to a buffer, relative to the current file.
174
- * Creates a new buffer on each call, as concatenating import strings directly
175
- * upon discovering them would complicate filtering out duplicate entries.
176
- * @returns all imports written to a buffer.
177
- */
178
- getImports(): Buffer;
179
-
180
- /**
181
- * Creates one string from the buffers representing the type definitions.
182
- * @returns complete file contents.
183
- */
184
- toTypeDefs(): string;
185
-
186
- /**
187
- * Concats the classnames to an export dictionary
188
- * to create the accompanying JS file for the typings.
189
- * @returns a string containing the module.exports for the JS file.
190
- */
191
- toJSExports(): string;
192
- }
193
-
194
- /**
195
- * Base definitions used throughout the typing process,
196
- * such as Associations and Compositions.
197
- */
198
- declare const baseDefinitions: SourceFile;
199
-
200
- /**
201
- * Writes the files to disk. For each source, a index.d.ts holding the type definitions
202
- * and a index.js holding implementation stubs is generated at the appropriate directory.
203
- * Missing directories are created automatically and asynchronously.
204
- * @param root root directory to prefix all directories with
205
- * @param sources source files to write to disk
206
- * @returns Promise that resolves to a list of all directory paths pointing to generated files.
207
- */
208
- export function writeout(root: string, sources: SourceFile[]): Promise<string[]>;
package/lib/logging.d.ts DELETED
@@ -1,50 +0,0 @@
1
- export enum Levels {
2
- TRACE = 1,
3
- DEBUG = 2,
4
- INFO = 3,
5
- WARNING = 4,
6
- ERROR = 8,
7
- CRITICAL = 16,
8
- NONE = 32
9
- }
10
-
11
- export class Logger {
12
- private mask: number;
13
-
14
- public constructor();
15
-
16
- /**
17
- * Add all log levels starting at level.
18
- * @param level level to start from.
19
- */
20
- public addFrom(level: number): void;
21
-
22
- /**
23
- * Adds a log level to react to.
24
- * @param level the level to react to.
25
- */
26
- public add(level: number): void;
27
-
28
- /**
29
- * Ignores a log level.
30
- * @param level the level to ignore.
31
- */
32
- public ignore(level: number): void;
33
-
34
- /**
35
- * Attempts to log a message.
36
- * Only iff levelName is a valid log level
37
- * and the corresponding number if part of mask,
38
- * the message gets logged.
39
- * @param levelName name of the log level.
40
- * @param message message to log.
41
- */
42
- private _log(levelName: Levels, message: string);
43
-
44
- public trace(message: string);
45
- public debug(message: string);
46
- public info(message: string);
47
- public warning(message: string);
48
- public error(message: string);
49
- public critical(message: string);
50
- }
package/lib/util.d.ts DELETED
@@ -1,87 +0,0 @@
1
- interface Annotations {
2
- name?: string,
3
- '@singular'?: string,
4
- '@plural'?: string
5
- }
6
-
7
- interface CommandlineFlag {
8
- desc: string,
9
- default?: any
10
- }
11
-
12
- interface ParsedFlags {
13
- positional: string[],
14
- named: {[key: string]: any}
15
- }
16
-
17
- /**
18
- * Tries to retrieve an annotation that specifies the singular name
19
- * from a CSN. Valid annotations are listed in util.annotations
20
- * and their precedence is in order of definition.
21
- * If no singular is specified at all, undefined is returned.
22
- * @param csn the CSN of an entity to check
23
- * @returns the singular annotation or undefined
24
- */
25
- export function getSingularAnnotation(csn: {}): string | undefined;
26
-
27
- /**
28
- * Tries to retrieve an annotation that specifies the plural name
29
- * from a CSN. Valid annotations are listed in util.annotations
30
- * and their precedence is in order of definition.
31
- * If no plural is specified at all, undefined is returned.
32
- * @param csn the CSN of an entity to check
33
- * @returns the plural annotation or undefined
34
- */
35
- export function getPluralAnnotation(csn: {}): string | undefined;
36
-
37
-
38
- /**
39
- * Users can specify that they want to refer to localisation
40
- * using the syntax {i18n>Foo}, where Foo is the name of the
41
- * entity as found in the .cds file
42
- * (see: https://pages.github.tools.sap/cap/docs/guides/i18n)
43
- * As this throws off the naming, we remove this wrapper
44
- * unlocalize("{i18n>Foo}") -> "Foo"
45
- * @param name the entity name (singular or plural).
46
- * @returns the name without localisation syntax or untouched.
47
- */
48
- export function unlocalize(name: string): string;
49
-
50
- /**
51
- * Attempts to derive the singular form of an English noun.
52
- * If '@singular' is passed as annotation, that is preferred.
53
- * @param dn annotations
54
- * @param stripped if true, leading namespace will be stripped
55
- */
56
- export function singular4(dn: Annotations | string, stripped: boolean): string;
57
-
58
- /**
59
- * Attempts to derive the plural form of an English noun.
60
- * If '@plural' is passed as annotation, that is preferred.
61
- * @param dn annotations
62
- * @param stripped if true, leading namespace will be stripped
63
- */
64
- export function plural4(dn: Annotations | string, stripped: boolean): string;
65
-
66
- /**
67
- * Parses command line arguments into named and positional parameters.
68
- * Named parameters are expected to start with a double dash (--).
69
- * If the next argument `B` after a named parameter `A` is not a named parameter itself,
70
- * `B` is used as value for `A`.
71
- * If `A` and `B` are both named parameters, `A` is just treated as a flag (and may receive a default value).
72
- * Only named parameters that occur in validFlags are allowed. Specifying named flags that are not listed there
73
- * will cause an error.
74
- * Named parameters that are either not specified or do not have a value assigned to them may draw a default value
75
- * from their definition in validFlags.
76
- * @param argv list of command line arguments
77
- * @param validFlags allowed flags. May specify default values.
78
- */
79
- export function parseCommandlineArgs(argv: string[], validFlags: {[key: string]: CommandlineFlag}): ParsedFlags;
80
-
81
- /**
82
- * Performs a deep merge of the passed objects into the first object.
83
- * See Object.assign(target, source).
84
- * @param target object to assign into.
85
- * @param source object to assign from.
86
- */
87
- export function deepMerge(target: {}, source: {}): void;