convex
Version:
Client for the Convex Cloud
118 lines (117 loc) • 2.98 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var validator_exports = {};
__export(validator_exports, {
Validator: () => Validator,
v: () => v
});
module.exports = __toCommonJS(validator_exports);
var import_value = require("./value.js");
class Validator {
/**
* @internal
*/
constructor(json, optional) {
this.json = json;
this.optional = optional;
}
}
const v = {
id(tableName) {
return new Validator({ type: "id", tableName }, false);
},
null() {
return new Validator({ type: "null" }, false);
},
/**
* Alias for `v.float64()`
*/
number() {
return new Validator({ type: "number" }, false);
},
float64() {
return new Validator({ type: "number" }, false);
},
/**
* @deprecated Use `v.int64()` instead
*/
bigint() {
return new Validator({ type: "bigint" }, false);
},
int64() {
return new Validator({ type: "bigint" }, false);
},
boolean() {
return new Validator({ type: "boolean" }, false);
},
string() {
return new Validator({ type: "string" }, false);
},
bytes() {
return new Validator({ type: "bytes" }, false);
},
literal(literal) {
const value = (0, import_value.convexToJson)(literal);
return new Validator({ type: "literal", value }, false);
},
array(values) {
return new Validator({ type: "array", value: values.json }, false);
},
object(schema) {
return new Validator(
{
type: "object",
value: Object.fromEntries(
Object.entries(schema).map(([k, v2]) => [
k,
{ fieldType: v2.json, optional: v2.optional }
])
)
},
false
);
},
/** @internal */
record(keys, values) {
return new Validator(
{
type: "record",
keys: keys.json,
values: { fieldType: values.json, optional: values.optional }
},
false
);
},
union(...schemaTypes) {
return new Validator(
{
type: "union",
value: schemaTypes.map((t) => t.json)
},
false
);
},
any() {
return new Validator({ type: "any" }, false);
},
optional(inner) {
return new Validator(inner.json, true);
}
};
//# sourceMappingURL=validator.js.map