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());
    });
};
export const permissions = (api, table, actions = {
    role: 'link',
    select: {},
    insert: {},
    update: {},
    delete: {},
    columns: '*',
    computed_fields: [],
}) => __awaiter(void 0, void 0, void 0, function* () {
    const columns = actions.columns || '*';
    const computed_fields = actions.computed_fields || [];
    yield api.metadata({
        type: 'pg_create_select_permission',
        args: {
            table: table,
            role: actions.role,
            permission: {
                columns: columns,
                computed_fields,
                filter: actions.select,
                limit: 999,
                allow_aggregations: true
            }
        }
    });
    yield api.query({
        type: 'create_insert_permission',
        args: {
            table: table,
            role: actions.role,
            permission: {
                check: actions.insert,
                columns: '*',
            }
        }
    });
    yield api.query({
        type: 'create_update_permission',
        args: {
            table: table,
            role: actions.role,
            permission: {
                columns: '*',
                filter: actions.update,
                check: {},
            }
        }
    });
    yield api.query({
        type: 'create_delete_permission',
        args: {
            table: table,
            role: actions.role,
            permission: {
                filter: actions.delete,
            }
        }
    });
});
//# sourceMappingURL=permission.js.map