this repo has no description
1import * as validation from "@jet/environment/json/validation";
2import { LegacyRuntime } from "@jet/environment/runtime";
3export class AppStoreRuntime extends LegacyRuntime {
4 constructor(dispatcher, objectGraph) {
5 super(dispatcher, objectGraph, {});
6 }
7 exportingService(name, service) {
8 this.wrapServiceInValidation(service);
9 const existingService = this.serviceWithName(name) || {};
10 const newService = {
11 ...existingService,
12 ...service,
13 };
14 return super.exportingService(name, newService);
15 }
16 // eslint-disable-next-line @typescript-eslint/ban-types
17 exportingServiceName(name, functionName, implementation) {
18 const service = {};
19 service[functionName] = implementation;
20 this.exportingService(name, service);
21 }
22 wrapServiceInValidation(service) {
23 for (const memberName of Object.keys(service)) {
24 const serviceFunction = service[memberName];
25 // For every service route function that we find, we're going
26 // to wrap it in a thunk so that we can attach validation
27 // incidents to it before it's returned back to native code.
28 if (serviceFunction instanceof Function) {
29 // Using a regular function here because we want to forward
30 // `this` as well as our arguments to the wrapped function.
31 service[memberName] = function validationThunk(...args) {
32 // Execute the function
33 const returnValue = serviceFunction.apply(this, args);
34 // Ensure we record validation incidents after the fact
35 if (returnValue instanceof Promise) {
36 return returnValue.then((value) => {
37 validation.recordValidationIncidents(value);
38 return value;
39 });
40 }
41 else {
42 // This would be a violation of the calling convention,
43 // but I guess we might as well consume the incidents.
44 validation.recordValidationIncidents(returnValue);
45 return returnValue;
46 }
47 };
48 }
49 }
50 }
51}
52//# sourceMappingURL=runtime.js.map