spawn/packages/shared/src/parse.ts
A d04096a15b
feat!: remove Fly.io cloud provider support (#1979)
* feat!: remove Fly.io cloud provider support

Drop Fly.io as a supported cloud provider. Sprite (which uses Fly.io
infrastructure internally) is retained.

- Delete packages/cli/src/fly/ module, sh/fly/ scripts, fixtures/fly/
- Remove fly cloud entry and 6 fly matrix entries from manifest.json
- Remove fly imports, destroy cases, and connection handlers from commands.ts
- Remove fly-ssh sentinel from security.ts
- Port E2E test suite from Fly.io to AWS Lightsail (fly-e2e.sh → aws-e2e.sh)
- Update README (7 clouds, 42 combinations), CLAUDE.md, and skill prompts
- Clean up fly references in build config, gitignore, icon sources
- Bump CLI version to 0.11.0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: restore Docker image build under sh/docker/

Move openclaw Dockerfile from sh/fly/docker/ to sh/docker/ and rename
workflow from fly-docker.yml to docker.yml with updated paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: fix extra blank lines in commands.ts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: spawn-bot <spawn-bot@openrouter.ai>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: L <6723574+louisgv@users.noreply.github.com>
2026-02-27 00:06:32 -05:00

48 lines
1.3 KiB
TypeScript

// shared/parse.ts — Schema-validated JSON parsing (replaces unsafe `as` casts)
import * as v from "valibot";
/**
* Parse a JSON string and validate it against a valibot schema.
* Returns the validated value, or null if parsing/validation fails.
*/
export function parseJsonWith<T extends v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>>(
text: string,
schema: T,
): v.InferOutput<T> | null {
try {
return v.parse(schema, JSON.parse(text));
} catch {
return null;
}
}
/**
* Escape hatch: parse JSON to `unknown` without schema validation.
* Use for dynamic response formats where a fixed schema isn't practical
* (e.g., cloud APIs with 5+ response shapes).
*/
export function parseJsonRaw(text: string): unknown {
try {
return JSON.parse(text);
} catch {
return null;
}
}
/**
* Parse a JSON string and return it as a Record<string, unknown> or null.
* Rejects non-object results (arrays, primitives).
* Use for API responses that are always a JSON object.
*/
export function parseJsonObj(text: string): Record<string, unknown> | null {
try {
const val = JSON.parse(text);
if (val !== null && typeof val === "object" && !Array.isArray(val)) {
return val;
}
return null;
} catch {
return null;
}
}