diff --git a/.changeset/healthy-cougars-jog.md b/.changeset/healthy-cougars-jog.md new file mode 100644 index 0000000..9db4fe1 --- /dev/null +++ b/.changeset/healthy-cougars-jog.md @@ -0,0 +1,5 @@ +--- +"@hydrofoil/shell-operations": patch +--- + +Pass the original payload to operation completion callback diff --git a/packages/operations/index.ts b/packages/operations/index.ts index 350d25a..662a6dd 100644 --- a/packages/operations/index.ts +++ b/packages/operations/index.ts @@ -5,6 +5,7 @@ import { createModel } from '@captaincodeman/rdx' import { Model } from '@hydrofoil/shell-core/store' import { Term } from '@rdfjs/types' import TermMap from '@rdf-esm/term-map' +import { GraphPointer } from 'clownface' import { effects } from './lib/effects.js' import reducers from './lib/reducers.js' @@ -26,6 +27,8 @@ export interface OperationsState { operations: Map } +export type Payload = GraphPointer + export const operation = createModel({ state: { operations: new TermMap(), diff --git a/packages/operations/lib/completed.ts b/packages/operations/lib/completed.ts index 9b8b44a..2acf13a 100644 --- a/packages/operations/lib/completed.ts +++ b/packages/operations/lib/completed.ts @@ -4,8 +4,10 @@ import type { ResponseWrapper } from 'alcaeus/ResponseWrapper' import type { ResourceRepresentation } from 'alcaeus/ResourceRepresentation' import { hydra } from '@tpluscode/rdf-ns-builders' import type { Error } from '@rdfine/hydra/lib/Error' +import type { Payload } from '../index' export interface OperationCompleted { + payload: Payload operation: RuntimeOperation response?: ResponseWrapper representation?: ResourceRepresentation @@ -14,14 +16,15 @@ export interface OperationCompleted { export function completed(store: Store) { const dispatch = store.getDispatch() - return function ({ operation, response, representation }: OperationCompleted) { + return function ({ payload, operation, response, representation }: OperationCompleted) { if (!response?.xhr.ok) { const error = representation?.ofType(hydra.Error).shift() - dispatch.operation.failed({ operation, response, error }) + dispatch.operation.failed({ payload, operation, response, error }) return } dispatch.operation.succeeded({ + payload, operation, response, representation, diff --git a/packages/operations/lib/invoke.ts b/packages/operations/lib/invoke.ts index 525b35e..f7c3021 100644 --- a/packages/operations/lib/invoke.ts +++ b/packages/operations/lib/invoke.ts @@ -1,11 +1,11 @@ import type { RuntimeOperation } from 'alcaeus' -import { GraphPointer } from 'clownface' import { turtle } from '@tpluscode/rdf-string' import type { Store } from '@hydrofoil/shell' +import type { Payload } from '../index' export interface InvokeOperation { operation: RuntimeOperation - payload: GraphPointer + payload: Payload } export function invoke(store: Store) { @@ -18,6 +18,6 @@ export function invoke(store: Store) { 'content-type': 'text/turtle', }) - dispatch.operation.completed({ operation, ...response }) + dispatch.operation.completed({ payload, operation, ...response }) } } diff --git a/packages/operations/lib/reducers.ts b/packages/operations/lib/reducers.ts index 8e1d8f0..8a1c7d1 100644 --- a/packages/operations/lib/reducers.ts +++ b/packages/operations/lib/reducers.ts @@ -2,9 +2,10 @@ import type { RuntimeOperation } from 'alcaeus' import type { Error } from '@rdfine/hydra/lib/Error' import type { ResponseWrapper } from 'alcaeus/ResponseWrapper' import type { ResourceRepresentation } from 'alcaeus/ResourceRepresentation' -import type { FailureResult, OperationsState, SuccessResult } from '..' +import type { FailureResult, OperationsState, Payload, SuccessResult } from '..' export interface OperationCompleted { + payload: Payload operation: RuntimeOperation }