Skip to main content

WriteonlySchema

Marks a field as write-only, so the record an ObjectSchema parses to declares it write. Created by calling :writeonly() on any schema, or by wrapping one with Vet.writeonly.

local PlayerData = v.object({
	name = v.string(),
	secretToken = v.string():writeonly(),
})

type PlayerData = v.infer<typeof(PlayerData)>
--> { name: string, write secretToken: string }

local data = PlayerData:parse(payload)

data.secretToken = "rotated" --> fine
print(data.secretToken)      --> analysis error: `secretToken` is write-only

Use it for a field that has to be validated on the way in but must not be read back out by accident — a token, a password, a nonce. Like ReadonlySchema this is a type-level restriction, so the value is still present at runtime and still reachable through a cast.

Properties​

access​

This item is read only and cannot be modified. Read OnlyReflection
WriteonlySchema.access: "write"

Always "write".

isOptional​

This item is read only and cannot be modified. Read OnlyReflection
WriteonlySchema.isOptional: boolean

Forwarded from the wrapped schema.

minimum​

This item is read only and cannot be modified. Read OnlyReflection
WriteonlySchema.minimum: number?

Forwarded from the wrapped schema.

maximum​

This item is read only and cannot be modified. Read OnlyReflection
WriteonlySchema.maximum: number?

Forwarded from the wrapped schema.

Functions​

safeParse​

Parsing
WriteonlySchema:safeParse(value: unknown) → Result<T>

Defers to the wrapped schema.

parse​

Parsing
WriteonlySchema:parse(value: unknown) → T

Validates value and returns it, throwing on failure.

Errors

TypeDescription
"expected ..."Thrown when `value` fails the wrapped schema

readonly​

Wrapper
WriteonlySchema:readonly() → ReadonlySchema<T>

Returns a read-only wrapper around the same schema, replacing the write-only marker.

writeonly​

Wrapper
WriteonlySchema:writeonly() → WriteonlySchema<T>

Returns the same schema, since it is already write-only.

Show raw api
{
    "functions": [
        {
            "name": "safeParse",
            "desc": "Defers to the wrapped schema.\n\t",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "unknown"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Parsing"
            ],
            "source": {
                "line": 572,
                "path": "src/init.luau"
            }
        },
        {
            "name": "parse",
            "desc": "Validates `value` and returns it, throwing on failure.\n\t",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "unknown"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "tags": [
                "Parsing"
            ],
            "errors": [
                {
                    "lua_type": "\"expected ...\"",
                    "desc": "Thrown when `value` fails the wrapped schema"
                }
            ],
            "source": {
                "line": 603,
                "path": "src/init.luau"
            }
        },
        {
            "name": "readonly",
            "desc": "Returns a read-only wrapper around the same schema, replacing the\nwrite-only marker.\n\t",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ReadonlySchema<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 631,
                "path": "src/init.luau"
            }
        },
        {
            "name": "writeonly",
            "desc": "Returns the same schema, since it is already write-only.\n\t",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "WriteonlySchema<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 657,
                "path": "src/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "access",
            "desc": "Always `\"write\"`.\n\t",
            "lua_type": "\"write\"",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 488,
                "path": "src/init.luau"
            }
        },
        {
            "name": "isOptional",
            "desc": "Forwarded from the wrapped schema.\n\t",
            "lua_type": "boolean",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 508,
                "path": "src/init.luau"
            }
        },
        {
            "name": "minimum",
            "desc": "Forwarded from the wrapped schema.\n\t",
            "lua_type": "number?",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 527,
                "path": "src/init.luau"
            }
        },
        {
            "name": "maximum",
            "desc": "Forwarded from the wrapped schema.\n\t",
            "lua_type": "number?",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 546,
                "path": "src/init.luau"
            }
        }
    ],
    "types": [],
    "name": "WriteonlySchema",
    "desc": "Marks a field as write-only, so the record an [ObjectSchema] parses to\ndeclares it `write`. Created by calling `:writeonly()` on any schema, or by\nwrapping one with [Vet.writeonly].\n\n```lua\nlocal PlayerData = v.object({\n\tname = v.string(),\n\tsecretToken = v.string():writeonly(),\n})\n\ntype PlayerData = v.infer<typeof(PlayerData)>\n--> { name: string, write secretToken: string }\n\nlocal data = PlayerData:parse(payload)\n\ndata.secretToken = \"rotated\" --> fine\nprint(data.secretToken)      --> analysis error: `secretToken` is write-only\n```\n\nUse it for a field that has to be validated on the way in but must not be\nread back out by accident — a token, a password, a nonce. Like\n[ReadonlySchema] this is a type-level restriction, so the value is still\npresent at runtime and still reachable through a cast.",
    "source": {
        "line": 427,
        "path": "src/init.luau"
    }
}