Skip to content

Commit

Permalink
sync local codebase with git
Browse files Browse the repository at this point in the history
  • Loading branch information
thesophiaxu committed Sep 21, 2022
1 parent 8a10afb commit 1613443
Show file tree
Hide file tree
Showing 53 changed files with 1,259 additions and 3,479 deletions.
Expand Up @@ -249,7 +249,17 @@ const syncGoogleCalendarSpecific = async () => {
// });
// syncToken = undefined;

const { items, nextSyncToken } = await sync(calendar, unigraphCalendar, syncToken);
let syncResults;
try {
syncResults = await sync(calendar, unigraphCalendar, syncToken);
} catch (e) {
if (e.message?.includes('Sync token is no longer valid')) {
console.log('Getting a new token...');
syncResults = await sync(calendar, unigraphCalendar, undefined);
}
}

const { items, nextSyncToken } = syncResults;
// const { items, nextSyncToken } = await syncDebug(calendar, unigraphCalendar, syncToken);
// console.log('items', { itemsLen: items.length, calendarName });

Expand Down
@@ -1,6 +1,25 @@
const { data, callbacks, inline } = params;
const name = data?.get('name')?.as('primitive');
console.log(data.get('emails'));

const profiles = data
?.get('profiles')
?.map((pf) => pf.as('subentity'))
?.map((el) => unigraph.getNamespaceMap()[el.type['unigraph.id']]?._icon)
?.filter(Boolean)
?.map((el) => (
<span
style={{
minWidth: '16px',
minHeight: '16px',
width: '16px',
height: '16px',
display: 'inline-block',
marginRight: '2px',
backgroundImage: `url("data:image/svg+xml,${el}")`,
opacity: 0.54,
}}
/>
));

if (inline)
return (
Expand All @@ -19,11 +38,14 @@ return (
/>
</ListItemIcon>
<ListItemText>
<Typography>{name || data._value.emails['_value['][0]['_value.%']}</Typography>
<Typography>
{name || data._value.emails['_value['][0]['_value.%']}
{profiles ? <span style={{ display: 'inline-block', marginLeft: '8px' }}>{profiles}</span> : undefined}
</Typography>
<div style={{ display: 'inline', alignItems: 'center', overflowWrap: 'break-word', color: 'gray' }}>
{data?._value?.children?.['_value[']?.map ? (
{data?.get('children')?.map ? (
<div style={{ display: 'inline', marginRight: '8px' }}>
{data._value.children['_value['].map((it) => (
{data.get('children').map((it) => (
<AutoDynamicView
object={new UnigraphObject(it._value)}
callbacks={callbacks}
Expand Down
Expand Up @@ -8,7 +8,8 @@ ${data._value.selftext._value._value['_value.%']}
Subreddit: r/${data._value.subreddit._value._value.name['_value.%']}
Subreddit description: ${new UnigraphObject(data).get('subreddit/description')?.as('primitive')}`,
'$/schema/web_bookmark': (data) => `Title: ${new UnigraphObject(data).get('name')?.as('primitive')}
Abstract: ${new UnigraphObject(data).get('creative_work/abstract')?.as('primitive')}`,
Abstract: ${new UnigraphObject(data).get('creative_work/abstract')?.as('primitive')}
Content: ${new UnigraphObject(data).get('creative_work/text')?.as('primitive')}`,
'$/schema/youtube_video': (data) => `YouTube video: ${new UnigraphObject(data).get('title')?.as('primitive')}
Description: ${new UnigraphObject(data).get('description')?.as('primitive')}
Channel: ${new UnigraphObject(data).get('channel/name')?.as('primitive')}`,
Expand Down Expand Up @@ -41,6 +42,19 @@ ${text}`;
`Tag: ${new UnigraphObject(data).get('name')?.as('primitive')}, description: ${new UnigraphObject(data)
.get('description')
?.as('primitive')}`,
'$/schema/todo': (data) => {
const name = new UnigraphObject(data).get('name')?.as('primitive');
const tags = (new UnigraphObject(data).get('children')?.['_value['] || [])
.filter(
(el) =>
el?._value?.type?.['unigraph.id'] === '$/schema/interface/semantic' &&
el?._value?._value?.type?.['unigraph.id'] === '$/schema/tag',
)
.map((el) => new UnigraphObject(el._value._value).get('name')?.as('primitive'))
.filter((el) => el?.length)
.map((el) => `#${el}`);
return `Todo item: ${name}${tags.length ? `\nTags: ${tags.join(', ')}` : ``}`;
},
};

let data = objects;
Expand Down
17 changes: 15 additions & 2 deletions packages/unigraph-dev-backend/src/datamodelManager.ts
Expand Up @@ -7,7 +7,11 @@

import { insertsToUpsert } from 'unigraph-dev-common/lib/utils/txnWrapper';
import { ComposerUnionInstance } from 'unigraph-dev-common/lib/types/json-ts';
import { buildGraphFromMap, processAutorefUnigraphId } from 'unigraph-dev-common/lib/utils/entityUtils';
import {
buildGraphFromMap,
makeQueryFragmentFromType,
processAutorefUnigraphId,
} from 'unigraph-dev-common/lib/utils/entityUtils';
import { Cache } from './caches';
import { defaultPackages, defaultTypes, defaultUserlandSchemas } from './templates/defaultDb';
import DgraphClient from './dgraphClient';
Expand Down Expand Up @@ -91,7 +95,7 @@ export async function checkOrCreateDefaultDataModel(client: DgraphClient) {
export function createSchemaCache(client: DgraphClient): Cache<any> {
const cache: Cache<any> = {
data: {},
dataAlt: [{}],
dataAlt: [{}, {}],
updateNow: async () => null,
cacheType: 'manual',
subscribe: (listener) => null,
Expand Down Expand Up @@ -140,6 +144,15 @@ export function createSchemaCache(client: DgraphClient): Cache<any> {
}
});
cache.data = buildGraphFromMap(cache.data);

const t = new Date().getTime();
cache.dataAlt![1] = Object.fromEntries(
Object.keys(cache.data).map((schemaName) => [
schemaName,
makeQueryFragmentFromType(schemaName, cache.data),
]),
);
console.log(`Building query templates took ${new Date().getTime() - t} ms.`);
};

cache.updateNow();
Expand Down
3 changes: 1 addition & 2 deletions packages/unigraph-dev-backend/src/localUnigraphApi.ts
Expand Up @@ -7,7 +7,6 @@ import { buildGraph, getCircularReplacer, getRandomInt } from 'unigraph-dev-comm
import { Unigraph } from 'unigraph-dev-common/lib/types/unigraph';
import {
processAutorefUnigraphId,
makeQueryFragmentFromType,
clearEmpties,
buildUnigraphEntity,
processAutoref,
Expand Down Expand Up @@ -158,7 +157,7 @@ export function getLocalUnigraphAPI(
name === 'any'
? queryAny
: `query {entities(func: uid(par${eventId}))
${makeQueryFragmentFromType(name, states.caches.schemas.data)}
${states.caches.schemas.dataAlt?.[1][name]}
par${eventId} as var(func: has(type)) @filter((NOT type(Deleted)) AND type(Entity)) @cascade {
type @filter(eq(<unigraph.id>, "${name}"))
}}`;
Expand Down
7 changes: 3 additions & 4 deletions packages/unigraph-dev-backend/src/subscriptions.ts
Expand Up @@ -2,8 +2,7 @@
import _ from 'lodash';
import stringify from 'json-stable-stringify';
import { Query, QueryObject, QueryType } from 'unigraph-dev-common/lib/types/unigraph';
import { buildGraph, getCircularReplacer, getRandomId, getRandomInt } from 'unigraph-dev-common/lib/utils/utils';
import { makeQueryFragmentFromType } from 'unigraph-dev-common/lib/utils/entityUtils';
import { getCircularReplacer, getRandomId, getRandomInt } from 'unigraph-dev-common/lib/utils/utils';
import { buildExecutable } from './executableManager';
import DgraphClient, { queries } from './dgraphClient';
import { IWebsocket, Subscription } from './custom.d';
Expand Down Expand Up @@ -46,7 +45,7 @@ export function getFragment(query: Query, states: any) {
? '@recurse { uid <unigraph.id> expand(_userpredicate_) } '
: metadataOnly
? ' { uid <dgraph.type> type { <unigraph.id> } _updatedAt _createdAt _hide } '
: queryAs || makeQueryFragmentFromType(query.name, states.caches.schemas.data, depth)
: queryAs || states.caches.schemas.dataAlt[1]?.[query.name]
}
var(func: eq(<unigraph.id>, "${query.name}")) {
<~type> {
Expand All @@ -64,7 +63,7 @@ export function getFragment(query: Query, states: any) {
uid = uid.map((u: any) => (typeof u === 'string' && u.startsWith('$/') ? states.namespaceMap[u].uid : u));
}
const queryBody = options?.queryAsType
? makeQueryFragmentFromType(options.queryAsType, states.caches.schemas.data, options?.depth)
? states.caches.schemas.dataAlt[1]?.[options.queryAsType]
: `@recurse${
options?.depth ? `(depth: ${options?.depth})` : ''
} { uid unigraph.id unigraph.indexes expand(_userpredicate_) }`;
Expand Down
1 change: 1 addition & 0 deletions packages/unigraph-dev-common/src/utils/entityUtils.ts
Expand Up @@ -515,6 +515,7 @@ export function makeQueryFragmentFromType(
'<_value[>': {
...makePart(localSchema._parameters._element, depth + 1),
'<_index>': { '<_value.#i>': {}, '<_value.#>': {} },
'<_key>': {},
},
},
);
Expand Down
34 changes: 34 additions & 0 deletions packages/unigraph-dev-common/src/utils/utils.ts
Expand Up @@ -253,13 +253,33 @@ function getObjectAsRecursivePrimitive(object: any, getRef?: boolean) {
return targetValue;
}

function getObjectAsRecursiveSubentity(object: any, getRef?: boolean) {
let targetValue: any;
if (object?.type?.['unigraph.id'] === '$/schema/subentity' && object._value) {
targetValue = getRef ? object : object._value;
} else
Object.keys(object).forEach((el) => {
if (el === '_value' && typeof object[el] === 'object') {
const subObj = getObjectAsRecursiveSubentity(object[el], getRef);
if (subObj !== undefined) targetValue = subObj;
}
});
return targetValue;
}

export const getObjectAs = (object: any, type: 'primitive') => {
if (type === 'primitive') {
return getObjectAsRecursivePrimitive(object);
}
if (type === 'primitiveRef') {
return getObjectAsRecursivePrimitive(object, true);
}
if (type === 'subentity') {
return getObjectAsRecursiveSubentity(object);
}
if (type === 'subentityRef') {
return getObjectAsRecursiveSubentity(object, true);
}
return object;
};

Expand All @@ -281,6 +301,20 @@ export class UnigraphObject extends Object {
}
};

map = (fn: any) => {
if (Array.isArray((this as any)?.['_value['])) {
return (this as any)['_value['].map((el: any) => fn(new UnigraphObject(el)));
}
return undefined;
};

forEach = (fn: any) => {
if (Array.isArray((this as any)?.['_value['])) {
return (this as any)['_value['].forEach((el: any) => fn(new UnigraphObject(el)));
}
return undefined;
};

// eslint-disable-next-line class-methods-use-this
getMetadata = () => undefined;

Expand Down
2 changes: 1 addition & 1 deletion packages/unigraph-dev-electron/src/preload.js
Expand Up @@ -18,7 +18,7 @@ window.electronPreload = () => {
ipcRenderer.send('favorites_updated', newFavs);
});
ipcRenderer.on('newTab', (event, tab) => {
window.newTab(window.layoutModel, {
window.newTab({
type: 'tab',
config: tab.config,
name: tab.name,
Expand Down
2 changes: 1 addition & 1 deletion packages/unigraph-dev-explorer/package.json
Expand Up @@ -72,7 +72,7 @@
"react-image-gallery": "^1.2.8",
"react-infinite-scroll-component": "^6.1.0",
"react-json-view": "^1.20.2",
"react-markdown": "^6.0.2",
"react-markdown": "^8.0.3",
"react-player": "^2.10.1",
"react-refresh": "^0.8.3",
"react-resize-detector": "^6.7.6",
Expand Down

0 comments on commit 1613443

Please sign in to comment.