Skip to content

Commit

Permalink
0.0.616
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansglazunov committed Oct 10, 2024
1 parent 009509f commit b3a3e08
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
10 changes: 9 additions & 1 deletion imports/bool_exp_to_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ const deep = new DeepClient({

export const itemReplaceSymbol = 777777777777;
export const userReplaceSymbol = 777777777778;
export const fromReplaceSymbol = 777777777779;
export const toReplaceSymbol = 777777777780;
export const typeReplaceSymbol = 777777777781;
export const itemPublicSymbol = 'X-Deep-Item-Id';
export const userPublicSymbol = 'X-Deep-User-Id';
export const fromPublicSymbol = 'X-Deep-From-Id';
export const toPublicSymbol = 'X-Deep-To-Id';
export const typePublicSymbol = 'X-Deep-Type-Id';

export const applyBoolExpToLink = (sql: string, linkId: Id) => {
return sql.replace(`${itemReplaceSymbol}`, `${linkId}`);
Expand All @@ -48,7 +54,9 @@ export const boolExpToSQL = async (boolExpId: Id, boolExpValue: any) => {
gql = gql.replace(new RegExp(`'${userPublicSymbol}'`, 'g'), userReplaceSymbol);
gql = gql.replace(new RegExp(`"${userPublicSymbol}"`, 'g'), userReplaceSymbol);
gql = gql.replace(new RegExp(`'${itemPublicSymbol}'`, 'g'), itemReplaceSymbol);
gql = gql.replace(new RegExp(`"${itemPublicSymbol}"`, 'g'), itemReplaceSymbol);
gql = gql.replace(new RegExp(`"${fromPublicSymbol}"`, 'g'), fromReplaceSymbol);
gql = gql.replace(new RegExp(`"${toPublicSymbol}"`, 'g'), toReplaceSymbol);
gql = gql.replace(new RegExp(`"${typePublicSymbol}"`, 'g'), typeReplaceSymbol);
explained = await api.explain(`{ links(where: { _and: [{ id: { _eq: ${itemReplaceSymbol} } }, ${gql}] }, limit: 1) { id } }`);
sql = explained?.data?.[0]?.sql;
if (sql) {
Expand Down
10 changes: 8 additions & 2 deletions migrations/1622421760258-selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generateApolloClient } from '@deep-foundation/hasura/client.js';
import { sql } from '@deep-foundation/hasura/sql.js';
import Debug from 'debug';
import { itemReplaceSymbol, userReplaceSymbol } from '../imports/bool_exp_to_sql.js';
import { fromReplaceSymbol, itemReplaceSymbol, toReplaceSymbol, typeReplaceSymbol, userReplaceSymbol } from '../imports/bool_exp_to_sql.js';
import { DeepClient, _ids } from '../imports/client.js';
import { api, SCHEMA } from './1616701513782-links.js';
import { MP_TABLE_NAME } from './1621815803572-materialized-path.js';
Expand Down Expand Up @@ -63,17 +63,23 @@ export const up = async () => {
await api.sql(sql`
CREATE OR REPLACE FUNCTION bool_exp_execute(target_link_id bigint, bool_exp_link_id bigint, user_id bigint) RETURNS BOOL AS $trigger$ DECLARE
boolExp RECORD;
link RECORD;
sqlResult INT;
query TEXT;
BEGIN
SELECT be.* into boolExp
FROM "${BOOL_EXP_TABLE_NAME}" as be
WHERE be.link_id=bool_exp_link_id;
SELECT * into link
FROM "links"
WHERE id=target_link_id;
IF boolExp IS NOT NULL THEN
IF (user_id IS NULL) THEN
user_id := ${_ids?.['@deep-foundation/core']?.Any};
END IF;
SELECT REPLACE(REPLACE(boolExp.value, ${itemReplaceSymbol}::text, target_link_id::text), ${userReplaceSymbol}::text, user_id::text) INTO query;
SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(boolExp.value, ${itemReplaceSymbol}::text, target_link_id::text), ${userReplaceSymbol}::text, user_id::text), ${fromReplaceSymbol}::text, user_id::text), ${toReplaceSymbol}::text, user_id::text), ${typeReplaceSymbol}::text, user_id::text) INTO query;
EXECUTE query INTO sqlResult;
IF sqlResult = 0 THEN
RETURN FALSE;
Expand Down
1 change: 0 additions & 1 deletion migrations/1622421760260-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const log = debug.extend('log');
const error = debug.extend('error');

export const TABLE_NAME = 'links';
export const REPLACE_PATTERN_ID = '777777777777';

const client = generateApolloClient({
path: `${process.env.MIGRATIONS_HASURA_PATH}/v1/graphql`,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deep-foundation/deeplinks",
"version": "0.0.615",
"version": "0.0.616",
"license": "Unlicense",
"type": "module",
"main": "import.js",
Expand Down

0 comments on commit b3a3e08

Please sign in to comment.