@cap-js/cds-typer 0.37.0 → 0.38.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/lib/cli.js CHANGED
@@ -149,6 +149,10 @@ const flags = enrichFlagSchema({
149
149
  default: './',
150
150
  type: 'string'
151
151
  },
152
+ outputDTsFiles: parameterTypes.boolean({
153
+ desc: '(experimental) If set to true, emits .d.ts files for each generated .js file. If set to false (default), emits .ts files instead. Note: skipLibCheck must be set to true in your tsconfig for this option to work properly.',
154
+ default: 'false',
155
+ }),
152
156
  help: {
153
157
  desc: 'This text.',
154
158
  },
package/lib/file.js CHANGED
@@ -162,7 +162,7 @@ class SourceFile extends File {
162
162
  * @param {string} options.name - name of the lambda
163
163
  * @param {import('./typedefs').visitor.ParamInfo[]} [options.parameters] - list of parameters, passed as [name, modifier, type, doc] pairs
164
164
  * @param {string} [options.returns] - the return type of the function
165
- * @param {string} [options.self] - what is set as "__self", which is used for bound actions
165
+ * @param {string} [options.self] - what is set as "__self", which is used for bound actions. For unbound actions, this will be `never` (null would lead to incorrect type reduction)
166
166
  * @param {'action' | 'function'} options.kind - kind of the lambda
167
167
  * @param {string} [options.initialiser] - the initialiser expression
168
168
  * @param {boolean} [options.isStatic] - whether the lambda is static
@@ -188,7 +188,7 @@ class SourceFile extends File {
188
188
  * stringifyLambda({name: 'f', parameters: [{name:'p',type:'T'}], returns: 'number'}) // { (p: T): number, __parameters: { p: T } }
189
189
  * ```
190
190
  */
191
- static stringifyLambda({name, parameters=[], returns='any', kind, initialiser, self='null', isStatic=false, callStyles={positional:true, named:true}, doc}) {
191
+ static stringifyLambda({name, parameters=[], returns='any', kind, initialiser, self='never', isStatic=false, callStyles={positional:true, named:true}, doc}) {
192
192
  let docStr = doc?.length ? doc.join('\n')+'\n' : ''
193
193
  const parameterTypes = parameters.map(({name, modifier, type, doc}) => `${doc?'\n'+doc:''}${normalise(name)}${modifier}: ${type}`).join(', ')
194
194
  const parameterTypeAsObject = parameterTypes.length
@@ -825,10 +825,11 @@ const writeout = async (root, sources) =>
825
825
  Promise.all(
826
826
  sources.map(async source => {
827
827
  const dir = path.join(root, source.path.asDirectory({local: false, posix: false}))
828
+ const outputFile = configuration.outputDTsFiles ? 'index.d.ts' : 'index.ts'
828
829
  try {
829
830
  await fs.mkdir(dir, { recursive: true })
830
831
  await Promise.all([
831
- fs.writeFile(path.join(dir, 'index.ts'), source.toTypeDefs()),
832
+ fs.writeFile(path.join(dir, outputFile), source.toTypeDefs()),
832
833
  fs.writeFile(path.join(dir, 'index.js'), source.toJSExports()),
833
834
  ])
834
835
 
@@ -184,7 +184,7 @@ class EntityRepository {
184
184
 
185
185
  /**
186
186
  * Derives an identifier from an entity info.
187
- * That identifier can be used to refer to a specific entity within an index.ts file.
187
+ * That identifier can be used to refer to a specific entity within an index.ts / index.d.ts file.
188
188
  * By passing a relative file, the identifier will be preceeded with a scope if needed.
189
189
  * @param {object} options - the options
190
190
  * @param {EntityInfo} options.info - the entity info
package/lib/typedefs.d.ts CHANGED
@@ -189,6 +189,7 @@ export module config {
189
189
 
190
190
  export type Configuration = {
191
191
  outputDirectory: string,
192
+ outputDTsFiles: boolean,
192
193
  cache: 'none' | 'blake2s256'
193
194
  logLevel: number,
194
195
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/cds-typer",
3
- "version": "0.37.0",
3
+ "version": "0.38.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
  "repository": "github:cap-js/cds-typer",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@cap-js/cds-types": "^0",
48
- "@stylistic/eslint-plugin-js": "^4.2.0",
48
+ "@stylistic/eslint-plugin": "^5.3.1",
49
49
  "acorn": "^8.10.0",
50
50
  "eslint": "^9",
51
51
  "eslint-plugin-jsdoc": "^51.2.1",
@@ -54,6 +54,7 @@
54
54
  "cds": {
55
55
  "typer": {
56
56
  "output_directory": "@cds-models",
57
+ "output_d_ts_files": false,
57
58
  "inline_declarations": "flat",
58
59
  "target_module_type": "auto",
59
60
  "properties_optional": true,
@@ -84,6 +85,11 @@
84
85
  "description": "Root directory to write the generated files to.",
85
86
  "default": "@cds-models"
86
87
  },
88
+ "output_d_ts_files": {
89
+ "type": "boolean",
90
+ "description": "(experimental) If set to true, emits .d.ts files for each generated .js file. If set to false (default), emits .ts files instead. Note: skipLibCheck must be set to true in your tsconfig for this option to work properly.",
91
+ "default": false
92
+ },
87
93
  "log_level": {
88
94
  "type": "string",
89
95
  "description": "Minimum log level that is printed.\nThe default is only used if no explicit value is passed\nand there is no configuration passed via cds.env either.",