Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

change dataSource to datasource #10438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/site/Discovering-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Models can be discovered from a supported datasource by running the

### Options

`--dataSource`: Put a valid datasource name here to skip the datasource prompt
`--datasource`: Put a valid datasource name here to skip the datasource prompt

`--views`: Choose whether to discover views. Default is true

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/.yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1236,11 +1236,11 @@
"name": "packageManager",
"hide": false
},
"dataSource": {
"datasource": {
"type": "String",
"alias": "ds",
"description": "The name of the datasource to discover",
"name": "dataSource",
"name": "datasource",
"hide": false
},
"views": {
Expand Down
50 changes: 25 additions & 25 deletions packages/cli/generators/discover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
constructor(args, opts) {
super(args, opts);

this.option('dataSource', {
this.option('datasource', {
type: String,
alias: 'ds',
description: g.f('The name of the datasource to discover'),
Expand Down Expand Up @@ -83,15 +83,15 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
}

/**
* If we have a dataSource, attempt to load it
* If we have a datasource, attempt to load it
* @returns {*}
*/
setOptions() {
/* istanbul ignore next */
if (this.options.dataSource) {
debug(`Data source specified: ${this.options.dataSource}`);
this.artifactInfo.dataSource = modelMaker.loadDataSourceByName(
this.options.dataSource,
if (this.options.datasource) {
debug(`Data source specified: ${this.options.datasource}`);
this.artifactInfo.datasource = modelMaker.loadDataSourceByName(
this.options.datasource,
);
}
// remove not needed .env property
Expand All @@ -111,12 +111,12 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
}

/**
* Loads all datasources to choose if the dataSource option isn't set
* Loads all datasources to choose if the datasource option isn't set
*/
async loadAllDatasources() {
// If we have a dataSourcePath then it is already loaded for us, we don't need load any
/* istanbul ignore next */
if (this.artifactInfo.dataSource) {
if (this.artifactInfo.datasource) {
return;
}
const dsDir = modelMaker.DEFAULT_DATASOURCE_DIRECTORY;
Expand All @@ -132,15 +132,15 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
path.resolve(dsDir, `${utils.toFileName(s)}.datasource.js`),
),
);
if (this.options.dataSource) {
if (this.options.datasource) {
if (
this.dataSourceChoices
.map(d => d.name)
.includes(this.options.dataSource)
.includes(this.options.datasource)
) {
Object.assign(this.artifactInfo, {
dataSource: this.dataSourceChoices.find(
d => d.name === this.options.dataSource,
datasource: this.dataSourceChoices.find(
d => d.name === this.options.datasource,
),
});
}
Expand All @@ -156,23 +156,23 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
if (this.shouldExit()) return;
const prompts = [
{
name: 'dataSource',
name: 'datasource',
message: g.f('Select the connector to discover'),
type: 'list',
choices: this.dataSourceChoices,
when:
this.artifactInfo.dataSource === undefined &&
this.artifactInfo.datasource === undefined &&
!this.artifactInfo.modelDefinitions,
},
];

return this.prompt(prompts).then(answer => {
/* istanbul ignore next */
if (!answer.dataSource) return;
if (!answer.datasource) return;
debug(`Datasource answer: ${JSON.stringify(answer)}`);

this.artifactInfo.dataSource = this.dataSourceChoices.find(
d => d.name === answer.dataSource,
this.artifactInfo.datasource = this.dataSourceChoices.find(
d => d.name === answer.datasource,
);
});
}
Expand All @@ -183,10 +183,10 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
async discoverModelInfos() {
/* istanbul ignore if */
if (this.artifactInfo.modelDefinitions) return;
debug(`Getting all models from ${this.artifactInfo.dataSource.name}`);
debug(`Getting all models from ${this.artifactInfo.datasource.name}`);

this.modelChoices = await modelMaker.discoverModelNames(
this.artifactInfo.dataSource,
this.artifactInfo.datasource,
{
views: this.options.views,
schema: this.options.schema,
Expand All @@ -197,7 +197,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
this.modelChoices.sort((a, b) => a.name.localeCompare(b.name));

debug(
`Got ${this.modelChoices.length} models from ${this.artifactInfo.dataSource.name}`,
`Got ${this.modelChoices.length} models from ${this.artifactInfo.datasource.name}`,
);
}

Expand Down Expand Up @@ -295,7 +295,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
}

/**
* Using artifactInfo.dataSource,
* Using artifactInfo.datasource,
* artifactInfo.modelNameOptions
*
* this will discover every model
Expand All @@ -305,7 +305,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
async getAllModelDefs() {
/* istanbul ignore next */
if (this.shouldExit()) {
await this.artifactInfo.dataSource.disconnect();
await this.artifactInfo.datasource.disconnect();
return false;
}
this.artifactInfo.modelDefinitions = [];
Expand All @@ -319,7 +319,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
}
debug(`Discovering: ${modelInfo.name}...`);
const modelDefinition = await modelMaker.discoverSingleModel(
this.artifactInfo.dataSource,
this.artifactInfo.datasource,
modelInfo.name,
{
schema: modelInfo.owner,
Expand Down Expand Up @@ -350,7 +350,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
// Exit if needed
/* istanbul ignore next */
if (this.shouldExit()) {
await this.artifactInfo.dataSource.disconnect();
await this.artifactInfo.datasource.disconnect();
return;
}
this.artifactInfo.indexesToBeUpdated =
Expand Down Expand Up @@ -443,7 +443,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
file: utils.getModelFileName(modelDefinition.name),
});

await this.artifactInfo.dataSource.disconnect();
await this.artifactInfo.datasource.disconnect();
}

// This part at the end is just for the ArtifactGenerator
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"node": "18 || 20"
},
"scripts": {
"test": "lb-mocha --lang en_US.UTF-8 \"test/**/*.js\"",
"test": "lb-mocha --lang en_US.UTF-8 \"test/**/discover.integration.js\"",
"smoke-test": "lb-mocha --allow-console-logs \"smoke-test/**/*.smoke.js\"",
"build:globalize": "slt-globalize -e && git add \"intl/en/messages.json\""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export type AppointmentWithRelations = Appointment & AppointmentRelations;
`;


exports[`lb4 discover integration model discovery generates all models without prompts using --all --dataSource 1`] = `
exports[`lb4 discover integration model discovery generates all models without prompts using --all --datasource 1`] = `
import {Entity, model, property} from '@loopback/repository';

@model()
Expand All @@ -143,7 +143,7 @@ export type SchemaWithRelations = Schema & SchemaRelations;
`;


exports[`lb4 discover integration model discovery generates all models without prompts using --all --dataSource 2`] = `
exports[`lb4 discover integration model discovery generates all models without prompts using --all --datasource 2`] = `
import {Entity, model, property} from '@loopback/repository';

@model()
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/test/integration/generators/discover.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const sandbox = new TestSandbox(path.resolve(__dirname, '../.sandbox'));
// CLI Inputs
const baseOptions = {
all: true,
dataSource: 'mem',
datasource: 'mem',
};
const outDirOptions = {
...baseOptions,
Expand All @@ -48,11 +48,11 @@ const disableCamelCaseOptions = {
disableCamelCase: true,
};
const missingDataSourceOptions = {
dataSource: 'foo',
datasource: 'foo',
};
const specificmodelsOptions = {
models: 'Test',
dataSource: 'mem',
datasource: 'mem',
views: false,
disableCamelCase: true,
};
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('lb4 discover integration', () => {
await sandbox.mkdir('dist/datasources');
});

it('generates all models without prompts using --all --dataSource', /** @this {Mocha.Context} */ async function () {
it('generates all models without prompts using --all --datasource', /** @this {Mocha.Context} */ async function () {
this.timeout(10000);
await testUtils
.executeGenerator(generator)
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('lb4 discover integration', () => {
expectFileToMatchSnapshot(defaultExpectedNamingModel);
});

it('will fail gracefully if you specify a --dataSource which does not exist', async () => {
it('will fail gracefully if you specify a --datasource which does not exist', async () => {
return expect(
testUtils
.executeGenerator(generator)
Expand Down