diff --git a/packages/default-packages/unigraph.calendar/executables/syncGoogleCalendar.js b/packages/default-packages/unigraph.calendar/executables/syncGoogleCalendar.js index f0f42688..06a17d07 100644 --- a/packages/default-packages/unigraph.calendar/executables/syncGoogleCalendar.js +++ b/packages/default-packages/unigraph.calendar/executables/syncGoogleCalendar.js @@ -46,7 +46,7 @@ if (account?.uid) { await unigraph.updateObject(account.uid, { access_token: token, token_expires_in: (new Date((new Date()).getTime() + 3600 * 1000)).toISOString() - }); + }, undefined, undefined, []); let auth = new google.auth.OAuth2( gmailClientId, @@ -69,8 +69,8 @@ if (account?.uid) { name: {type: {"unigraph.id": "$/schema/markdown"}, _value: cal.summary} } }); + const uids = await unigraph.addObject(calObjs, '$/schema/calendar', undefined, []); for (let i=0; i { // Process the changes, looping through all the events one by one //if (cal['_value'].id?.['_value.%'] !== "c_5le2cv45o72utfkh4bcntpj2f4@group.calendar.google.com") return; - +const toAdd = []; for (let i=0; i { + addObject: async (object, schema, padded, subIds) => { clearEmpties(object); //console.log(JSON.stringify(object, null, 4)); const objects = Array.isArray(object) ? object : [object]; + if (objects.length === 0) return []; const finalUnigraphObjects = objects.map((obj, index) => { let unigraphObject = obj; if (!padded) unigraphObject = buildUnigraphEntity(obj, schema, states.caches['schemas'].data, undefined, {globalStates: {nextUid: 100000 * index}} as any); @@ -96,7 +97,7 @@ export function getLocalUnigraphAPI(client: DgraphClient, states: {caches: Recor //console.log(JSON.stringify(finalUnigraphObject, null, 4)); const upsert = insertsToUpsert(finalUnigraphObjects, undefined, states.caches['schemas'].dataAlt![0]); const uids = await client.createUnigraphUpsert(upsert); - callHooks(states.hooks, "after_object_changed", {subscriptions: states.subscriptions, caches: states.caches}); + callHooks(states.hooks, "after_object_changed", {subscriptions: states.subscriptions, caches: states.caches, subIds}); return uids; }, getNamespaceMapUid: (name) => { diff --git a/packages/unigraph-dev-common/src/types/unigraph.ts b/packages/unigraph-dev-common/src/types/unigraph.ts index bf4e90d7..f399ab26 100644 --- a/packages/unigraph-dev-common/src/types/unigraph.ts +++ b/packages/unigraph-dev-common/src/types/unigraph.ts @@ -144,7 +144,7 @@ export interface Unigraph { * @param object The object to be added. * @param schema Schema of that object, must be valid. Such as: `$/schema/abc` */ - addObject(object: any, schema: string, padded?: boolean): any; + addObject(object: any, schema: string, padded?: boolean, subIds?: any[]): any; /** * Reach into the namespace map cache and get a UID corresponding to the name. *