Skip to content

Commit

Permalink
Merge pull request #613 from deco-cx/revert-612-revert-593-fixes-for-…
Browse files Browse the repository at this point in the history
…roles-n-perm

fix invoke resolve chain
  • Loading branch information
ItamarRocha authored May 2, 2024
2 parents c32f58e + 2c9a480 commit 519d2d3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions blocks/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "../engine/middleware.ts";
import { DecoManifest, FnContext } from "../types.ts";
import { resolversFrom } from "./appsUtil.ts";
import { isInvokeCtx } from "./loader.ts";
import { fnContextFromHttpContext } from "./utils.tsx";

export type Apps = InstanceOf<AppRuntime, "#/root/apps">;
Expand Down Expand Up @@ -72,6 +73,7 @@ export type AppMiddlewareContext<
TApp extends App = App,
TResponse = any,
> = AppContext<TApp> & {
isInvoke: boolean;
resolveChain: FieldResolver[];
next?: () => Promise<TResponse>;
};
Expand Down Expand Up @@ -247,6 +249,7 @@ const appMiddlewareToResolverMiddleware = <
const appCtx = {
...fnContextFromHttpContext(appHttpCtx),
...state,
isInvoke: isInvokeCtx(ctx),
resolveChain: ctx.resolveChain,
next: ctx.next?.bind?.(ctx),
};
Expand Down
16 changes: 14 additions & 2 deletions engine/manifest/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default {
},
invoke: async function invoke(
{ props, block }: BlockInvocation,
{ resolvables, resolvers, resolve },
{ resolvables, resolvers, resolve, ...ctx },
) {
const invokeBlock = `${INVOKE_PREFIX_KEY}${block}`;
const _invokeResolver = resolvers[invokeBlock];
Expand All @@ -181,10 +181,22 @@ export default {
}
const { __resolveType, ...savedprops } = resolvable;
// recursive call
return await resolve({ ...props, ...savedprops, __resolveType });
return await resolve({ ...props, ...savedprops, __resolveType }, {
resolveChain: [...ctx?.resolveChain ?? [], {
type: "resolvable",
value: block,
}, {
type: "resolver",
value: __resolveType,
}],
});
}
return await resolve({ ...props, __resolveType }, {
propsAreResolved: true,
resolveChain: [...ctx?.resolveChain ?? [], {
type: "resolver",
value: __resolveType,
}],
});
},
} satisfies ResolverMap<BaseContext>;
4 changes: 3 additions & 1 deletion runtime/fresh/routes/batchInvoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const handler = async (
? await req.json()
: bodyFromUrl("body", new URL(req.url)); // TODO(mcandeia) check if ctx.url can be used here

const result = await resolve(payloadToResolvable(data)).catch(wrapInvokeErr);
const result = await resolve(payloadToResolvable(data), {
resolveChain: [{ type: "resolver", value: "invoke" }],
}).catch(wrapInvokeErr);

const response = invokeToHttpResponse(req, result);

Expand Down
4 changes: 3 additions & 1 deletion runtime/fresh/routes/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const handler = async (
(url.searchParams.getAll("select") ?? []) as InvokeFunction["select"],
};

const resp = await resolve(payloadToResolvable(invokeFunc)).catch(
const resp = await resolve(payloadToResolvable(invokeFunc), {
resolveChain: [{ type: "resolver", value: "invoke" }],
}).catch(
wrapInvokeErr,
);

Expand Down
5 changes: 1 addition & 4 deletions utils/invoke.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export const buildInvokeFunc = <
payloadForFunc({ key, props } as InvokeFunction<TManifest>),
{
...options,
resolveChain: [...options?.resolveChain ?? [], {
type: "resolver" as const,
value: key,
}],
resolveChain: options?.resolveChain ?? [],
},
partialCtx,
);
Expand Down

0 comments on commit 519d2d3

Please sign in to comment.