summaryrefslogtreecommitdiff
path: root/node_modules/@jet/environment/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@jet/environment/runtime')
-rw-r--r--node_modules/@jet/environment/runtime/bootstrap.js47
-rw-r--r--node_modules/@jet/environment/runtime/index.js19
-rw-r--r--node_modules/@jet/environment/runtime/runtime.js35
3 files changed, 101 insertions, 0 deletions
diff --git a/node_modules/@jet/environment/runtime/bootstrap.js b/node_modules/@jet/environment/runtime/bootstrap.js
new file mode 100644
index 0000000..7e09342
--- /dev/null
+++ b/node_modules/@jet/environment/runtime/bootstrap.js
@@ -0,0 +1,47 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.exportBootstrap = void 0;
+const jet_proxy_1 = require("../dependencies/jet-proxy");
+function exportBootstrap(bootstrap) {
+ if (typeof $exportBootstrap !== "undefined") {
+ /* Wraps the given bootstrap function to perform custom bootstrap behavior such
+ as supporting lazy dependencies. */
+ const customBootstrap = (service) => {
+ proxyLazyDependencies(service);
+ return bootstrap(service);
+ };
+ $exportBootstrap(customBootstrap);
+ }
+}
+exports.exportBootstrap = exportBootstrap;
+// We put has_lazy_support on the global object so native can check that the Jet runtime has lazy support.
+globalThis["has_lazy_support"] = true;
+// Installs proxies for lazy dependencies so we can create objects only as needed.
+function proxyLazyDependencies(service) {
+ const lazyDependencyNames = service.$lazyDependencyNames;
+ const lazyDependencyNamesSet = new Set(lazyDependencyNames !== null && lazyDependencyNames !== void 0 ? lazyDependencyNames : []);
+ const lazyGlobalNames = globalThis.$lazyGlobalNames;
+ const lazyGlobalNamesSet = new Set(lazyGlobalNames !== null && lazyGlobalNames !== void 0 ? lazyGlobalNames : []);
+ /* We take the union of lazy globals and lazy dependencies. For each lazy dependency name,
+ we will make one proxy. We must avoid creating more than one proxy for a given name.
+ For instance, if the name is present in the lazy dependencies and lazy globals, we do
+ not want to create two proxies. Doing so would cause multiple object instances to be created
+ natively for use in JS (one instance in the dependency object,
+ another instance in the global object), leading to potential bugs. */
+ const uniqueLazyNames = new Set([...lazyDependencyNamesSet, ...lazyGlobalNamesSet]);
+ const proxyMap = new Map();
+ const lazyProvider = globalThis.$lazyProvider;
+ for (const lazyName of uniqueLazyNames) {
+ // Create one proxy per name present in either lazy globals or lazy dependencies.
+ proxyMap.set(lazyName, jet_proxy_1.LazyProxyFactory.makeProxy(lazyName, lazyProvider));
+ }
+ // For each lazy dependency name, put the proxy on the dependency (service) object under the given name.
+ for (const lazyDependencyName of lazyDependencyNamesSet) {
+ service[lazyDependencyName] = proxyMap.get(lazyDependencyName);
+ }
+ // For each lazy global name, put the proxy on the global object under the given name.
+ for (const lazyGlobalName of lazyGlobalNamesSet) {
+ globalThis[lazyGlobalName] = proxyMap.get(lazyGlobalName);
+ }
+}
+//# sourceMappingURL=bootstrap.js.map \ No newline at end of file
diff --git a/node_modules/@jet/environment/runtime/index.js b/node_modules/@jet/environment/runtime/index.js
new file mode 100644
index 0000000..ac2825f
--- /dev/null
+++ b/node_modules/@jet/environment/runtime/index.js
@@ -0,0 +1,19 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ var desc = Object.getOwnPropertyDescriptor(m, k);
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+ desc = { enumerable: true, get: function() { return m[k]; } };
+ }
+ Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __exportStar = (this && this.__exportStar) || function(m, exports) {
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+__exportStar(require("./bootstrap"), exports);
+__exportStar(require("./runtime"), exports);
+//# sourceMappingURL=index.js.map \ No newline at end of file
diff --git a/node_modules/@jet/environment/runtime/runtime.js b/node_modules/@jet/environment/runtime/runtime.js
new file mode 100644
index 0000000..3c885c5
--- /dev/null
+++ b/node_modules/@jet/environment/runtime/runtime.js
@@ -0,0 +1,35 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.LegacyRuntime = exports.Runtime = void 0;
+const isJetEnvironment = typeof exportService === "function";
+function nativeExportService(name, service) {
+ exportService(name, service);
+}
+class Runtime {
+ constructor(dispatcher, objectGraph) {
+ this.dispatcher = dispatcher;
+ this.objectGraph = objectGraph;
+ }
+ async dispatch(intent) {
+ return await this.dispatcher.dispatch(intent, this.objectGraph);
+ }
+}
+exports.Runtime = Runtime;
+class LegacyRuntime extends Runtime {
+ constructor(dispatcher, objectGraph, services) {
+ super(dispatcher, objectGraph);
+ this.services = services;
+ }
+ serviceWithName(name) {
+ return this.services[name];
+ }
+ exportingService(name, service) {
+ if (isJetEnvironment) {
+ nativeExportService(name, service);
+ }
+ this.services[name] = service;
+ return this;
+ }
+}
+exports.LegacyRuntime = LegacyRuntime;
+//# sourceMappingURL=runtime.js.map \ No newline at end of file