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 OnlyReflectionWriteonlySchema.access: "write"Always "write".
isOptional
This item is read only and cannot be modified. Read OnlyReflectionWriteonlySchema.isOptional: booleanForwarded from the wrapped schema.
minimum
This item is read only and cannot be modified. Read OnlyReflectionWriteonlySchema.minimum: number?Forwarded from the wrapped schema.
maximum
This item is read only and cannot be modified. Read OnlyReflectionWriteonlySchema.maximum: number?Forwarded from the wrapped schema.
Functions
safeParse
ParsingWriteonlySchema:safeParse(value: unknown) → Result<T>Defers to the wrapped schema.
parse
ParsingWriteonlySchema:parse(value: unknown) → TValidates value and returns it, throwing on failure.
Errors
| Type | Description |
|---|---|
| "expected ..." | Thrown when `value` fails the wrapped schema |
readonly
WrapperReturns a read-only wrapper around the same schema, replacing the write-only marker.
writeonly
WrapperReturns the same schema, since it is already write-only.