From fbe754c87b23ecd843ca13700e48d8b0ad38e026 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Mon, 5 Jun 2023 16:24:19 +0600 Subject: [PATCH 1/6] Return returning per alias instead of array of returnings --- imports/client.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/imports/client.tsx b/imports/client.tsx index cf3ff3ba..c599945e 100644 --- a/imports/client.tsx +++ b/imports/client.tsx @@ -846,8 +846,12 @@ export class DeepClient> implements DeepClientInstance { if (!silent) throw e; return { ...result, data: (result)?.data?.m0?.returning, error: e }; } - // @ts-ignore - return { ...result, data: (result)?.data && Object.values((result)?.data).flatMap(m => m.returning)}; + + return { ...result, data: (result)?.data && Object.entries((result)?.data).reduce>((returningPerAlias, [alias, m]) => { + // @ts-ignore + returningPerAlias[alias] = m.returning; + return returningPerAlias + }, {})}; }; reserve(count: number): Promise { From a6054ec694fd3b3ca8cd6d6ef8be5ca24b833543 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Mon, 5 Jun 2023 19:01:46 +0600 Subject: [PATCH 2/6] Update tests to use resultAlias --- tests/client.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/client.tsx b/tests/client.tsx index 0ad22945..0e5bd25d 100644 --- a/tests/client.tsx +++ b/tests/client.tsx @@ -241,9 +241,11 @@ describe('client', () => { it('one insert', async () => { let linkIdsToDelete = []; const typeTypeLinkId = await deepClient.id("@deep-foundation/core", "Type"); + const resultAlias = "resultAlias"; const operation = createSerialOperation({ table: 'links', type: 'insert', + resultAlias, objects: { type_id: typeTypeLinkId } @@ -256,7 +258,7 @@ describe('client', () => { }); assert.equal(result.error, undefined); assert.notEqual(result.data, undefined); - linkIdsToDelete = [...linkIdsToDelete, ...result.data.map(link => link.id)]; + linkIdsToDelete = [...linkIdsToDelete, ...result.data[resultAlias].map(link => link.id)]; assert.strictEqual(result.data.length, 1); } finally { await deepClient.delete(linkIdsToDelete) @@ -265,9 +267,11 @@ describe('client', () => { it('multiple inserts in one operation', async () => { let linkIdsToDelete = []; const typeTypeLinkId = await deepClient.id("@deep-foundation/core", "Type"); + const resultAlias = "resultAlias"; const operation = createSerialOperation({ table: 'links', type: 'insert', + resultAlias, objects: { type_id: typeTypeLinkId } @@ -281,7 +285,7 @@ describe('client', () => { }); assert.equal(result.error, undefined); assert.notEqual(result.data, undefined); - linkIdsToDelete = [...linkIdsToDelete, ...result.data.map(link => link.id)]; + linkIdsToDelete = [...linkIdsToDelete, ...result.data[resultAlias].map(link => link.id)]; assert.strictEqual(result.data.length, 2); } finally { await deepClient.delete(linkIdsToDelete) @@ -290,9 +294,11 @@ describe('client', () => { it('multiple inserts ine multiple operations', async () => { let linkIdsToDelete = []; const typeTypeLinkId = await deepClient.id("@deep-foundation/core", "Type"); + const resultAlias = "resultAlias"; const operation = createSerialOperation({ table: 'links', type: 'insert', + resultAlias, objects: { type_id: typeTypeLinkId } @@ -307,7 +313,7 @@ describe('client', () => { inspect(result); assert.equal(result.error, undefined); assert.notEqual(result.data, undefined); - linkIdsToDelete = [...linkIdsToDelete, ...result.data.map(link => link.id)]; + linkIdsToDelete = [...linkIdsToDelete, ...result.data[resultAlias].map(link => link.id)]; assert.strictEqual(result.data.length, 2); } finally { await deepClient.delete(linkIdsToDelete) From 7ef42fa1194e71cd870d55888ef979a98d9d68f8 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Mon, 5 Jun 2023 19:02:20 +0600 Subject: [PATCH 3/6] Add result alias param --- imports/gql/serial.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/imports/gql/serial.ts b/imports/gql/serial.ts index faf3f571..1815a50f 100644 --- a/imports/gql/serial.ts +++ b/imports/gql/serial.ts @@ -59,6 +59,7 @@ export function createSerialOperation< >(params: { type: TSerialOperationType; table: TTable; + resultAlias?: string; } & SerialOperationDetails): SerialOperation { return params; } \ No newline at end of file From 07cdcc19f7814ebd3167a8491ff3205620e98d24 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Mon, 5 Jun 2023 19:02:39 +0600 Subject: [PATCH 4/6] Add result alias param --- imports/client.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/imports/client.tsx b/imports/client.tsx index c599945e..74884004 100644 --- a/imports/client.tsx +++ b/imports/client.tsx @@ -511,6 +511,7 @@ export type SerialOperation< > = { type: TSerialOperationType; table: TTable; + resultAlias?: string; } & SerialOperationDetails; export type DeepSerialOperation = SerialOperation> From b54f537953677603dca623a45687fb1bd2cf1690 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Mon, 5 Jun 2023 19:02:49 +0600 Subject: [PATCH 5/6] Update type of return value of serial --- imports/client.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imports/client.tsx b/imports/client.tsx index 74884004..2cbdaca0 100644 --- a/imports/client.tsx +++ b/imports/client.tsx @@ -790,7 +790,7 @@ export class DeepClient> implements DeepClientInstance { LL = L >({ name, operations, returning, silent - }: AsyncSerialParams): Promise> { + }: AsyncSerialParams): Promise>>> { // @ts-ignore let operationsGroupedByTypeAndTable: Record>> = {}; operationsGroupedByTypeAndTable = operations.reduce((acc, operation) => { From a48dc313a19c9a3bcd307f4746f03590e0d228f5 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Fri, 16 Jun 2023 15:45:29 +0600 Subject: [PATCH 6/6] Trigger workflow --- imports/client.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imports/client.tsx b/imports/client.tsx index 2cbdaca0..a480d6e4 100644 --- a/imports/client.tsx +++ b/imports/client.tsx @@ -2,7 +2,7 @@ import atob from 'atob'; import { gql, useQuery, useSubscription, useApolloClient } from '@apollo/client/index.js'; import type { ApolloQueryResult } from '@apollo/client/index.js'; import { generateApolloClient, IApolloClient } from '@deep-foundation/hasura/client.js'; -import { useLocalStore } from '@deep-foundation/store/local.js'; +import { useLocalStore } from '@deep-foundation/store/local.js'; import React, { createContext, useContext, useEffect, useMemo, useState } from "react"; import { deprecate, inherits, inspect } from "util"; import { deleteMutation, generateMutation, generateQuery, generateQueryData, generateSerial, IGenerateMutationBuilder, IGenerateMutationOptions, insertMutation, ISerialResult, updateMutation } from './gql/index.js'; @@ -1149,4 +1149,4 @@ export interface UseDeepSubscriptionResult> { data?: LL[]; error?: any; loading: boolean; -} \ No newline at end of file +}