From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- node_modules/@jet/environment/runtime/bootstrap.js | 47 ++++++++++++++++++++++ node_modules/@jet/environment/runtime/index.js | 19 +++++++++ node_modules/@jet/environment/runtime/runtime.js | 35 ++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 node_modules/@jet/environment/runtime/bootstrap.js create mode 100644 node_modules/@jet/environment/runtime/index.js create mode 100644 node_modules/@jet/environment/runtime/runtime.js (limited to 'node_modules/@jet/environment/runtime') 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 -- cgit v1.2.3