UNPKG

convex

Version:

Client for the Convex Cloud

179 lines (178 loc) 6.09 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; 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 __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var schema_exports = {}; __export(schema_exports, { SchemaDefinition: () => SchemaDefinition, TableDefinition: () => TableDefinition, defineSchema: () => defineSchema, defineTable: () => defineTable }); module.exports = __toCommonJS(schema_exports); var import_validator = require("../values/validator.js"); class TableDefinition { /** * @internal */ constructor(documentType) { __publicField(this, "indexes"); __publicField(this, "searchIndexes"); __publicField(this, "vectorIndexes"); // The type of documents stored in this table. __publicField(this, "validator"); this.indexes = []; this.searchIndexes = []; this.vectorIndexes = []; this.validator = documentType; } /** * Define an index on this table. * * To learn about indexes, see [Defining Indexes](https://docs.convex.dev/using/indexes). * * @param name - The name of the index. * @param fields - The fields to index, in order. Must specify at least one * field. * @returns A {@link TableDefinition} with this index included. */ index(name, fields) { this.indexes.push({ indexDescriptor: name, fields }); return this; } /** * Define a search index on this table. * * To learn about search indexes, see [Search](https://docs.convex.dev/text-search). * * @param name - The name of the index. * @param indexConfig - The search index configuration object. * @returns A {@link TableDefinition} with this search index included. */ searchIndex(name, indexConfig) { this.searchIndexes.push({ indexDescriptor: name, searchField: indexConfig.searchField, filterFields: indexConfig.filterFields || [] }); return this; } /** * Define a vector index on this table. * * To learn about vector indexes, see [Vector Search](https://docs.convex.dev/vector-search). * * @param name - The name of the index. * @param indexConfig - The vector index configuration object. * @returns A {@link TableDefinition} with this vector index included. */ vectorIndex(name, indexConfig) { this.vectorIndexes.push({ indexDescriptor: name, vectorField: indexConfig.vectorField, dimensions: indexConfig.dimensions, filterFields: indexConfig.filterFields || [] }); return this; } /** * Work around for https://github.com/microsoft/TypeScript/issues/57035 */ self() { return this; } /** * Export the contents of this definition. * * This is called internally by the Convex framework. * @internal */ export() { return { indexes: this.indexes, searchIndexes: this.searchIndexes, vectorIndexes: this.vectorIndexes, documentType: this.validator.json }; } } function defineTable(documentSchema) { if ((0, import_validator.isValidator)(documentSchema)) { return new TableDefinition(documentSchema); } else { return new TableDefinition(import_validator.v.object(documentSchema)); } } class SchemaDefinition { /** * @internal */ constructor(tables, options) { __publicField(this, "tables"); __publicField(this, "strictTableNameTypes"); __publicField(this, "schemaValidation"); this.tables = tables; this.schemaValidation = options?.schemaValidation === void 0 ? true : options.schemaValidation; } /** * Export the contents of this definition. * * This is called internally by the Convex framework. * @internal */ export() { return JSON.stringify({ tables: Object.entries(this.tables).map(([tableName, definition]) => { const { indexes, searchIndexes, vectorIndexes, documentType } = definition.export(); return { tableName, indexes, searchIndexes, vectorIndexes, documentType }; }), schemaValidation: this.schemaValidation }); } } function defineSchema(schema, options) { return new SchemaDefinition(schema, options); } const _systemSchema = defineSchema({ _scheduled_functions: defineTable({ name: import_validator.v.string(), args: import_validator.v.array(import_validator.v.any()), scheduledTime: import_validator.v.float64(), completedTime: import_validator.v.optional(import_validator.v.float64()), state: import_validator.v.union( import_validator.v.object({ kind: import_validator.v.literal("pending") }), import_validator.v.object({ kind: import_validator.v.literal("inProgress") }), import_validator.v.object({ kind: import_validator.v.literal("success") }), import_validator.v.object({ kind: import_validator.v.literal("failed"), error: import_validator.v.string() }), import_validator.v.object({ kind: import_validator.v.literal("canceled") }) ) }), _storage: defineTable({ sha256: import_validator.v.string(), size: import_validator.v.float64(), contentType: import_validator.v.optional(import_validator.v.string()) }) }); //# sourceMappingURL=schema.js.map