import { query as q } from "faunadb" ; import { IndexResource , Resource } from "../types" ; import client from "./client" ; import wait from "./wait" ; import createOrUpdateResources from "./createOrUpdateStandardResources" ; export default async function updateIndexes ( indexes ) { await deleteOriginalIndexes ( indexes ) ; await wait ( 60 * 1000 ) ; await createOrUpdateResources ( indexes as Resource [ ] , "indexes" ) ; } async function deleteOriginalIndexes ( indexes ) { return client . query ( q . Foreach ( indexes , q . Lambda ( "index" , q . Let ( { name : q . Select ( [ "name" ] , q . Var ( "index" ) ) , indexRef : q . Index ( q . Var ( "name" ) ) , exists : q . Exists ( q . Var ( "indexRef" ) ) } , q . If ( q . Var ( "exists" ) , q . Delete ( q . Var ( "indexRef" ) ) , null ) ) ) ) ) ; }