Skip to content

Migrate file commands to Zod#7370

Open
waldekmastykarz wants to merge 3 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-file-commands-to-zod
Open

Migrate file commands to Zod#7370
waldekmastykarz wants to merge 3 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-file-commands-to-zod

Conversation

@waldekmastykarz
Copy link
Copy Markdown
Member

Summary

Migrates all 5 file commands to use Zod schemas for option definitions and validation, replacing the old #initTelemetry, #initOptions, and #initValidators pattern.

Commands migrated

Command Key changes
file add folderUrl/siteUrl SharePoint URL validation via Zod refine; filePath existence check via getRefinedSchema
file copy webUrl SharePoint URL validation; nameConflictBehavior as z.enum
file list webUrl SharePoint URL validation; recursive as optional boolean
file move webUrl SharePoint URL validation; nameConflictBehavior as z.enum
file convert pdf sourceFile/targetFile existence checks via getRefinedSchema

Changes per file

  • Command files: Removed constructors, #initTelemetry, #initOptions, #initValidators; added exported z.strictObject schema with globalOptionsZod.shape spread and get schema() getter
  • Spec files: Updated validation tests to use commandOptionsSchema.safeParse() instead of command.validate()

Closes #7303

waldekmastykarz and others added 2 commits May 28, 2026 15:20
Migrates all 5 file commands under src/m365/file/commands/ from the
old options/validators/telemetry pattern to Zod schemas:

- file add
- file copy
- file list
- file move
- file convert pdf

Closes pnp#7303

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds missing test to cover the folderUrl validation error callback,
fixing 100% function coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates the m365 file command set from the legacy #initTelemetry/#initOptions/#initValidators pattern to Zod-based option schemas, aligning these commands with the newer schema-driven command infrastructure (option metadata + validation + telemetry).

Changes:

  • Replaced manual option/validator/telemetry initialization with exported z.strictObject option schemas and schema getters for 5 file commands.
  • Moved additional validations (eg. file existence, optional URL validity) into getRefinedSchema() where needed.
  • Updated unit tests to validate options via commandInfo.command.getSchemaToParse().safeParse(...) rather than command.validate(...).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/m365/file/commands/file-move.ts Defines Zod schema for file move options (incl. enums/aliases) and removes legacy init methods.
src/m365/file/commands/file-move.spec.ts Switches validation tests to schema safeParse.
src/m365/file/commands/file-list.ts Defines Zod schema for file list options and removes legacy init methods.
src/m365/file/commands/file-list.spec.ts Switches validation tests to schema safeParse.
src/m365/file/commands/file-copy.ts Defines Zod schema for file copy options (incl. enums/aliases) and removes legacy init methods.
src/m365/file/commands/file-copy.spec.ts Switches validation tests to schema safeParse.
src/m365/file/commands/file-add.ts Defines Zod schema for file add options and adds refined schema checks (file existence, optional siteUrl).
src/m365/file/commands/file-add.spec.ts Switches validation tests to schema safeParse and adds a folderUrl-invalid test.
src/m365/file/commands/convert/convert-pdf.ts Defines Zod schema for file convert pdf options and moves path checks into refined schema.
src/m365/file/commands/convert/convert-pdf.spec.ts Switches validation tests to schema safeParse.

Comment thread src/m365/file/commands/file-add.ts
@MartinM85 MartinM85 marked this pull request as draft June 3, 2026 05:39
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@waldekmastykarz waldekmastykarz marked this pull request as ready for review June 5, 2026 11:08
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.

Migrate file commands to Zod

2 participants