var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { generateApolloClient } from '@deep-foundation/hasura/client.js';
import Debug from 'debug';
import { DeepClient } from '../imports/client.js';
const debug = Debug('deeplinks:migrations:tsx');
const log = debug.extend('log');
const error = debug.extend('error');
const rootClient = generateApolloClient({
    path: `${process.env.MIGRATIONS_HASURA_PATH}/v1/graphql`,
    ssl: !!+(process.env.MIGRATIONS_HASURA_SSL || 0),
    secret: process.env.MIGRATIONS_HASURA_SECRET,
});
var dc = '@deep-foundation/core';
const deep = new DeepClient({
    apolloClient: rootClient,
});
export const demoRules = ['usersCanSeeAll', 'usersCanInsertSafeLinks', 'usersCanUpdateSafeLinks', 'usersCanDeleteSafeLinks'];
export const up = () => __awaiter(void 0, void 0, void 0, function* () {
    log('up');
    const TSX = yield deep.id('@deep-foundation/tsx', 'TSX');
    const { data: rules } = yield deep.select({ from_id: yield deep.id('deep', 'admin'), type_id: deep.idLocal(dc, 'Contain'), string: { value: { _in: demoRules } } }, { apply: 'rules' });
    const { data: selectors } = yield deep.Traveler(rules).to().out({ type_id: deep.idLocal(dc, 'RuleObject') }).to().select();
    yield deep.insert(selectors.map(s => ({
        from_id: s.id,
        type_id: deep.idLocal('@deep-foundation/core', 'SelectorInclude'),
        to_id: TSX,
        out: {
            type_id: deep.idLocal('@deep-foundation/core', 'SelectorTree'),
            to_id: deep.idLocal('@deep-foundation/core', 'typesTree'),
        },
    })));
});
export const down = () => __awaiter(void 0, void 0, void 0, function* () {
    log('down');
});
//# sourceMappingURL=1726136790617-tsx.js.map