@loopback/cli 4.0.0 → 4.1.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.
Files changed (57) hide show
  1. package/.yo-rc.json +22 -0
  2. package/LICENSE +1 -1
  3. package/bin/cli-main.js +1 -1
  4. package/generators/app/index.js +1 -1
  5. package/generators/controller/index.js +1 -1
  6. package/generators/copyright/fs.js +1 -1
  7. package/generators/copyright/git.js +1 -1
  8. package/generators/copyright/header.js +1 -1
  9. package/generators/copyright/index.js +1 -1
  10. package/generators/copyright/license.js +2 -2
  11. package/generators/datasource/index.js +1 -1
  12. package/generators/discover/import-discovered-model.js +1 -1
  13. package/generators/discover/index.js +72 -10
  14. package/generators/example/downloader.js +1 -1
  15. package/generators/example/index.js +1 -1
  16. package/generators/extension/index.js +1 -1
  17. package/generators/import-lb3-models/index.js +1 -1
  18. package/generators/import-lb3-models/lb3app-loader.js +1 -1
  19. package/generators/import-lb3-models/migrate-model.js +1 -1
  20. package/generators/import-lb3-models/model-names.js +1 -1
  21. package/generators/interceptor/index.js +1 -1
  22. package/generators/model/index.js +1 -1
  23. package/generators/model/property-definition.js +1 -1
  24. package/generators/model/templates/model.ts.ejs +11 -4
  25. package/generators/observer/index.js +1 -1
  26. package/generators/openapi/index.js +1 -1
  27. package/generators/openapi/schema-helper.js +1 -1
  28. package/generators/openapi/spec-helper.js +1 -1
  29. package/generators/openapi/spec-loader.js +1 -1
  30. package/generators/openapi/utils.js +1 -1
  31. package/generators/relation/base-relation.generator.js +1 -1
  32. package/generators/relation/belongs-to-relation.generator.js +1 -1
  33. package/generators/relation/has-many-relation.generator.js +1 -1
  34. package/generators/relation/has-many-through-relation.generator.js +1 -1
  35. package/generators/relation/has-one-relation.generator.js +1 -1
  36. package/generators/relation/index.js +1 -1
  37. package/generators/relation/references-many-relation.generator.js +1 -1
  38. package/generators/relation/utils.generator.js +1 -1
  39. package/generators/repository/index.js +1 -1
  40. package/generators/rest-crud/crud-rest-component.js +1 -1
  41. package/generators/rest-crud/index.js +23 -1
  42. package/generators/rest-crud/templates/src/model-endpoints/model.rest-config-template.ts.ejs +1 -0
  43. package/generators/service/index.js +1 -1
  44. package/generators/update/index.js +1 -1
  45. package/lib/artifact-generator.js +1 -1
  46. package/lib/ast-helper.js +1 -1
  47. package/lib/base-generator.js +1 -1
  48. package/lib/cli.js +1 -1
  49. package/lib/debug.js +1 -1
  50. package/lib/globalize.js +1 -1
  51. package/lib/model-discoverer.js +1 -1
  52. package/lib/project-generator.js +1 -1
  53. package/lib/tab-completion.js +1 -1
  54. package/lib/update-index.js +1 -1
  55. package/lib/utils.js +1 -1
  56. package/lib/version-helper.js +1 -1
  57. package/package.json +90 -90
package/.yo-rc.json CHANGED
@@ -1251,6 +1251,13 @@
1251
1251
  "name": "views",
1252
1252
  "hide": false
1253
1253
  },
1254
+ "relations": {
1255
+ "type": "Boolean",
1256
+ "description": "Discover and create relations",
1257
+ "default": false,
1258
+ "name": "relations",
1259
+ "hide": false
1260
+ },
1254
1261
  "schema": {
1255
1262
  "type": "String",
1256
1263
  "description": "Schema to discover",
@@ -1270,6 +1277,13 @@
1270
1277
  "description": "Specify the directory into which the `model.model.ts` files will be placed",
1271
1278
  "name": "outDir",
1272
1279
  "hide": false
1280
+ },
1281
+ "optionalId": {
1282
+ "type": "Boolean",
1283
+ "description": "Boolean to mark id property as optional field",
1284
+ "default": false,
1285
+ "name": "optionalId",
1286
+ "hide": false
1273
1287
  }
