aws / aws/aws-toolkit-vscode

validate runtime objects (e.g. package.json, settings.json, etc) with zod or other "data validation" library

Open
#3,368 1 comment 0 reactions 0 assignees View on GitHub
architecture technical-debt
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

## Problem

For validating unknown input/data (`package.json`, `settings.json`, `globalState`, ...) at runtime we use either [ad-hoc procedural logic](https://github.com/aws/aws-toolkit-vscode/blob/5439f9527224d8d1c0b98cd9941ee55a0cefb9ae/src/shared/sam/debugger/awsSamDebugConfigurationValidator.ts#L33-L94) or typescript type generators: https://github.com/aws/aws-toolkit-vscode/blob/5439f9527224d8d1c0b98cd9941ee55a0cefb9ae/src/shared/settings.ts#L458-L482

## Solution

TypScript ecosystem now has rather mature libraries like [zod](https://www.youtube.com/watch?v=CughWjaoXZw) which achieve something similar to clojure's [spec](https://clojure.org/guides/spec): rich description of objects with runtime-checking (as opposed to typescript's compile-time-only checking).

- use zod(?) to replace [AwsSamDebugConfigurationValidator](https://github.com/aws/aws-toolkit-vscode/blob/8182aa558ed2b9a144ab9dff5b55b2abcedd4ef3/src/shared/sam/debugger/awsSamDebugConfigurationValidator.ts), [sharedCredentialsValidation.ts](https://github.com/aws/aws-toolkit-vscode/pull/3409)
- zod is an extra dependency, but itself has zero transitive dependencies.
- zod specs can also be used to _define_ TypeScript types, which avoids duplication for cases where you need both.
- via `z.infer()`

Contributor guide

Open the contributing guide

Research direction

Start by reading src/shared/sam/debugger/awsSamDebugConfigurationValidator.ts and the generated type logic in src/shared/settings.ts. Review the referenced sharedCredentialsValidation.ts change and determine which runtime objects are in scope for a common validation approach. Done means the named validators are replaced or unified while preserving runtime checks and TypeScript type support.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.