Skip to content

Commit 5aa6188

Browse files
2 parents 5aed341 + dab1171 commit 5aa6188

File tree

7 files changed

+286
-4
lines changed

7 files changed

+286
-4
lines changed

automation/remove-build-files.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import glob from "glob";
2+
import fs from "fs-extra";
3+
4+
const options = {
5+
ignore: "**/node_modules/**",
6+
nodir: true,
7+
};
8+
9+
glob("./**/*.{d.ts,js,js.map}", options, (err, files) => {
10+
if (err) {
11+
console.log(err);
12+
return;
13+
}
14+
15+
files.forEach((file) => {
16+
fs.remove(file, (err) => {
17+
if (err) console.error(`Failed to remove ${file}:`, err);
18+
else console.log(`Successfully removed ${file}`);
19+
});
20+
});
21+
});

imports/client.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const serializeWhere = (exp: any, env: string = 'links'): any => {
152152
for (let k = 0; k < keys.length; k++) {
153153
const key = keys[k];
154154
const type = typeof(exp[key]);
155-
if (typeof(exp[key]) === 'undefined') throw new Error(`value of key "${key}" can't be undefined`);
155+
if (typeof(exp[key]) === 'undefined') throw new Error(`${key} === undefined`);
156156
let setted: any = false;
157157
const is_id_field = !!~['type_id', 'from_id', 'to_id'].indexOf(key);
158158
// if this is link
@@ -171,6 +171,15 @@ export const serializeWhere = (exp: any, env: string = 'links'): any => {
171171
// @ts-ignore
172172
setted = result[key] = serializeWhere(pathToWhere(...exp[key]));
173173
}
174+
} else if (env === 'tree') {
175+
// if field contain primitive type - string/number
176+
if (type === 'string' || type === 'number') {
177+
setted = result[key] = { _eq: exp[key] };
178+
} else if (!_boolExpFields[key] && Object.prototype.toString.call(exp[key]) === '[object Array]') {
179+
// if field is not boolExp (_and _or _not) but contain array
180+
// @ts-ignore
181+
setted = result[key] = serializeWhere(pathToWhere(...exp[key]));
182+
}
174183
} else if (env === 'value') {
175184
// if this is value
176185
if (type === 'string' || type === 'number') {

imports/react-token.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export function useTokenController() {
99
export function TokenProvider({ children }: { children?: any }) {
1010
const [token, setToken] = useTokenController();
1111
// console.log('TokenProvider', { token });
12+
// @ts-ignore
1213
return <TokenContext.Provider value={token}>{children}</TokenContext.Provider>;
1314
}

migrations/1655979260869-sync-handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ const deepFabric = /*javascript*/`(ownerId, hasura_session) => {
452452
const linkid = plv8.execute(insertLinkString)[0]?.id;
453453
const linkCheck = checkInsertPermission(linkid, ownerId);
454454
if (!linkCheck) plv8.elog(ERROR, 'Insert not permitted');
455-
const value = number || string || object;
455+
if (object && typeof object !== 'object') plv8.elog(ERROR, 'inserting value is not object');
456+
const value = number || string || JSON.stringify(object);
456457
if (!value) return { data: [{ id: linkid }]};
457458
const insertValueString = ${insertValueStringCode};
458459
const valueId = plv8.execute(insertValueString)[0]?.id;

package-lock.json

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deep-foundation/deeplinks",
3-
"version": "0.0.189",
3+
"version": "0.0.192",
44
"license": "Unlicense",
55
"type": "module",
66
"scripts": {
@@ -56,6 +56,7 @@
5656
"debug": "^4.3.4",
5757
"dotenv": "^16.0.3",
5858
"fix-path": "^4.0.0",
59+
"fs-extra": "^11.1.1",
5960
"get-port": "^5.1.1",
6061
"gists": "^2.0.0",
6162
"graphql": "^15.8.0",

tests/sync-handlers.ts

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,5 +2009,230 @@ describe('sync handlers', () => {
20092009
}
20102010
});
20112011
});
2012+
describe('Handle IUD for values', () => {
2013+
it('Handle IUD for strings', async () => {
2014+
const debug = log.extend('HandleIUDStrings');
2015+
2016+
const typeId = await deep.id('@deep-foundation/core', 'Operation');
2017+
const handleInsertId = await deep.id('@deep-foundation/core', 'HandleInsert');
2018+
const handleUpdateId = await deep.id('@deep-foundation/core', 'HandleUpdate');
2019+
const supportsId = await deep.id('@deep-foundation/core', 'plv8SupportsJs');
2020+
2021+
const anyTypeId = await deep.id('@deep-foundation/core', 'Any');
2022+
const typeToHandle = await deep.insert({type_id: 1, from_id: anyTypeId, to_id: anyTypeId});
2023+
const typeToInsertInHandler = await deep.insert({type_id: 1, from_id: anyTypeId, to_id: anyTypeId});
2024+
const typeIdToInsertInHandler = typeToInsertInHandler?.data?.[0]?.id;
2025+
const typeIdToHandle = typeToHandle?.data?.[0]?.id;
2026+
debug('typeIdToHandle', typeIdToHandle);
2027+
2028+
const onInsertHandler = await insertHandler(
2029+
handleInsertId,
2030+
typeIdToHandle,
2031+
`({deep, data}) => {
2032+
const inserted = deep.insert({type_id: ${typeIdToInsertInHandler}, to_id: ${typeIdToInsertInHandler}, from_id: ${typeIdToInsertInHandler}, string: 'HelloBugFixers'});
2033+
deep.update({link_id: inserted.data[0].id}, { value: 'GoodbyeBugFixers'}, { table: 'strings' });
2034+
}`.trim(),
2035+
undefined,
2036+
supportsId
2037+
);
2038+
debug('onInsertHandler', onInsertHandler);
2039+
2040+
try {
2041+
const linkId = (await deep.insert({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle } ))?.data?.[0].id;
2042+
debug('linkId', linkId);
2043+
const insertedLink = await deep.select(linkId);
2044+
debug('insertedLink', insertedLink?.data);
2045+
} catch (e){
2046+
debug('insert error: ', e);
2047+
}
2048+
2049+
const insertedByHandler = await deep.select({ type_id: { _eq: typeIdToInsertInHandler }, to_id: { _eq: typeIdToInsertInHandler }, from_id: { _eq: typeIdToInsertInHandler } });
2050+
const insertedByHandlerId = insertedByHandler.data[0].id;
2051+
debug('insertedByHandler', insertedByHandler?.data);
2052+
const value = insertedByHandler?.data?.[0]?.value;
2053+
assert.equal(value?.value, 'GoodbyeBugFixers');
2054+
debug('delete insert handler', await deleteHandler(onInsertHandler));
2055+
2056+
const onUpdateHandler = await insertHandler(
2057+
handleUpdateId,
2058+
typeIdToHandle,
2059+
`({deep, data}) => {
2060+
deep.delete({link_id: ${insertedByHandlerId}}, { table: 'strings' });
2061+
}`.trim(),
2062+
undefined,
2063+
supportsId
2064+
);
2065+
debug('onUpdateHandler', onUpdateHandler);
2066+
2067+
try {
2068+
const linkId = (await deep.select({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle }))?.data?.[0].id;
2069+
await deep.update({ link_id: linkId }, { value: 'TERMINATING'}, { table: 'strings' } );
2070+
debug('linkId', linkId);
2071+
2072+
const linkWithoutValue = await deep.select({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle });
2073+
const value = linkWithoutValue?.data?.[0]?.value;
2074+
debug('value', value);
2075+
assert.equal(value?.value, undefined);
2076+
2077+
const deletedLink = await deep.select(linkId);
2078+
debug('delete linkid', await deep.delete({ id: { _eq: linkId } }));
2079+
2080+
} catch (e){
2081+
debug('insert error: ', e);
2082+
}
2083+
2084+
debug('delete update handler', await deleteHandler(onUpdateHandler));
2085+
});
2086+
it('Handle IUD for numbers', async () => {
2087+
const debug = log.extend('HandleIUDStrings');
2088+
2089+
const typeId = await deep.id('@deep-foundation/core', 'Operation');
2090+
const handleInsertId = await deep.id('@deep-foundation/core', 'HandleInsert');
2091+
const handleUpdateId = await deep.id('@deep-foundation/core', 'HandleUpdate');
2092+
const supportsId = await deep.id('@deep-foundation/core', 'plv8SupportsJs');
2093+
2094+
const anyTypeId = await deep.id('@deep-foundation/core', 'Any');
2095+
const typeToHandle = await deep.insert({type_id: 1, from_id: anyTypeId, to_id: anyTypeId});
2096+
const typeToInsertInHandler = await deep.insert({type_id: 1, from_id: anyTypeId, to_id: anyTypeId});
2097+
const typeIdToInsertInHandler = typeToInsertInHandler?.data?.[0]?.id;
2098+
const typeIdToHandle = typeToHandle?.data?.[0]?.id;
2099+
debug('typeIdToHandle', typeIdToHandle);
2100+
2101+
const onInsertHandler = await insertHandler(
2102+
handleInsertId,
2103+
typeIdToHandle,
2104+
`({deep, data}) => {
2105+
const inserted = deep.insert({type_id: ${typeIdToInsertInHandler}, to_id: ${typeIdToInsertInHandler}, from_id: ${typeIdToInsertInHandler}, number: 1});
2106+
deep.update({link_id: inserted.data[0].id}, { value: 2 }, { table: 'numbers' });
2107+
}`.trim(),
2108+
undefined,
2109+
supportsId
2110+
);
2111+
debug('onInsertHandler', onInsertHandler);
2112+
2113+
try {
2114+
const linkId = (await deep.insert({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle } ))?.data?.[0].id;
2115+
debug('linkId', linkId);
2116+
const insertedLink = await deep.select(linkId);
2117+
debug('insertedLink', insertedLink?.data);
2118+
} catch (e){
2119+
debug('insert error: ', e);
2120+
}
2121+
2122+
const insertedByHandler = await deep.select({ type_id: { _eq: typeIdToInsertInHandler }, to_id: { _eq: typeIdToInsertInHandler }, from_id: { _eq: typeIdToInsertInHandler } });
2123+
const insertedByHandlerId = insertedByHandler.data[0].id;
2124+
debug('insertedByHandler', insertedByHandler?.data);
2125+
const value = insertedByHandler?.data?.[0]?.value;
2126+
assert.equal(value?.value, 2);
2127+
debug('delete insert handler', await deleteHandler(onInsertHandler));
2128+
2129+
const onUpdateHandler = await insertHandler(
2130+
handleUpdateId,
2131+
typeIdToHandle,
2132+
`({deep, data}) => {
2133+
deep.delete({link_id: ${insertedByHandlerId}}, { table: 'numbers' });
2134+
}`.trim(),
2135+
undefined,
2136+
supportsId
2137+
);
2138+
debug('onUpdateHandler', onUpdateHandler);
2139+
2140+
try {
2141+
const linkId = (await deep.select({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle }))?.data?.[0].id;
2142+
await deep.update({ link_id: linkId }, { value: 3}, { table: 'numbers' } );
2143+
debug('linkId', linkId);
2144+
2145+
const linkWithoutValue = await deep.select({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle });
2146+
const value = linkWithoutValue?.data?.[0]?.value;
2147+
debug('value', value);
2148+
assert.equal(value?.value, undefined);
2149+
2150+
const deletedLink = await deep.select(linkId);
2151+
debug('delete linkid', await deep.delete({ id: { _eq: linkId } }));
2152+
2153+
} catch (e){
2154+
debug('insert error: ', e);
2155+
}
2156+
2157+
debug('delete update handler', await deleteHandler(onUpdateHandler));
2158+
});
2159+
it('Handle IUD for object', async () => {
2160+
const debug = log.extend('HandleIUDStrings');
2161+
2162+
const typeId = await deep.id('@deep-foundation/core', 'Operation');
2163+
const handleInsertId = await deep.id('@deep-foundation/core', 'HandleInsert');
2164+
const handleUpdateId = await deep.id('@deep-foundation/core', 'HandleUpdate');
2165+
const supportsId = await deep.id('@deep-foundation/core', 'plv8SupportsJs');
2166+
2167+
const anyTypeId = await deep.id('@deep-foundation/core', 'Any');
2168+
const typeToHandle = await deep.insert({type_id: 1, from_id: anyTypeId, to_id: anyTypeId});
2169+
const typeToInsertInHandler = await deep.insert({type_id: 1, from_id: anyTypeId, to_id: anyTypeId});
2170+
const typeIdToInsertInHandler = typeToInsertInHandler?.data?.[0]?.id;
2171+
const typeIdToHandle = typeToHandle?.data?.[0]?.id;
2172+
debug('typeIdToHandle', typeIdToHandle);
2173+
2174+
const onInsertHandler = await insertHandler(
2175+
handleInsertId,
2176+
typeIdToHandle,
2177+
`({deep, data}) => {
2178+
const inserted = deep.insert({
2179+
type_id: ${typeIdToInsertInHandler},
2180+
to_id: ${typeIdToInsertInHandler},
2181+
from_id: ${typeIdToInsertInHandler},
2182+
object: { string: 'HelloBugFixers' }
2183+
});
2184+
}`.trim(),
2185+
undefined,
2186+
supportsId
2187+
);
2188+
debug('onInsertHandler', onInsertHandler);
2189+
2190+
try {
2191+
const linkId = (await deep.insert({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle } ))?.data?.[0].id;
2192+
debug('linkId', linkId);
2193+
const insertedLink = await deep.select(linkId);
2194+
debug('insertedLink', insertedLink?.data);
2195+
} catch (e){
2196+
debug('insert error: ', e);
2197+
}
2198+
2199+
const insertedByHandler = await deep.select({ type_id: { _eq: typeIdToInsertInHandler }, to_id: { _eq: typeIdToInsertInHandler }, from_id: { _eq: typeIdToInsertInHandler } });
2200+
const insertedByHandlerId = insertedByHandler.data[0].id;
2201+
debug('insertedByHandler', insertedByHandler?.data);
2202+
const value = insertedByHandler?.data?.[0]?.value;
2203+
assert.equal(value?.value?.string, 'HelloBugFixers');
2204+
debug('delete insert handler', await deleteHandler(onInsertHandler));
2205+
2206+
const onUpdateHandler = await insertHandler(
2207+
handleUpdateId,
2208+
typeIdToHandle,
2209+
`({deep, data}) => {
2210+
deep.delete({link_id: ${insertedByHandlerId}}, { table: 'objects' });
2211+
}`.trim(),
2212+
undefined,
2213+
supportsId
2214+
);
2215+
debug('onUpdateHandler', onUpdateHandler);
2216+
2217+
try {
2218+
const linkId = (await deep.select({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle }))?.data?.[0].id;
2219+
await deep.update({ link_id: linkId }, { value: { string: 'TERMINATING' }}, { table: 'objects' } );
2220+
debug('linkId', linkId);
2221+
2222+
const linkWithoutValue = await deep.select({ type_id: typeIdToHandle, to_id: typeIdToHandle, from_id: typeIdToHandle });
2223+
const value = linkWithoutValue?.data?.[0]?.value;
2224+
debug('value', value);
2225+
assert.equal(value?.value, undefined);
2226+
2227+
const deletedLink = await deep.select(linkId);
2228+
debug('delete linkid', await deep.delete({ id: { _eq: linkId } }));
2229+
2230+
} catch (e){
2231+
debug('insert error: ', e);
2232+
}
2233+
2234+
debug('delete update handler', await deleteHandler(onUpdateHandler));
2235+
});
2236+
});
20122237
});
20132238
});

0 commit comments

Comments
 (0)