1274
1288
  },
1275
1289
  "arguments": [
@@ -1577,6 +1591,14 @@
1577
1591
  "name": "basePath",
1578
1592
  "hide": false
1579
1593
  },
1594
+ "readonly": {
1595
+ "type": "Boolean",
1596
+ "required": false,
1597
+ "description": "Create readonly APIs",
1598
+ "default": false,
1599
+ "name": "readonly",
1600
+ "hide": false
1601
+ },
1580
1602
  "config": {
1581
1603
  "type": "String",
1582
1604
  "alias": "c",
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) IBM Corp. 2017,2019.
1
+ Copyright (c) IBM Corp. and LoopBack contributors 2017,2019.
2
2
  Node module: @loopback/cli
3
3
  This project is licensed under the MIT License, full text below.
4
4
 
package/bin/cli-main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
2
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
3
3
  // Node module: @loopback/cli
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2017,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2017,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -43,7 +43,7 @@ This project is licensed under the ${license.name}, full text below.
43
43
  ${text}
44
44
  `;
45
45
  /*
46
- Copyright (c) IBM Corp. 2018,2019. All Rights Reserved.
46
+ Copyright (c) IBM Corp. and LoopBack contributors 2018,2019. All Rights Reserved.
47
47
  Node module: @loopback/boot
48
48
  This project is licensed under the MIT License, full text below.
49
49
 
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -31,6 +31,12 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
31
31
  default: true,
32
32
  });
33
33
 
34
+ this.option('relations', {
35
+ type: Boolean,
36
+ description: g.f('Discover and create relations'),
37
+ default: false,
38
+ });
39
+
34
40
  this.option('schema', {
35
41
  type: String,
36
42
  description: g.f('Schema to discover'),
@@ -50,6 +56,12 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
50
56
  ),
51
57
  default: undefined,
52
58
  });
59
+
60
+ this.option('optionalId', {
61
+ type: Boolean,
62
+ description: g.f('Boolean to mark id property as optional field'),
63
+ default: false,
64
+ });
53
65
  }
54
66
 
55
67
  _setupGenerator() {
@@ -277,16 +289,26 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
277
289
  for (let i = 0; i < this.discoveringModels.length; i++) {
278
290
  const modelInfo = this.discoveringModels[i];
279
291
  debug(`Discovering: ${modelInfo.name}...`);
280
- this.artifactInfo.modelDefinitions.push(
281
- await modelMaker.discoverSingleModel(
282
- this.artifactInfo.dataSource,
283
- modelInfo.name,
284
- {
285
- schema: modelInfo.owner,
286
- disableCamelCase: this.artifactInfo.disableCamelCase,
287
- },
288
- ),
292
+ const modelDefinition = await modelMaker.discoverSingleModel(
293
+ this.artifactInfo.dataSource,
294
+ modelInfo.name,
295
+ {
296
+ schema: modelInfo.owner,
297
+ disableCamelCase: this.artifactInfo.disableCamelCase,
298
+ associations: this.options.relations,
299
+ },
289
300
  );
301
+ if (this.options.optionalId) {
302
+ // Find id properties (can be multiple ids if using composite key)
303
+ const idProperties = Object.values(modelDefinition.properties).filter(
304
+ property => property.id,
305
+ );
306
+ // Mark as not required
307
+ idProperties.forEach(property => {
308
+ property.required = false;
309
+ });
310
+ }
311
+ this.artifactInfo.modelDefinitions.push(modelDefinition);
290
312
  debug(`Discovered: ${modelInfo.name}`);
291
313
  }
292
314
  }
@@ -321,6 +343,46 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
321
343
  );
322
344
  debug(`Writing: ${fullPath}`);
323
345
 
346
+ if (this.options.relations) {
347
+ const relationImports = [];
348
+ const relationDestinationImports = [];
349
+ const foreignKeys = {};
350
+ for (const relationName in templateData.settings.relations) {
351
+ const relation = templateData.settings.relations[relationName];
352
+ const targetModel = this.artifactInfo.modelDefinitions.find(
353
+ model => model.name === relation.model,
354
+ );
355
+ // If targetModel is not in discovered models, skip creating relation
356
+ if (targetModel) {
357
+ Object.assign(templateData.properties[relation.foreignKey], {
358
+ relation,
359
+ });
360
+ relationImports.push(relation.type);
361
+ relationDestinationImports.push(relation.model);
362
+
363
+ foreignKeys[relationName] = {};
364
+ Object.assign(foreignKeys[relationName], {
365
+ name: relationName,
366
+ entity: relation.model,
367
+ entityKey: Object.entries(targetModel.properties).find(
368
+ x => x?.[1].id === 1,
369
+ )?.[0],
370
+ foreignKey: relation.foreignKey,
371
+ });
372
+ }
373
+ }
374
+ templateData.relationImports = relationImports;
375
+ templateData.relationDestinationImports = relationDestinationImports;
376
+ // Delete relation from modelSettings
377
+ delete templateData.settings.relations;
378
+ if (Object.keys(foreignKeys)?.length > 0) {
379
+ Object.assign(templateData.settings, {foreignKeys});
380
+ }
381
+ templateData.modelSettings = utils.stringifyModelSettings(
382
+ templateData.settings,
383
+ );
384
+ }
385
+
324
386
  this.copyTemplatedFiles(
325
387
  modelDiscoverer.MODEL_TEMPLATE_PATH,
326
388
  fullPath,
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2017,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,9 +1,12 @@
1
1
  <% if (isModelBaseBuiltin) { -%>
2
- import {<%= modelBaseClass %>, model, property} from '@loopback/repository';
2
+ import {<%= modelBaseClass %>, model, property<%if (locals.relationImports) {%><% relationImports.forEach((relation) => {-%>, <%= relation %> <%_})-%><%}%>} from '@loopback/repository';
3
3
  <% } else { -%>
4
- import {model, property} from '@loopback/repository';
4
+ import {model, property<%if (locals.relationImports) {%><% relationImports.forEach((relation) => {-%> , <%= relation %> <%_})-%><%}%>} from '@loopback/repository';
5
5
  import {<%= modelBaseClass %>} from '.';
6
6
  <% } -%>
7
+ <%_ if (locals.relationDestinationImports && locals.relationDestinationImports.length > 0) { -%>
8
+ import {<% relationDestinationImports.forEach((model, index) => {-%><%= model %><%if (index!==relationDestinationImports.length-1) {%>,<% } %> <%_}) -%>} from '.';
9
+ <%_ } -%>
7
10
 
8
11
  <% if (modelSettings) { -%>
9
12
  @model(<%- modelSettings %>)
@@ -12,13 +15,17 @@ import {<%= modelBaseClass %>} from '.';
12
15
  <% } -%>
13
16
  export class <%= className %> extends <%= modelBaseClass %> {
14
17
  <% Object.entries(properties).forEach(([key, val]) => { -%>
18
+ <% if (val.relation) { -%>
19
+ @<%= val.relation.type %>(() => <%= val.relation.model %>)
20
+ <% } else { -%>
15
21
  @property({
16
22
  <%_ Object.entries(val).forEach(([propKey, propVal]) => { -%>
17
- <%_ if (!['tsType'].includes(propKey)) { -%>
23
+ <%_ if (!['tsType', 'relation'].includes(propKey)) { -%>
18
24
  <%= propKey %>: <%- propVal %>,
19
- <%_ } -%>
25
+ <%_ } -%>
20
26
  <%_ }) -%>
21
27
  })
28
+ <% } -%>
22
29
  <%= key %><%if (!val.required) {%>?<% } %>: <%= val.tsType %>;
23
30
 
24
31
  <% }) -%>
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -26,6 +26,7 @@ const PROMPT_MESSAGE_MODEL = g.f(
26
26
  );
27
27
  const PROMPT_MESSAGE_DATA_SOURCE = g.f('Please select the datasource');
28
28
  const PROMPT_MESSAGE_BASE_PATH = g.f('Please specify the base path');
29
+ const PROMPT_MESSAGE_READONLY = g.f('Do you want to create readonly APIs?');
29
30
 
30
31
  const ERROR_NO_DATA_SOURCES_FOUND = g.f('No datasources found at');
31
32
  const ERROR_NO_MODELS_FOUND = g.f('No models found at');
@@ -93,6 +94,13 @@ module.exports = class RestCrudGenerator extends ArtifactGenerator {
93
94
  description: g.f('A valid base path'),
94
95
  });
95
96
 
97
+ this.option('readonly', {
98
+ type: Boolean,
99
+ required: false,
100
+ description: g.f('Create readonly APIs'),
101
+ default: false,
102
+ });
103
+
96
104
  return super._setupGenerator();
97
105
  }
98
106
 
@@ -308,6 +316,20 @@ module.exports = class RestCrudGenerator extends ArtifactGenerator {
308
316
  }
309
317
  }
310
318
 
319
+ async promptReadonly() {
320
+ const props = await this.prompt([
321
+ {
322
+ type: 'confirm',
323
+ name: 'readonly',
324
+ message: PROMPT_MESSAGE_READONLY,
325
+ default: false,
326
+ },
327
+ ]);
328
+ if (props) {
329
+ this.artifactInfo.readonly = props.readonly;
330
+ }
331
+ }
332
+
311
333
  async scaffold() {
312
334
  if (this.shouldExit()) return false;
313
335
 
@@ -6,5 +6,6 @@ const config: ModelCrudRestApiConfig = {
6
6
  pattern: 'CrudRest',
7
7
  dataSource: '<%= dataSourceName %>',
8
8
  basePath: '<%= basePath %>',
9
+ readonly: <%= readonly %>,
9
10
  };
10
11
  module.exports = config;
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2017,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
package/lib/ast-helper.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2017,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
package/lib/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
package/lib/debug.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
package/lib/globalize.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2017,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2018,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
package/lib/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2017,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- // Copyright IBM Corp. 2019,2020. All Rights Reserved.
1
+ // Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
2
2
  // Node module: @loopback/cli
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loopback/cli",
3
3
  "description": "Yeoman generator for LoopBack 4",
4
- "version": "4.0.0",
4
+ "version": "4.1.0",
5
5
  "keywords": [
6
6
  "LoopBack",
7
7
  "CLI",
@@ -12,8 +12,8 @@
12
12
  "lb4": "bin/cli-main.js"
13
13
  },
14
14
  "main": "generators/app/index.js",
15
- "author": "IBM Corp.",
16
- "copyright.owner": "IBM Corp.",
15
+ "author": "IBM Corp. and LoopBack contributors",
16
+ "copyright.owner": "IBM Corp. and LoopBack contributors",
17
17
  "homepage": "https://github.com/loopbackio/loopback-next/tree/master/packages/cli",
18
18
  "repository": {
19
19
  "type": "git",
@@ -39,7 +39,7 @@
39
39
  ".yo-rc.json"
40
40
  ],
41
41
  "dependencies": {
42
- "@lerna/project": "^4.0.0",
42
+ "@lerna/project": "^5.1.1",
43
43
  "@openapi-contrib/openapi-schema-to-json-schema": "^3.1.2",
44
44
  "@phenomnomnominal/tsquery": "^4.2.0",
45
45
  "camelcase-keys": "^7.0.2",
@@ -47,16 +47,16 @@
47
47
  "change-case": "^4.1.2",
48
48
  "debug": "^4.3.4",
49
49
  "fs-extra": "^10.1.0",
50
- "glob": "^8.0.1",
50
+ "glob": "^8.0.3",
51
51
  "inquirer-autocomplete-prompt": "^2.0.0",
52
52
  "json5": "^2.2.1",
53
53
  "latest-version": "^5.1.0",
54
54
  "lodash": "^4.17.21",
55
- "minimatch": "^5.0.1",
55
+ "minimatch": "^5.1.0",
56
56
  "minimist": "^1.2.6",
57
57
  "mkdirp": "^1.0.4",
58
58
  "natural-compare": "^1.4.0",
59
- "pacote": "^13.3.0",
59
+ "pacote": "^13.6.0",
60
60
  "pluralize": "^8.0.0",
61
61
  "regenerate": "^1.4.2",
62
62
  "semver": "^7.3.7",
@@ -70,24 +70,24 @@
70
70
  "terminal-link": "^2.1.1",
71
71
  "tildify": "^2.0.0",
72
72
  "ts-morph": "^12.2.0",
73
- "typescript": "~4.6.4",
73
+ "typescript": "~4.7.3",
74
74
  "unicode-10.0.0": "^0.7.5",
75
75
  "untildify": "^4.0.0",
76
76
  "update-notifier": "^5.1.0",
77
- "url-slug": "^3.0.3",
77
+ "url-slug": "^3.0.4",
78
78
  "validate-npm-package-name": "^4.0.0",
79
79
  "write-file-atomic": "^4.0.1",
80
80
  "yeoman-environment": "^2.10.3",
81
81
  "yeoman-generator": "^4.13.0"
82
82
  },
83
83
  "devDependencies": {
84
- "@loopback/build": "^9.0.0",
85
- "@loopback/eslint-config": "^13.0.0",
86
- "@loopback/testlab": "^5.0.0",
87
- "@types/ejs": "^3.1.0",
84
+ "@loopback/build": "^9.0.1",
85
+ "@loopback/eslint-config": "^13.0.1",
86
+ "@loopback/testlab": "^5.0.1",
87
+ "@types/ejs": "^3.1.1",
88
88
  "@types/fs-extra": "^9.0.13",
89
89
  "@types/minimatch": "^3.0.5",
90
- "@types/node": "^12.20.50",
90
+ "@types/node": "^14.18.21",
91
91
  "loopback": "^3.28.0",
92
92
  "loopback-datasource-juggler": "^4.27.1",
93
93
  "mem-fs": "^2.2.1",
@@ -103,7 +103,7 @@
103
103
  "templateDependencies": {
104
104
  "tslib": "^2.0.0",
105
105
  "@types/mocha": "^9.1.1",
106
- "@types/node": "^12.20.50",
106
+ "@types/node": "^14.18.21",
107
107
  "cross-spawn": "^7.0.3",
108
108
  "debug": "^4.3.4",
109
109
  "fs-extra": "^10.1.0",
@@ -112,87 +112,87 @@
112
112
  "prettier": "^2.6.2",
113
113
  "rimraf": "^3.0.2",
114
114
  "source-map-support": "^0.5.21",
115
- "typescript": "~4.6.4",
116
- "@loopback/authentication": "^9.0.0",
117
- "@loopback/boot": "^5.0.0",
118
- "@loopback/build": "^9.0.0",
119
- "@loopback/cli": "^4.0.0",
120
- "@loopback/context": "^5.0.0",
121
- "@loopback/core": "^4.0.0",
122
- "@loopback/metadata": "^5.0.0",
123
- "@loopback/openapi-spec-builder": "^5.0.0",
124
- "@loopback/openapi-v3": "^8.0.0",
125
- "@loopback/repository-json-schema": "^6.0.0",
126
- "@loopback/repository": "^5.0.0",
127
- "@loopback/rest": "^12.0.0",
128
- "@loopback/testlab": "^5.0.0",
129
- "@loopback/docs": "^5.0.0",
130
- "glob": "^8.0.1",
131
- "@loopback/example-hello-world": "^5.0.0",
132
- "@loopback/example-log-extension": "^5.0.0",
133
- "@loopback/example-rpc-server": "^5.0.0",
134
- "@loopback/example-todo": "^6.0.0",
135
- "@loopback/example-soap-calculator": "^5.0.0",
136
- "@loopback/service-proxy": "^5.0.0",
137
- "@loopback/http-caching-proxy": "^4.0.0",
138
- "@loopback/http-server": "^4.0.0",
139
- "@loopback/example-todo-list": "^6.0.0",
115
+ "typescript": "~4.7.3",
116
+ "@loopback/authentication": "^9.0.1",
117
+ "@loopback/boot": "^5.0.1",
118
+ "@loopback/build": "^9.0.1",
119
+ "@loopback/cli": "^4.1.0",
120
+ "@loopback/context": "^5.0.1",
121
+ "@loopback/core": "^4.0.1",
122
+ "@loopback/metadata": "^5.0.1",
123
+ "@loopback/openapi-spec-builder": "^5.0.1",
124
+ "@loopback/openapi-v3": "^8.0.1",
125
+ "@loopback/repository-json-schema": "^6.0.1",
126
+ "@loopback/repository": "^5.0.1",
127
+ "@loopback/rest": "^12.0.1",
128
+ "@loopback/testlab": "^5.0.1",
129
+ "@loopback/docs": "^5.1.0",
130
+ "glob": "^8.0.3",
131
+ "@loopback/example-hello-world": "^5.0.1",
132
+ "@loopback/example-log-extension": "^5.0.1",
133
+ "@loopback/example-rpc-server": "^5.0.1",
134
+ "@loopback/example-todo": "^6.0.1",
135
+ "@loopback/example-soap-calculator": "^5.0.1",
136
+ "@loopback/service-proxy": "^5.0.1",
137
+ "@loopback/http-caching-proxy": "^4.0.1",
138
+ "@loopback/http-server": "^4.0.1",
139
+ "@loopback/example-todo-list": "^6.0.1",
140
140
  "@loopback/dist-util": "^0.4.0",
141
- "@loopback/rest-explorer": "^5.0.0",
142
- "@loopback/eslint-config": "^13.0.0",
141
+ "@loopback/rest-explorer": "^5.0.1",
142
+ "@loopback/eslint-config": "^13.0.1",
143
143
  "express-composition": "^1.1.0",
144
- "@loopback/example-express-composition": "^5.0.0",
145
- "@loopback/example-greeter-extension": "^5.0.0",
146
- "@loopback/booter-lb3app": "^4.0.0",
147
- "@loopback/example-lb3-application": "^5.0.0",
148
- "eslint": "^8.14.0",
149
- "eslint-plugin-mocha": "10.0.3",
150
- "@loopback/example-greeting-app": "^5.0.0",
151
- "@loopback/example-context": "^5.0.0",
152
- "@typescript-eslint/eslint-plugin": "^5.22.0",
153
- "@typescript-eslint/parser": "^5.22.0",
154
- "eslint-plugin-eslint-plugin": "^4.1.0",
144
+ "@loopback/example-express-composition": "^5.0.1",
145
+ "@loopback/example-greeter-extension": "^5.0.1",
146
+ "@loopback/booter-lb3app": "^4.0.1",
147
+ "@loopback/example-lb3-application": "^5.0.1",
148
+ "eslint": "^8.17.0",
149
+ "eslint-plugin-mocha": "^10.0.5",
150
+ "@loopback/example-greeting-app": "^5.0.1",
151
+ "@loopback/example-context": "^5.0.1",
152
+ "@typescript-eslint/eslint-plugin": "^5.27.1",
153
+ "@typescript-eslint/parser": "^5.27.1",
154
+ "eslint-plugin-eslint-plugin": "^4.2.0",
155
155
  "eslint-config-prettier": "^8.5.0",
156
- "@loopback/repository-tests": "^0.21.0",
157
- "@loopback/health": "^0.11.0",
158
- "@loopback/authorization": "^0.12.0",
159
- "@loopback/rest-crud": "^0.14.0",
160
- "@loopback/security": "^0.8.0",
161
- "@loopback/authentication-passport": "^5.0.0",
162
- "@loopback/example-metrics-prometheus": "^0.10.0",
163
- "@loopback/metrics": "^0.11.0",
164
- "@loopback/model-api-builder": "^4.0.0",
165
- "@loopback/logging": "^0.9.0",
166
- "@loopback/example-access-control-migration": "^5.0.0",
167
- "@loopback/example-file-transfer": "^4.0.0",
168
- "@loopback/example-rest-crud": "^4.0.0",
169
- "@loopback/apiconnect": "^0.10.0",
170
- "@loopback/example-validation-app": "^4.0.0",
171
- "@loopback/cron": "^0.9.0",
172
- "@loopback/example-multi-tenancy": "^0.13.0",
173
- "@loopback/example-passport-login": "^4.0.0",
174
- "@loopback/authentication-jwt": "^0.12.0",
175
- "@loopback/context-explorer": "^0.8.0",
176
- "@loopback/express": "^5.0.0",
156
+ "@loopback/repository-tests": "^0.21.1",
157
+ "@loopback/health": "^0.11.1",
158
+ "@loopback/authorization": "^0.12.1",
159
+ "@loopback/rest-crud": "^0.15.0",
160
+ "@loopback/security": "^0.8.1",
161
+ "@loopback/authentication-passport": "^5.0.1",
162
+ "@loopback/example-metrics-prometheus": "^0.10.1",
163
+ "@loopback/metrics": "^0.11.1",
164
+ "@loopback/model-api-builder": "^4.0.1",
165
+ "@loopback/logging": "^0.9.1",
166
+ "@loopback/example-access-control-migration": "^5.0.1",
167
+ "@loopback/example-file-transfer": "^4.0.1",
168
+ "@loopback/example-rest-crud": "^4.0.1",
169
+ "@loopback/apiconnect": "^0.10.1",
170
+ "@loopback/example-validation-app": "^4.0.1",
171
+ "@loopback/cron": "^0.9.1",
172
+ "@loopback/example-multi-tenancy": "^0.13.1",
173
+ "@loopback/example-passport-login": "^4.0.1",
174
+ "@loopback/authentication-jwt": "^0.12.1",
175
+ "@loopback/context-explorer": "^0.8.1",
176
+ "@loopback/express": "^5.0.1",
177
177
  "@types/js-yaml": "^3.12.4",
178
178
  "js-yaml": "^3.13.1",
179
- "@loopback/example-todo-jwt": "^4.0.0",
180
- "@loopback/mock-oauth2-provider": "^0.6.0",
179
+ "@loopback/example-todo-jwt": "^4.0.1",
180
+ "@loopback/mock-oauth2-provider": "^0.6.1",
181
181
  "lodash": "^4.17.21",
182
- "@loopback/pooling": "^0.8.0",
183
- "@loopback/typeorm": "^0.7.0",
184
- "@loopback/example-graphql": "^0.7.0",
185
- "@loopback/graphql": "^0.8.0",
186
- "@loopback/filter": "^3.0.0",
187
- "@loopback/rest-msgpack": "^0.8.0",
188
- "@loopback/example-binding-resolution": "^0.7.0",
189
- "@loopback/example-webpack": "^0.8.0",
190
- "@loopback/example-socketio": "^0.6.0",
191
- "@loopback/socketio": "^0.6.0",
192
- "@loopback/monorepo": "^0.5.0",
193
- "@loopback/tsdocs": "^4.0.0",
194
- "@loopback/example-references-many": "^6.0.0"
182
+ "@loopback/pooling": "^0.8.1",
183
+ "@loopback/typeorm": "^0.7.1",
184
+ "@loopback/example-graphql": "^0.7.1",
185
+ "@loopback/graphql": "^0.8.1",
186
+ "@loopback/filter": "^3.0.1",
187
+ "@loopback/rest-msgpack": "^0.8.1",
188
+ "@loopback/example-binding-resolution": "^0.7.1",
189
+ "@loopback/example-webpack": "^0.8.1",
190
+ "@loopback/example-socketio": "^0.6.1",
191
+ "@loopback/socketio": "^0.6.1",
192
+ "@loopback/monorepo": "^0.5.1",
193
+ "@loopback/tsdocs": "^4.0.1",
194
+ "@loopback/example-references-many": "^6.0.1"
195
195
  }
196
196
  },
197
- "gitHead": "61453a3d7a16f9f37875a3f2c2a071568eb3e3af"
197
+ "gitHead": "ccf7863d0639de966d6c6129b4aa94ba1dce2c33"
198
198
  }