fortify-schema
Version:
TypeScript interface-like schema validation system that's easier to use than Zod
81 lines (62 loc) ⢠2.67 kB
text/typescript
import { Interface } from "../schema/mode/interfaces/Interface";
console.log("š§ SIMPLE PARENTHESES SYNTAX TEST");
console.log("=================================\n");
// Test simple parentheses syntax without nested parentheses
const SimpleParenthesesSchema = Interface({
role: "admin|user|guest",
// Simple parentheses syntax without nested parentheses
permissions: "when(role=admin) then(string) else(string?)",
id: "positive",
name: "string"
});
console.log("ā
Simple parentheses syntax schema created successfully!");
// Test TypeScript type inference
const testData = {
role: "admin" as const,
permissions: "read", // Should be inferred as string
id: 1,
name: "Admin User"
};
const result = SimpleParenthesesSchema.safeParse(testData);
console.log("ā
Simple parentheses test:", result.success);
// Test with type error - this should show TypeScript error if type inference works
const invalidData = {
role: "admin" as const,
permissions: 123, // ā Should show TypeScript error: number instead of string
id: 1,
name: "Admin User"
};
console.log("šÆ Testing TypeScript error detection for simple parentheses syntax...");
console.log("If you see a TypeScript error above, type inference is working!");
// Now test with array syntax that has nested parentheses
const ArrayParenthesesSchema = Interface({
role: "admin|user|guest",
// This has nested parentheses: string[]
permissions: "when(role=admin) then(string[]) else(string[]?)",
id: "positive",
name: "string"
});
console.log("ā
Array parentheses syntax schema created successfully!");
// Test with array data
const arrayTestData = {
role: "admin" as const,
permissions: ["read", "write"], // Should be inferred as string[]
id: 1,
name: "Admin User"
};
const arrayResult = ArrayParenthesesSchema.safeParse(arrayTestData);
console.log("ā
Array parentheses test:", arrayResult.success);
// Test with array type error
const invalidArrayData = {
role: "admin" as const,
permissions: ["read", "write", 2], // ā Should show TypeScript error: number in string[]
id: 1,
name: "Admin User"
};
console.log("šÆ Testing TypeScript error detection for array parentheses syntax...");
console.log("If you see a TypeScript error above, array type inference is working!");
console.log("\nš§ PARENTHESES SYNTAX ANALYSIS");
console.log("==============================");
console.log("ā
Simple parentheses: when(condition) then(string) else(string?)");
console.log("š§ Array parentheses: when(condition) then(string[]) else(string[]?)");
console.log("š The issue might be with nested parentheses in TypeScript template literals");