Skip to content

Add udf and trigger commands for server-side programming management#125

Open
mkrueger wants to merge 1 commit into
mainfrom
dev/mkrueger/udf-trigger
Open

Add udf and trigger commands for server-side programming management#125
mkrueger wants to merge 1 commit into
mainfrom
dev/mkrueger/udf-trigger

Conversation

@mkrueger

Copy link
Copy Markdown
Contributor

Summary

Adds udf and trigger commands so the shell can manage the remaining Cosmos DB for NoSQL server-side programming resources, completing the feature set requested in #103 (the sproc command was added separately in #124).

Both commands mirror the sproc surface and operate on the current container (same scope as index).

udf

Subcommand Behavior
list List user-defined function ids in the current container
show <name> Display a UDF body
exists <name> Boolean result usable in if/while conditions
create <name> <file> Create from a JS file or piped body; --force to replace
delete <name> Delete a UDF

trigger

Subcommand Behavior
list List trigger ids with their type and operation
show <name> Display a trigger body
exists <name> Boolean result usable in if/while conditions
create <name> <file> Create from a JS file or piped body; --type (pre/post, required), --operation (all/create/replace/delete/update, default all), --force to replace
delete <name> Delete a trigger

Examples

udf list
udf create myFunc ./myFunc.js
udf exists myFunc

trigger list
trigger create myTrigger ./myTrigger.js --type pre --operation create
trigger create myTrigger ./myTrigger.js --type post --force

Notes

  • Both commands are restricted in MCP (run manually in the shell), consistent with sproc.
  • list returns structured JSON for piping; exists returns a ShellBool.

Testing

  • Added unit tests for the pure helpers (subcommand normalization, trigger type/operation parsing).
  • dotnet build clean; full test suite passes (1315 passed, 74 skipped, 0 failed), including the localization key audit and help verification tests that validate command registration.

Docs

Part of #103.

Adds 'udf' and 'trigger' commands that mirror the 'sproc' surface for the
remaining Cosmos DB for NoSQL server-side resources:

- udf: list, show, exists, create (from file or piped body, --force), delete
- trigger: list, show, exists, create (--type pre/post, --operation, --force), delete

Both operate on the current container (same scope as 'index'), return JSON
results for piping, and expose 'exists' as a ShellBool for if/while conditions.
Includes localization strings, docs, CHANGELOG, and unit tests for the pure
helpers (subcommand normalization, trigger type/operation parsing).

Part of #103.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new CLI surfaces to manage Cosmos DB for NoSQL server-side programming artifacts (UDFs and triggers) from within CosmosDBShell, completing the server-side programming management set alongside the previously added stored procedure support.

Changes:

  • Introduces new udf and trigger commands with list/show/exists/create/delete subcommands scoped to the current container (with --database/--container overrides).
  • Adds localized help/error strings for both commands and updates user docs (docs/commands.md) plus the Unreleased changelog.
  • Adds unit tests for the pure helper logic (subcommand normalization; trigger type/operation parsing).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/commands.md Documents the new udf and trigger command surfaces and examples.
CosmosDBShell/lang/en.ftl Adds localization strings for help text and errors for both commands.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/UdfCommand.cs Implements udf command behavior (list/show/exists/create/delete) against container scripts.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/TriggerCommand.cs Implements trigger command behavior including --type and --operation parsing.
CosmosDBShell.Tests/CommandTests/UdfCommandTests.cs Tests UdfCommand.NormalizeSubcommand.
CosmosDBShell.Tests/CommandTests/TriggerCommandTests.cs Tests TriggerCommand helper parsing/normalization.
CHANGELOG.md Adds Unreleased entries describing the new commands.

Comment on lines +28 to +32
- 'list' returns the user-defined function ids in the container.
- 'show <name>' returns the body of a user-defined function.
- 'create <name> <file>' creates a user-defined function from a JavaScript file. Pass --force to replace an existing one.
- 'delete <name>' removes a user-defined function.
This command is restricted in MCP. Run it manually in the shell.
Comment on lines +28 to +32
- 'list' returns the trigger ids in the container with their type and operation.
- 'show <name>' returns the body of a trigger.
- 'create <name> <file>' creates a trigger from a JavaScript file. --type selects pre or post, --operation selects all/create/replace/delete/update, and --force replaces an existing one.
- 'delete <name>' removes a trigger.
This command is restricted in MCP. Run it manually in the shell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants