import { Database, aql } from "arangojs"; import { DocumentCollection, SchemaOptions } from "arangojs/collections"; import { EnsurePersistentIndexOptions } from "arangojs/indexes"; import { JSONSchema7 } from "json-schema"; // It's good practice to specify the URL. // We connect to the _system database first to check if our target DB exists. const sysdb = new Database({ url: "http://localhost:8529", auth: { username: "root", password: "pass", }, }); const db = sysdb.database("prod"); const ent = async ( name: string, schema?: SchemaOptions, index?: EnsurePersistentIndexOptions ) => { const col = db.collection(name); // @ts-ignore await col.exists().then((e) => e || db.createCollection(name)); schema && col.properties({ schema }); index && col.ensureIndex(index); return col; }; const Games = ent("games", { rule: { type: "object", properties: { name: { type: "string" }, }, } as JSONSchema7, }); const Instances = ent("instances"); const Humans = ent("humans");