@loopback/cli 4.0.0-alpha.7 → 4.0.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/.yo-rc.json +1697 -0
- package/{generators/project/templates/LICENSE → LICENSE} +2 -1
- package/README.md +44 -43
- package/bin/cli-main.js +61 -0
- package/generators/app/index.js +109 -15
- package/generators/app/templates/.dockerignore +5 -0
- package/generators/app/templates/Dockerfile +28 -0
- package/generators/app/templates/README.md.ejs +130 -0
- package/generators/app/templates/public/index.html.ejs +88 -0
- package/generators/app/templates/{test → src/__tests__}/README.md +0 -1
- package/generators/app/templates/src/__tests__/acceptance/home-page.acceptance.ts.ejs +31 -0
- package/generators/app/templates/src/__tests__/acceptance/ping.controller.acceptance.ts.ejs +21 -0
- package/generators/app/templates/src/__tests__/acceptance/test-helper.ts.ejs +32 -0
- package/generators/app/templates/src/application.ts.ejs +70 -0
- package/generators/app/templates/src/controllers/README.md +6 -0
- package/generators/app/templates/src/controllers/index.ts.ejs +1 -0
- package/generators/app/templates/src/controllers/ping.controller.ts.ejs +55 -0
- package/generators/app/templates/src/datasources/README.md +3 -0
- package/generators/app/templates/src/index.ts.ejs +39 -0
- package/generators/app/templates/src/migrate.ts.ejs +20 -0
- package/generators/app/templates/src/models/README.md +3 -0
- package/generators/app/templates/src/openapi-spec.ts.ejs +23 -0
- package/generators/app/templates/src/sequence.ts.ejs +3 -0
- package/generators/controller/index.js +279 -0
- package/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs +150 -0
- package/generators/controller/templates/src/controllers/controller-template.ts.ejs +8 -0
- package/generators/copyright/fs.js +46 -0
- package/generators/copyright/git.js +78 -0
- package/generators/copyright/header.js +306 -0
- package/generators/copyright/index.js +230 -0
- package/generators/copyright/license.js +105 -0
- package/generators/datasource/index.js +341 -0
- package/generators/datasource/templates/datasource.ts.ejs +22 -0
- package/generators/discover/import-discovered-model.js +70 -0
- package/generators/discover/index.js +349 -0
- package/generators/example/downloader.js +16 -0
- package/generators/example/index.js +176 -0
- package/generators/extension/index.js +34 -5
- package/generators/extension/templates/README.md.ejs +32 -0
- package/generators/extension/templates/{test → src/__tests__}/acceptance/README.md +0 -0
- package/generators/extension/templates/{test → src/__tests__}/integration/README.md +0 -0
- package/generators/extension/templates/{test → src/__tests__}/unit/README.md +0 -0
- package/generators/extension/templates/src/component.ts.ejs +22 -0
- package/generators/extension/templates/src/controllers/README.md +3 -2
- package/generators/extension/templates/src/decorators/README.md +10 -4
- package/generators/extension/templates/src/index.ts.ejs +3 -0
- package/generators/extension/templates/src/keys.ts.ejs +11 -0
- package/generators/extension/templates/src/mixins/README.md +77 -21
- package/generators/extension/templates/src/providers/README.md +51 -25
- package/generators/extension/templates/src/repositories/README.md +1 -1
- package/generators/extension/templates/src/types.ts.ejs +15 -0
- package/generators/import-lb3-models/index.js +197 -0
- package/generators/import-lb3-models/lb3app-loader.js +31 -0
- package/generators/import-lb3-models/migrate-model.js +249 -0
- package/generators/import-lb3-models/model-names.js +32 -0
- package/generators/interceptor/index.js +178 -0
- package/generators/interceptor/templates/interceptor-template.ts.ejs +62 -0
- package/generators/model/index.js +536 -0
- package/generators/model/property-definition.js +85 -0
- package/generators/model/templates/model.ts.ejs +42 -0
- package/generators/observer/index.js +132 -0
- package/generators/observer/templates/observer-template.ts.ejs +40 -0
- package/generators/openapi/README.md +211 -0
- package/generators/openapi/index.js +535 -0
- package/generators/openapi/schema-helper.js +447 -0
- package/generators/openapi/spec-helper.js +484 -0
- package/generators/openapi/spec-loader.js +75 -0
- package/generators/openapi/templates/src/controllers/controller-template.ts.ejs +43 -0
- package/generators/openapi/templates/src/datasources/datasource.ts.ejs +42 -0
- package/generators/openapi/templates/src/models/model-template.ts.ejs +71 -0
- package/generators/openapi/templates/src/models/type-template.ts.ejs +13 -0
- package/generators/openapi/templates/src/services/service-proxy-template.ts.ejs +55 -0
- package/generators/openapi/utils.js +322 -0
- package/generators/project/templates/.eslintignore +4 -0
- package/generators/project/templates/.eslintrc.js.ejs +3 -0
- package/generators/project/templates/.mocharc.json +5 -0
- package/generators/project/templates/.prettierignore +0 -2
- package/generators/project/templates/.prettierrc +2 -1
- package/generators/project/templates/.vscode/launch.json +38 -0
- package/generators/project/templates/.vscode/settings.json +32 -0
- package/generators/project/templates/.vscode/tasks.json +29 -0
- package/generators/project/templates/DEVELOPING.md +36 -0
- package/generators/project/templates/_.gitignore +3 -5
- package/generators/project/templates/package.json.ejs +175 -0
- package/generators/project/templates/package.plain.json.ejs +176 -0
- package/generators/project/templates/tsconfig.json.ejs +39 -0
- package/generators/relation/base-relation.generator.js +220 -0
- package/generators/relation/belongs-to-relation.generator.js +196 -0
- package/generators/relation/has-many-relation.generator.js +200 -0
- package/generators/relation/has-many-through-relation.generator.js +331 -0
- package/generators/relation/has-one-relation.generator.js +200 -0
- package/generators/relation/index.js +795 -0
- package/generators/relation/references-many-relation.generator.js +142 -0
- package/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs +38 -0
- package/generators/relation/templates/controller-relation-template-has-many-through.ts.ejs +110 -0
- package/generators/relation/templates/controller-relation-template-has-many.ts.ejs +110 -0
- package/generators/relation/templates/controller-relation-template-has-one.ts.ejs +110 -0
- package/generators/relation/utils.generator.js +260 -0
- package/generators/repository/index.js +576 -0
- package/generators/repository/templates/src/repositories/repository-crud-default-template.ts.ejs +21 -0
- package/generators/repository/templates/src/repositories/repository-kv-template.ts.ejs +19 -0
- package/generators/rest-crud/crud-rest-component.js +63 -0
- package/generators/rest-crud/index.js +401 -0
- package/generators/rest-crud/templates/src/model-endpoints/model.rest-config-template.ts.ejs +10 -0
- package/generators/service/index.js +351 -0
- package/generators/service/templates/local-service-class-template.ts.ejs +10 -0
- package/generators/service/templates/local-service-provider-template.ts.ejs +19 -0
- package/generators/service/templates/remote-service-proxy-template.ts.ejs +21 -0
- package/generators/update/index.js +55 -0
- package/intl/cs/messages.json +204 -0
- package/intl/de/messages.json +204 -0
- package/intl/en/messages.json +204 -0
- package/intl/es/messages.json +204 -0
- package/intl/fr/messages.json +204 -0
- package/intl/it/messages.json +204 -0
- package/intl/ja/messages.json +204 -0
- package/intl/ko/messages.json +204 -0
- package/intl/nl/messages.json +204 -0
- package/intl/pl/messages.json +204 -0
- package/intl/pt/messages.json +204 -0
- package/intl/ru/messages.json +204 -0
- package/intl/tr/messages.json +204 -0
- package/intl/zh-Hans/messages.json +204 -0
- package/intl/zh-Hant/messages.json +204 -0
- package/lib/artifact-generator.js +189 -0
- package/lib/ast-helper.js +214 -0
- package/lib/base-generator.js +509 -0
- package/lib/cli.js +233 -0
- package/lib/connectors.json +894 -0
- package/lib/debug.js +16 -0
- package/lib/globalize.js +12 -0
- package/lib/model-discoverer.js +118 -0
- package/lib/project-generator.js +154 -57
- package/lib/tab-completion.js +127 -0
- package/lib/update-index.js +44 -0
- package/lib/utils.js +746 -22
- package/lib/version-helper.js +299 -0
- package/package.json +183 -32
- package/CHANGELOG.md +0 -64
- package/bin/cli.js +0 -65
- package/generators/app/templates/index.js +0 -14
- package/generators/app/templates/src/application.ts +0 -27
- package/generators/app/templates/src/controllers/ping-controller.ts +0 -25
- package/generators/app/templates/src/index.ts +0 -25
- package/generators/app/templates/test/ping-controller.test.ts +0 -46
- package/generators/extension/templates/index.js +0 -8
- package/generators/extension/templates/src/component.ts +0 -14
- package/generators/extension/templates/src/index.ts +0 -6
- package/generators/project/templates/.npmrc +0 -1
- package/generators/project/templates/.yo-rc.json +0 -1
- package/generators/project/templates/README.md +0 -4
- package/generators/project/templates/index.d.ts +0 -6
- package/generators/project/templates/index.ts +0 -11
- package/generators/project/templates/package.json +0 -79
- package/generators/project/templates/package.plain.json +0 -82
- package/generators/project/templates/test/mocha.opts +0 -1
- package/generators/project/templates/tsconfig.json +0 -29
- package/generators/project/templates/tslint.build.json +0 -17
- package/generators/project/templates/tslint.json +0 -33
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/cli
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const {tsquery} = require('@phenomnomnominal/tsquery');
|
|
9
|
+
const {syntaxKindName} = tsquery;
|
|
10
|
+
const debug = require('./debug')('ast-query');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parse the file using the possible formats specified in the arrays
|
|
14
|
+
* rootNodesFindID and childNodesFindID
|
|
15
|
+
* @param {string} fileContent with a model.ts class
|
|
16
|
+
*/
|
|
17
|
+
exports.getIdFromModel = function (fileContent) {
|
|
18
|
+
const ast = tsquery.ast(fileContent);
|
|
19
|
+
for (const queryName in MODEL_ID_QUERIES) {
|
|
20
|
+
debug('Trying %s', queryName);
|
|
21
|
+
const {query, getModelPropertyDeclaration} = MODEL_ID_QUERIES[queryName];
|
|
22
|
+
|
|
23
|
+
const idFieldAssignments = tsquery(ast, query);
|
|
24
|
+
|
|
25
|
+
for (const node of idFieldAssignments) {
|
|
26
|
+
const fieldName = node.name.escapedText;
|
|
27
|
+
/* istanbul ignore if */
|
|
28
|
+
if (debug.enabled) {
|
|
29
|
+
debug(
|
|
30
|
+
' trying prop metadata field "%s" with value `%s`',
|
|
31
|
+
fieldName,
|
|
32
|
+
getNodeSource(node),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!isPrimaryKeyFlag(node.initializer)) continue;
|
|
37
|
+
|
|
38
|
+
const propDeclarationNode = getModelPropertyDeclaration(node);
|
|
39
|
+
const modelPropertyName = propDeclarationNode.name.escapedText;
|
|
40
|
+
/* istanbul ignore if */
|
|
41
|
+
if (debug.enabled) {
|
|
42
|
+
debug(
|
|
43
|
+
'Found primary key `%s` with id flag set to `%s`',
|
|
44
|
+
modelPropertyName,
|
|
45
|
+
getNodeSource(node),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return modelPropertyName;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// no primary key was found
|
|
54
|
+
return null;
|
|
55
|
+
|
|
56
|
+
function getNodeSource(node) {
|
|
57
|
+
return fileContent.slice(node.pos, node.end).trim();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const MODEL_ID_QUERIES = {
|
|
62
|
+
'default format generated by lb4 model': {
|
|
63
|
+
// @property({id: true|1})
|
|
64
|
+
// id: number
|
|
65
|
+
query:
|
|
66
|
+
// Find all class properties decorated with `@property()`
|
|
67
|
+
'ClassDeclaration>PropertyDeclaration>Decorator:has([name="id"])>' +
|
|
68
|
+
// Find object-literal argument passed to `@property` decorator
|
|
69
|
+
'CallExpression>ObjectLiteralExpression>' +
|
|
70
|
+
// Find all assignments to `id` property (metadata field)
|
|
71
|
+
'PropertyAssignment:has([name="id"])',
|
|
72
|
+
|
|
73
|
+
getModelPropertyDeclaration(node) {
|
|
74
|
+
return node.parent.parent.parent.parent;
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
'model JSON definition inside the @model decorator': {
|
|
79
|
+
// @model({properties: {id: {type:number, id:true|1}}})
|
|
80
|
+
query:
|
|
81
|
+
// Find all classes decorated with `@model()`
|
|
82
|
+
'ClassDeclaration>Decorator:has([name="model"])>' +
|
|
83
|
+
// Find object-literal argument passed to `@model` decorator
|
|
84
|
+
'CallExpression>ObjectLiteralExpression>' +
|
|
85
|
+
// Find {properties:{...}} initializer
|
|
86
|
+
'PropertyAssignment:has([name="properties"])>ObjectLiteralExpression>' +
|
|
87
|
+
// Find all model properties, e.g. {name: {required: true}}
|
|
88
|
+
'PropertyAssignment>ObjectLiteralExpression>' +
|
|
89
|
+
// Find all assignments to `id` property (metadata field)
|
|
90
|
+
'PropertyAssignment:has([name="id"])',
|
|
91
|
+
getModelPropertyDeclaration(node) {
|
|
92
|
+
return node.parent.parent;
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
'model JSON definition inside a static model property "definition"': {
|
|
97
|
+
// static definition = {properties: {id: {type:number, id:true|1}}}
|
|
98
|
+
query:
|
|
99
|
+
// Find all classes with static property `definition`
|
|
100
|
+
// TODO: check for "static" modifier
|
|
101
|
+
'ClassDeclaration>PropertyDeclaration:has([name="definition"])>' +
|
|
102
|
+
// Find object-literal argument used to initialize `definition`
|
|
103
|
+
'ObjectLiteralExpression>' +
|
|
104
|
+
// Find {properties:{...}} initializer
|
|
105
|
+
'PropertyAssignment:has([name="properties"])>ObjectLiteralExpression>' +
|
|
106
|
+
// Find all model properties, e.g. {name: {required: true}}
|
|
107
|
+
'PropertyAssignment>ObjectLiteralExpression>' +
|
|
108
|
+
// Find all assignments to `id` property (metadata field)
|
|
109
|
+
'PropertyAssignment:has([name="id"])',
|
|
110
|
+
|
|
111
|
+
getModelPropertyDeclaration(node) {
|
|
112
|
+
return node.parent.parent;
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
function isPrimaryKeyFlag(idInitializer) {
|
|
118
|
+
const kindName = syntaxKindName(idInitializer.kind);
|
|
119
|
+
|
|
120
|
+
/* istanbul ignore if */
|
|
121
|
+
if (debug.enabled) {
|
|
122
|
+
debug(
|
|
123
|
+
'Checking primary key flag initializer, kind: %s node:',
|
|
124
|
+
kindName,
|
|
125
|
+
require('util').inspect(
|
|
126
|
+
{...idInitializer, parent: '[removed for brevity]'},
|
|
127
|
+
{depth: null},
|
|
128
|
+
),
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// {id: true}
|
|
133
|
+
if (kindName === 'TrueKeyword') return true;
|
|
134
|
+
|
|
135
|
+
// {id: number}
|
|
136
|
+
if (kindName === 'NumericLiteral') {
|
|
137
|
+
const ix = +idInitializer.text;
|
|
138
|
+
// the value must be a non-zero number, e.g. {id: 1}
|
|
139
|
+
return ix !== 0 && !isNaN(ix);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
exports.getDataSourceConfig = function (fileContent) {
|
|
146
|
+
const ast = tsquery.ast(fileContent);
|
|
147
|
+
// Find a top-level declaration of `config` variable
|
|
148
|
+
const configVarDecl = tsquery(
|
|
149
|
+
ast,
|
|
150
|
+
// It must be a top-level declaration, not inside a function
|
|
151
|
+
'SourceFile>VariableStatement>VariableDeclarationList>' +
|
|
152
|
+
// The declaration should be for a variable called exactly `config`
|
|
153
|
+
'VariableDeclaration:has([name="config"])',
|
|
154
|
+
);
|
|
155
|
+
if (!configVarDecl || configVarDecl.length < 1) {
|
|
156
|
+
debug('No top-level declaration of variable "config" was not found.');
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const initializer = configVarDecl[0].initializer;
|
|
161
|
+
const initializerKindName = syntaxKindName(initializer.kind);
|
|
162
|
+
if (initializerKindName !== 'ObjectLiteralExpression') {
|
|
163
|
+
debug(
|
|
164
|
+
'Variable "config" is declared with an unsupported initializer kind %s.',
|
|
165
|
+
initializerKindName,
|
|
166
|
+
);
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const config = Object.create(null);
|
|
171
|
+
for (const prop of initializer.properties) {
|
|
172
|
+
const propKind = syntaxKindName(prop.kind);
|
|
173
|
+
if (propKind !== 'PropertyAssignment') {
|
|
174
|
+
debug('Skipping unknown property kind %s', propKind);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const propNameKind = syntaxKindName(prop.name.kind);
|
|
179
|
+
if (propNameKind !== 'Identifier') {
|
|
180
|
+
debug('Skipping unknown property name kind %s', propNameKind);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const propName = prop.name.escapedText;
|
|
185
|
+
|
|
186
|
+
const propInitKind = syntaxKindName(prop.initializer.kind);
|
|
187
|
+
let propValue;
|
|
188
|
+
switch (propInitKind) {
|
|
189
|
+
case 'StringLiteral':
|
|
190
|
+
propValue = prop.initializer.text;
|
|
191
|
+
break;
|
|
192
|
+
case 'NumericLiteral':
|
|
193
|
+
propValue = +prop.initializer.text;
|
|
194
|
+
break;
|
|
195
|
+
case 'TrueKeyword':
|
|
196
|
+
propValue = true;
|
|
197
|
+
break;
|
|
198
|
+
case 'FalseKeyword':
|
|
199
|
+
propValue = false;
|
|
200
|
+
break;
|
|
201
|
+
default:
|
|
202
|
+
debug(
|
|
203
|
+
'Skipping unsupported property initializer kind %s',
|
|
204
|
+
propInitKind,
|
|
205
|
+
);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
debug('Adding config entry %s: %j', propName, propValue);
|
|
210
|
+
config[propName] = propValue;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return config;
|
|
214
|
+
};
|