@forge/resolver
Advanced tools
Comparing version 0.1.0-next.1 to 0.1.0-next.2
# @forge/resolver | ||
## 0.1.0-next.2 | ||
### Patch Changes | ||
- 2fcd284: Add error case for returning primitive values from resolver definitions | ||
## 0.1.0-next.1 | ||
@@ -4,0 +10,0 @@ |
@@ -19,3 +19,3 @@ "use strict"; | ||
resolver.define('getCloudId', () => { | ||
return backendState.context.cloudId; | ||
return { cloudId: backendState.context.cloudId }; | ||
}); | ||
@@ -35,2 +35,5 @@ resolver.define('getLogs', () => { | ||
}); | ||
resolver.define('invalidReturn', () => { | ||
return 'foo'; | ||
}); | ||
resolver.define('invalidFunction', null); | ||
@@ -42,3 +45,3 @@ const invoke = async (functionKey, payload) => { | ||
it('should perform get operations', async () => { | ||
expect(await invoke('getCloudId')).toEqual('cloudId-123'); | ||
expect(await invoke('getCloudId')).toEqual({ cloudId: 'cloudId-123' }); | ||
expect(await invoke('getLogs')).toEqual(['some log entries', 'warning', 'not verified']); | ||
@@ -58,2 +61,5 @@ }); | ||
}); | ||
it('should throw an error if the resolver definition returns a value that is not an object or undefined', async () => { | ||
await expect(invoke('invalidReturn')).rejects.toThrowError(new Error("Value returned from resolver definition 'invalidReturn' is type 'string' expected 'object' or 'undefined'")); | ||
}); | ||
}); |
@@ -19,6 +19,10 @@ "use strict"; | ||
} | ||
return cb({ | ||
const result = await cb({ | ||
payload: callPayload || {}, | ||
context: Object.assign({ accountId: (_a = backendRuntimePayload === null || backendRuntimePayload === void 0 ? void 0 : backendRuntimePayload.principal) === null || _a === void 0 ? void 0 : _a.accountId }, context) | ||
}); | ||
if (typeof result !== 'object' && result !== undefined) { | ||
throw new Error(`Value returned from resolver definition '${functionKey}' is type '${typeof result}' expected 'object' or 'undefined'`); | ||
} | ||
return result; | ||
} | ||
@@ -25,0 +29,0 @@ throw new Error(`Function '${functionKey}' is not defined.`); |
{ | ||
"name": "@forge/resolver", | ||
"version": "0.1.0-next.1", | ||
"version": "0.1.0-next.2", | ||
"description": "Forge function resolver", | ||
@@ -5,0 +5,0 @@ "author": "Atlassian", |
Sorry, the diff of this file is not supported yet
7557
126