fortify-schema
Version:
A modern TypeScript validation library designed around familiar interface syntax and powerful conditional validation. Experience schema validation that feels natural to TypeScript developers while unlocking advanced runtime validation capabilities.
82 lines (61 loc) • 2.34 kB
Markdown
## fortify-ignore snipper
works for single line but for multiple lines, faild.
```ts
// @fortify-ignore
defaultTags: 'when config.tags.$exists() *? string[] : =test',
// Nested object defaults
defaultSettings:
'when config.settings.$exists() *? any : ={"theme":"dark","lang":"en"}',
```
Errors: Unknown type: "theme". or something like it
Collors dispears
No more hightligting everything are like normal string so no good (since before it was working but more we've added features more it got old)
## Syntax higthligth and diagnostics
- Its only higthligth "" or `` syntaxes but not for '' syntaxes
- Its only diagnos for "" syntaxes not for `` or '' syntaxes
```ts
'when config.settings.$exists() *? any : ={"theme":"dark","lang":"en"}',
```
## Conditionnal errors
```ts
// Array property access
hasFirstItem: "when data.items[0].$exists() *? boolean : =false",
// Invalid condition: "data.items[0].$exists()". Expected field=value, field.method(), or field~pattern.
```
## special chars
```typescript
const SpecialCharsSchema = Interface({
config: "any?",
// Properties with hyphens
hasAdminOverride:
'when config["admin-override"].$exists() *? boolean : =not_allowed',
// Properties with spaces
hasSpecialConfig:
'when config["special config"].$exists() *? boolean : =no_sp_config',
});
const config = {
"admin-override": true,
"special config": true,
};
const result = SpecialCharsSchema.safeParse({
config,
hasAdminOverride: "not_allowed", // should throw err
hasSpecialConfig: "no_sp_config", // should also throw err
});
if (result.success) {
console.log("✅ Expected success:", result.data);
} else {
console.log("❌ Unexpected errors:", result.errors);
}
/*
* bug output: Invalid schema syntax: "admin-override". Expected a type, type(constraints), type[], or type?
Invalid schema syntax: "special config". Expected a type, type(constraints), type[], or type?
*/
```
```ts
// Union with regex
code: "string(/^[A-Z]{3}$/)|string(/^\\d{6}$/)", // 3 letters OR 6 digits
//doesn't higthligt
```
## Important
We need to integrate all availlable and supported types in the extension. You will find all types (strongly tested and approved) [here](./../../../../docs/ALL_TYPES.md)