-
Notifications
You must be signed in to change notification settings - Fork 3
feat:cext-4860 added standalone commands #13
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9a329f4
feat:cext-4860 added standalone commands
559dad6
Merge branch 'epic/abdb-implementation' into feat/cext-4860
ecdd1e5
feat:cext-4860 added tests for standalone db commands
78b5299
feat:cext-4860 added tests for standalone db commands
eda0784
feat:cext-4860 updated README
ea1efd5
feat:cext-4860 updated description
08c2ec7
feat:cext-4860 implemented show collections command
ded163f
feat:cext-4860 implemented show collections command
e764f6a
first commit
0d49d6f
feat:cext-4860 added support for --json flag
1d309fb
feat:cext-4860 Removed the conditional logs based on json flag
015d961
feat:cext-4860 Removed the conditional logs based on json flag
1ec05ab
feat:cext-4860 Removed redundant logs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| Copyright 2025 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { DBBaseCommand } from '../../../DBBaseCommand.js' | ||
| import chalk from 'chalk' | ||
|
|
||
| export class GetCollectionInfos extends DBBaseCommand { | ||
| async run () { | ||
| try { | ||
| this.log(chalk.blue('Fetching collection info...')) | ||
|
|
||
| const client = await this.db.connect() | ||
| const collectionInfo = await client.listCollections() | ||
|
|
||
| this.debugLogger?.info?.(`Retrieved ${collectionInfo.length} collections with full details:`, collectionInfo) | ||
|
|
||
| if (this.flags.json) { | ||
| return collectionInfo | ||
| } | ||
|
simrangulati marked this conversation as resolved.
|
||
|
|
||
| this.log(chalk.green('Collection Information:')) | ||
| this.log(chalk.dim(` Namespace: ${this.rtNamespace}`)) | ||
|
|
||
| if (collectionInfo && collectionInfo.length > 0) { | ||
| this.log(chalk.dim(` Total Collections: ${collectionInfo.length}`)) | ||
| this.log('') | ||
|
|
||
| collectionInfo.forEach((collection, index) => { | ||
| this.log(chalk.cyan(` Collection ${index + 1}:`)) | ||
| Object.entries(collection).forEach(([key, value]) => { | ||
| this.log(chalk.dim(` ${key}: ${this.formatValue(value)}`)) | ||
| }) | ||
| if (index < collectionInfo.length - 1) { | ||
| this.log('') | ||
| } | ||
| }) | ||
| } else { | ||
| this.log(chalk.dim(' No collections found')) | ||
| } | ||
|
|
||
| this.log('') | ||
| this.log(chalk.dim(` Retrieved: ${new Date().toLocaleString()}`)) | ||
|
|
||
| return collectionInfo | ||
| } catch (error) { | ||
| this.debugLogger?.error?.('Error fetching collection info', error) | ||
|
|
||
| this.log(chalk.red('Failed to retrieve collection information')) | ||
| this.log(chalk.dim(` Namespace: ${this.rtNamespace}`)) | ||
| this.log(chalk.dim(` Error: ${error.message}`)) | ||
|
|
||
| this.error(`Failed to fetch collection information: ${error.message}`) | ||
|
simrangulati marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| formatValue (value) { | ||
| if (typeof value === 'number') { | ||
| // Format large numbers with commas | ||
| return value.toLocaleString() | ||
| } | ||
| if (typeof value === 'object' && value !== null) { | ||
| return JSON.stringify(value, null, 2) | ||
| } | ||
| return String(value) | ||
| } | ||
| } | ||
|
|
||
| GetCollectionInfos.description = 'Get details of your App Builder database collections' | ||
|
|
||
| GetCollectionInfos.examples = [ | ||
| '$ aio app db getCollectionInfos', | ||
| '$ aio app db getCollectionInfos --json' | ||
| ] | ||
|
|
||
| GetCollectionInfos.flags = { | ||
| ...DBBaseCommand.flags | ||
| } | ||
|
|
||
| GetCollectionInfos.args = {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| Copyright 2025 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { DBBaseCommand } from '../../../DBBaseCommand.js' | ||
| import chalk from 'chalk' | ||
|
|
||
| export class GetCollectionNames extends DBBaseCommand { | ||
| async run () { | ||
| try { | ||
| this.log(chalk.blue('Fetching collection names...')) | ||
|
|
||
| const client = await this.db.connect() | ||
| const collectionInfo = await client.listCollections() | ||
|
|
||
| this.debugLogger?.info?.(`Retrieved ${collectionInfo.length} collections from database`) | ||
|
|
||
| // Extract only the names from the collection info | ||
| const collectionNames = collectionInfo.map(collection => collection.name) | ||
|
|
||
| if (this.flags.json) { | ||
| return collectionNames | ||
| } | ||
|
simrangulati marked this conversation as resolved.
|
||
|
|
||
| this.log(chalk.green('Collection names:')) | ||
| this.log(JSON.stringify(collectionNames, null, 2)) | ||
|
|
||
| return collectionNames | ||
| } catch (error) { | ||
| this.debugLogger?.error?.('Error fetching collection names', error) | ||
|
|
||
| this.log(chalk.red('Error fetching collection names')) | ||
| this.log(chalk.dim(` Namespace: ${this.rtNamespace}`)) | ||
| this.log(chalk.dim(` Error: ${error.message}`)) | ||
|
|
||
| this.error(`Failed to fetch collection names: ${error.message}`) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| GetCollectionNames.description = 'Get collection names of your App Builder database' | ||
|
|
||
| GetCollectionNames.examples = [ | ||
| '$ aio app db GetCollectionNames', | ||
| '$ aio app db GetCollectionNames --json' | ||
| ] | ||
|
|
||
| GetCollectionNames.flags = { | ||
| ...DBBaseCommand.flags | ||
| } | ||
|
|
||
| GetCollectionNames.args = {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| Copyright 2025 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { GetCollectionNames } from '../getCollectionNames.js' | ||
|
|
||
| export class Collections extends GetCollectionNames { | ||
| async run () { | ||
| // Delegate to the parent GetCollectionNames implementation | ||
| return super.run() | ||
| } | ||
| } | ||
|
|
||
| Collections.description = 'Show collection names of your App Builder database (alias for getCollectionNames)' | ||
|
|
||
| Collections.examples = [ | ||
| '$ aio app db show collections', | ||
| '$ aio app db show collections --json' | ||
| ] | ||
|
|
||
| Collections.flags = { | ||
| ...GetCollectionNames.flags | ||
| } | ||
|
|
||
| Collections.args = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| Copyright 2025 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { DBBaseCommand } from '../../../DBBaseCommand.js' | ||
| import chalk from 'chalk' | ||
|
|
||
| export class Stats extends DBBaseCommand { | ||
| async run () { | ||
| try { | ||
| this.log(chalk.blue('Fetching database statistics...')) | ||
|
|
||
| const client = await this.db.connect() | ||
| const stats = await client.dbStats() | ||
|
|
||
| this.debugLogger?.info?.('Database statistics retrieved:', stats) | ||
|
|
||
| const result = { | ||
| ...stats, | ||
| namespace: this.rtNamespace, | ||
| timestamp: new Date().toISOString() | ||
| } | ||
|
|
||
| if (this.flags.json) { | ||
| return result | ||
| } | ||
|
simrangulati marked this conversation as resolved.
|
||
|
|
||
| this.displayStats(stats) | ||
|
|
||
| return result | ||
| } catch (error) { | ||
| this.debugLogger?.error?.('Stats command error:', error) | ||
|
|
||
| this.log(chalk.red('Failed to retrieve database statistics')) | ||
| this.log(chalk.dim(` Namespace: ${this.rtNamespace}`)) | ||
| this.log(chalk.dim(` Error: ${error.message}`)) | ||
|
|
||
| this.error(`Failed to fetch database statistics: ${error.message}`) | ||
|
simrangulati marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| displayStats (stats) { | ||
| this.log(chalk.green('Database Statistics:')) | ||
| this.log(chalk.dim(` Namespace: ${this.rtNamespace}`)) | ||
|
|
||
| if (stats && typeof stats === 'object') { | ||
| // Format and display stats in a readable way | ||
| Object.entries(stats).forEach(([key, value]) => { | ||
| this.log(chalk.dim(` ${key}: ${this.formatValue(value)}`)) | ||
| }) | ||
| } else { | ||
| this.log(chalk.dim(` Raw Stats: ${JSON.stringify(stats, null, 2)}`)) | ||
| } | ||
|
|
||
| this.log('') | ||
| this.log(chalk.dim(` Retrieved: ${new Date().toLocaleString()}`)) | ||
| } | ||
|
|
||
| formatValue (value) { | ||
| if (typeof value === 'number') { | ||
| // Format large numbers with commas | ||
| return value.toLocaleString() | ||
| } | ||
| if (typeof value === 'object' && value !== null) { | ||
| return JSON.stringify(value, null, 2) | ||
| } | ||
| return String(value) | ||
| } | ||
| } | ||
|
|
||
| Stats.description = 'Get statistics of your App Builder database' | ||
|
|
||
| Stats.examples = [ | ||
| '$ aio app db stats', | ||
| '$ aio app db stats --json' | ||
| ] | ||
|
|
||
| Stats.flags = { | ||
| ...DBBaseCommand.flags | ||
| } | ||
|
|
||
| Stats.args = {} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.