@forge/bridge
6.0.1-next.2-experimental-9423de16.0.1-next.3
out/invoke/invoke.js~
out/invoke/invoke.jsModified+3−29
Index: package/out/invoke/invoke.js
===================================================================
--- package/out/invoke/invoke.js
+++ package/out/invoke/invoke.js
@@ -12,42 +12,16 @@
if (Object.values(payload).some((val) => typeof val === 'function')) {
throw new errors_1.BridgeAPIError('Passing functions as part of the payload is not supported!');
}
};
-/**
- * While the rate limit metadata feature is being rolled out, the bridge may return either
- * the resolver body directly or an object of shape `{ body, metadata }`, where the
- * rate limit fields are reported under `metadata`.
- */
-const isMetadataWrappedResponse = (response) => {
- if (typeof response !== 'object' || response === null) {
- return false;
- }
- const keys = Object.keys(response);
- return keys.length === 2 && keys.includes('body') && keys.includes('metadata');
-};
const _invoke = async (functionKey, payload, metadata) => {
- var _a;
if (typeof functionKey !== 'string') {
throw new errors_1.BridgeAPIError('functionKey must be a string!');
}
validatePayload(payload);
- const response = await callBridge('invoke', { functionKey, payload });
- // If metadata is requested, return the response wrapped in metadata.
- if (metadata) {
- // If the bridge response is not wrapped in metadata, return the metadata field as undefined.
- if (!isMetadataWrappedResponse(response)) {
- return { body: response, metadata: undefined };
- }
- const requestedMetadataKeys = Object.keys(metadata !== null && metadata !== void 0 ? metadata : {}).filter((key) => (metadata === null || metadata === void 0 ? void 0 : metadata[key]) === true);
- const responseMetadata = {};
- for (const key of requestedMetadataKeys) {
- responseMetadata[key] = (_a = response.metadata) === null || _a === void 0 ? void 0 : _a[key];
- }
- return { body: response.body, metadata: responseMetadata };
- }
- // If metadata is not requested, return the response directly.
- return (isMetadataWrappedResponse(response) ? response.body : response);
+ // When metadata is defined, the bridge returns the response wrapped in metadata as { body, metadata }
+ // Otherwise, the bridge returns the response directly
+ return await callBridge('invoke', { functionKey, payload, metadata });
};
const limitedInvoke = (0, utils_1.withRateLimiter)(_invoke, 500, 1000 * 25, 'Resolver calls are rate limited at 500req/25s');
/**
* Calls a backend resolver function by key.