Skip to content

Commit

Permalink
chore(weave): add obj create and table update bindings to wf react in…
Browse files Browse the repository at this point in the history
…terface
  • Loading branch information
bcsherma committed Jan 7, 2025
1 parent fb3e3a7 commit 063e8c1
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
FeedbackCreateRes,
FeedbackPurgeReq,
FeedbackPurgeRes,
TableUpdateReq,
TableUpdateRes,
TraceCallsDeleteReq,
TraceCallUpdateReq,
TraceObjCreateReq,
Expand Down Expand Up @@ -115,6 +117,10 @@ export class TraceServerClient extends CachingTraceServerClient {
return res;
}

public tableUpdate(req: TableUpdateReq): Promise<TableUpdateRes> {
return super.tableUpdate(req);
}

public feedbackCreate(req: FeedbackCreateReq): Promise<FeedbackCreateRes> {
const res = super.feedbackCreate(req).then(createRes => {
const listeners = this.onFeedbackListeners[req.weave_ref] ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,35 @@ export type ActionsExecuteBatchReq = {
};

export type ActionsExecuteBatchRes = {};

export type TableUpdateSpec = TableAppendSpec | TablePopSpec | TableInsertSpec;

export interface TableAppendSpec {
append: {
row: Record<string, any>;
};
}

export interface TablePopSpec {
pop: {
index: number;
};
}

export interface TableInsertSpec {
insert: {
index: number;
row: Record<string, any>;
};
}

export type TableUpdateReq = {
project_id: string;
base_digest: string;
updates: TableUpdateSpec[];
};

export type TableUpdateRes = {
digest: string;
updated_row_digests: string[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
FeedbackPurgeRes,
FeedbackQueryReq,
FeedbackQueryRes,
TableUpdateReq,
TableUpdateRes,
TraceCallReadReq,
TraceCallReadRes,
TraceCallSchema,
Expand Down Expand Up @@ -253,6 +255,13 @@ export class DirectTraceServerClient {
);
}

public tableUpdate(req: TableUpdateReq): Promise<TableUpdateRes> {
return this.makeRequest<TableUpdateReq, TableUpdateRes>(
'/table/update',
req
);
}

public tableQuery(req: TraceTableQueryReq): Promise<TraceTableQueryRes> {
return this.makeRequest<TraceTableQueryReq, TraceTableQueryRes>(
'/table/query',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1713,21 +1713,75 @@ export const traceCallToUICallSchema = (
};
};

export const useObjCreate = (): ((
projectId: string,
objectId: string,
val: any,
baseObjectClass?: string
) => Promise<string>) => {
const getTsClient = useGetTraceServerClientContext();

return useCallback(
(
projectId: string,
objectId: string,
val: any,
baseObjectClass?: string
) => {
return getTsClient()
.objCreate({
obj: {
project_id: projectId,
object_id: objectId,
val,
builtin_object_class: baseObjectClass,
},
})
.then(res => {
return res.digest;
});
},
[getTsClient]
);
};

export const useTableUpdate = (): ((
projectId: string,
digest: string,
updates: traceServerTypes.TableUpdateSpec[]
) => Promise<traceServerTypes.TableUpdateRes>) => {
const getTsClient = useGetTraceServerClientContext();

return useCallback(
(
projectId: string,
baseDigest: string,
updates: traceServerTypes.TableUpdateSpec[]
) => {
return getTsClient().tableUpdate({
project_id: projectId,
base_digest: baseDigest,
updates,
});
},
[getTsClient]
);
};

/// Utility Functions ///

export const convertISOToDate = (iso: string): Date => {
return new Date(iso);
};

// Export //

export const tsWFDataModelHooks: WFDataModelHooksInterface = {
useCall,
useCalls,
useCallsStats,
useCallsDeleteFunc,
useCallUpdateFunc,
useCallsExport,
useObjCreate,
useOpVersion,
useOpVersions,
useObjectVersion,
Expand All @@ -1738,6 +1792,7 @@ export const tsWFDataModelHooks: WFDataModelHooksInterface = {
useFileContent,
useTableRowsQuery,
useTableQueryStats,
useTableUpdate,
derived: {
useChildCallsForCompare,
useGetRefsType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {WeaveKind} from '../../../../../../react';
import {KNOWN_BASE_OBJECT_CLASSES, OP_CATEGORIES} from './constants';
import {Query} from './traceServerClientInterface/query'; // TODO: This import is not ideal, should delete this whole interface
import * as traceServerClientTypes from './traceServerClientTypes'; // TODO: This import is not ideal, should delete this whole interface
import {ContentType} from './traceServerClientTypes';
import {ContentType, TableUpdateSpec} from './traceServerClientTypes';

export type OpCategory = (typeof OP_CATEGORIES)[number];
export type KnownBaseObjectClassType =
Expand Down Expand Up @@ -214,6 +214,12 @@ export type WFDataModelHooksInterface = {
expandedRefCols?: string[],
includeFeedback?: boolean
) => Promise<Blob>;
useObjCreate: () => (
projectId: string,
objectId: string,
val: any,
baseObjectClass?: string
) => Promise<string>;
useOpVersion: (key: OpVersionKey | null) => Loadable<OpVersionSchema | null>;
useOpVersions: (
entity: string,
Expand Down Expand Up @@ -270,6 +276,11 @@ export type WFDataModelHooksInterface = {
key: FeedbackKey | null,
sortBy?: traceServerClientTypes.SortBy[]
) => LoadableWithError<any[] | null> & Refetchable;
useTableUpdate: () => (
projectId: string,
baseDigest: string,
updates: traceServerClientTypes.TableUpdateSpec[]
) => Promise<traceServerClientTypes.TableUpdateRes>;
derived: {
useChildCallsForCompare: (
entity: string,
Expand Down

0 comments on commit 063e8c1

Please sign in to comment.